:root {
--bg: #0b1020; --panel:#111936; --ink:#e7ecff; --muted:#b8c0e0; --accent:#6ea8fe; --accent-2:#8bd3ff;
--chip:#1a244a; --chip-br:#2a376b; --btn:#1a2342; --btn-br:#2a335e; --btn-hover:#223059;
}
html,body { height:100%; }
body {
  margin:0;
  font:16px/1.6 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  background:
    linear-gradient(180deg, rgba(11,16,32,0.9), rgba(11,16,32,0.95)),
    url("img/bg.webp") center/cover no-repeat fixed;
  color:var(--ink);
  overflow: hidden;
}
.wrap {
  margin: 0 20%;
  padding: 24px;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  transition: opacity 0.35s ease;
}
body.ui-busy .wrap { pointer-events: none; }
body.ui-loading .wrap { opacity: 0; }

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #e7ecff;
  text-shadow: 0 6px 24px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 10002;
}
body.ui-loading .loading-overlay { opacity: 1; }
header { display:flex; align-items:center; gap:12px; margin-bottom: 16px; }
header .mark { font-size: 22px; line-height: 1; color: var(--accent-2); }
header h1 { font-size: 20px; margin:0; letter-spacing: 0.5px; color: var(--accent-2); }
.card { background: var(--panel); border:1px solid #1a2342; border-radius: 16px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.35); }
#view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.view-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.view-scroll.chapter-layout { overflow: hidden; }
.chapter-layout { display:flex; gap:16px; height: 100%; overflow: hidden; }
.chapters-panel {
  flex: 0 0 140px;
  align-self: flex-start;
  max-height: 100%;
  background: #0f1733;
  border: 1px solid #1a2342;
  border-radius: 12px;
  padding: 10px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
}
.chapters-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 2px 6px 8px;
}
.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.chapter-item {
  display: block;
  width: 100%;
  text-align: center;
  background: var(--chip);
  border: 1px solid var(--chip-br);
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.chapter-item:hover { background:#202b57; color: var(--ink); }
.chapter-item.is-active { color: var(--ink); border-color: var(--accent); box-shadow: 0 0 0 1px rgba(110,168,254,0.35); }
.chapter-body { flex: 1 1 auto; min-width: 0; overflow-y: auto; }
.chapters-collapsed .chapters-panel { display: none; }


/* Contents grid */
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap:12px; }
.book { background: var(--chip); border:1px solid var(--chip-br); padding: 10px 12px; border-radius: 12px; cursor: pointer; color: var(--muted); transition: transform .08s ease, background .15s; text-align:center; }
.book:hover { transform: translateY(-2px); background:#202b57; color:var(--ink); }


/* Chapter view */
.toolbar { display:flex; flex-wrap:wrap; gap:10px; margin-bottom:12px; align-items:center; }
.toolbar-left,
.toolbar-right { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.toolbar-right { margin-left:auto; }
.toolbar {
  background: #131d3e;
  border: 1px solid #1a2342;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}
.search-panel { margin-bottom: 12px; }
.search-panel.is-hidden { display: none; }
.search-bar {
  background: #131d3e;
  border: 1px solid #1a2342;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.search-input {
  flex: 1 1 260px;
  min-width: 180px;
  background: #0f1733;
  border: 1px solid #223059;
  border-radius: 10px;
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}
.search-results {
  background: rgba(15,23,51,0.9);
  border: 1px solid #1a2342;
  border-top: none;
  border-radius: 0 0 12px 12px;
  padding: 8px 12px;
  max-height: 240px;
  overflow: auto;
}
.search-status { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.search-status.is-error { color: #ffb4b4; }
.search-hits { display: flex; flex-direction: column; gap: 6px; }
.search-hit {
  text-align: left;
  background: #101a3a;
  border: 1px solid #223059;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.search-hit:hover { background: #1c2853; }
.search-hit.is-active {
  border-color: #f6b84a;
  box-shadow: 0 0 0 1px rgba(246,184,74,0.45);
  background: #1b274f;
}
.search-hit-word {
  background: #f6b84a;
  color: #1b1b1b;
  border-radius: 5px;
  padding: 0 2px;
}
.search-hit-word.is-dim {
  background: rgba(160,160,160,0.35);
  color: var(--ink);
}
.search-hit-word.is-selected {
  background: #f9c86b;
  color: #1b1b1b;
  box-shadow: 0 0 0 1px rgba(255,215,130,0.7);
}
.info-wrap { position: relative; display: inline-flex; }
.info-tip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 260px;
  max-width: 320px;
  background: #0f1733;
  border: 1px solid #223059;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 12px 24px rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
  z-index: 30;
}
.info-wrap.is-open .info-tip {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.search-results::-webkit-scrollbar { width: 10px; }
.search-results::-webkit-scrollbar-track { background: #0e1429; border-radius: 10px; }
.search-results::-webkit-scrollbar-thumb { background: #2a376b; border-radius: 10px; border: 2px solid #0e1429; }
.search-results { scrollbar-width: thin; scrollbar-color: #2a376b #0e1429; }
.btn { background: var(--btn); border:1px solid var(--btn-br); color: var(--ink); padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.btn:hover { background: var(--btn-hover); }
.btn[disabled] { opacity:.5; cursor: not-allowed; }
.toggle { display:flex; align-items:center; gap:6px; color:var(--muted); }

#paraMode,
#morphMode,
#lemmaMode {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--btn-br);
  border-radius: 4px;
  background: #0f1733;
  position: relative;
  display: inline-block;
}
#paraMode::after,
#morphMode::after,
#lemmaMode::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid var(--accent-2);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0;
}
#paraMode:checked::after,
#morphMode:checked::after,
#lemmaMode:checked::after { opacity: 1; }
#paraMode:disabled,
#morphMode:disabled,
#lemmaMode:disabled {
  background: #000;
  border-color: #111;
}
#paraMode:disabled::after,
#morphMode:disabled::after,
#lemmaMode:disabled::after { border-color: var(--ink); }


.title { display:flex; align-items:baseline; gap:10px; margin:0 0 8px; }
.title .book { font-weight: 700; color: var(--accent); }
.title .chapter { color: var(--muted); }


.flow { font-size: 20px; line-height: 1.95; letter-spacing: 0.2px; }
.vnum { vertical-align: super; font-size: .65em; color: var(--accent-2); margin-right: 6px; opacity: .9; }

/* Morphology */
.morph-word { position: relative; display: inline-block; padding: 0 2px; border-radius: 6px; }
.morph-word:hover { background: rgba(139,211,255,0.08); }
.morph-float-tip {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  background: #0f1733;
  border: 1px solid #223059;
  border-radius: 10px;
  padding: 6px 8px;
  color: var(--ink);
  font-size: 12px;
  white-space: normal;
  text-align: center;
  box-shadow: 0 12px 24px rgba(0,0,0,0.45);
  z-index: 10003;
  transform: translateX(-50%) translateY(6px);
  transition: opacity .15s ease, transform .15s ease;
}
.morph-float-tip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #223059;
}
.morph-float-tip.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.morph-lemma { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.morph-tag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: #1f2a57;
  border: 1px solid #2a376b;
  color: var(--accent-2);
  cursor: pointer;
}
.morph-tag.is-empty { color: var(--muted); cursor: default; }
.morph-desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

@keyframes morphFadeOut {
  0% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}
.morph-alert {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #1a244a;
  border: 1px solid #2a376b;
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
  z-index: 10001;
  animation: morphFadeOut 5s ease forwards;
}


/* Paragraph mode */
.verses { display:block; }
.verse { margin: 0 0 0.9em 0; }
.verse .vnum { margin-right: 8px; }


.footer { margin: 12px auto 0 auto; color: var(--muted); font-size: 13px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

@media (max-width: 1600px) {
  .wrap { margin: 0; }
}

/* Scrollbar */
.view-scroll::-webkit-scrollbar { width: 10px; }
.view-scroll::-webkit-scrollbar-track { background: #0e1429; border-radius: 10px; }
.view-scroll::-webkit-scrollbar-thumb { background: #2a376b; border-radius: 10px; border: 2px solid #0e1429; }
.view-scroll { scrollbar-width: thin; scrollbar-color: #2a376b #0e1429; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
}
.modal {
  background: var(--panel); color: var(--ink);
  border: 1px solid #1a2342; border-radius: 12px;
  width: 520px; max-width: 92vw; padding: 16px 16px 12px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.modal h3 { margin: 0 0 8px; font-size: 18px; color: var(--accent-2); }
.modal .row { margin: 10px 0; display: flex; gap: 10px; align-items: center; }
.modal .row label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal .btn { background: var(--btn); border:1px solid var(--btn-br); color: var(--ink); padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.modal .btn:hover { background: var(--btn-hover); }
