:root {
  --bg: #fbf9f4;
  --surface: #ffffff;
  --text: #22201c;
  --muted: #6d675d;
  --line: #e4ded2;
  --accent: #8a3b12;
  --accent-soft: #f5e6da;
  --same: #e9e1f5;
  --hit: #ffe28a;
  --hit-text: #22201c;
  --attested: #eef4ea;
  --seg-prefix: #6b7280;
  --seg-augment: #b45309;
  --seg-redup: #7c3aed;
  --seg-stem: #1d4ed8;
  --seg-formative: #be185d;
  --seg-ending: #047857;
  --greek: 'Gentium Plus', 'Gentium', 'GFS Didot', 'Times New Roman', serif;
  --ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --text-size: 1.35rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181715;
    --surface: #211f1c;
    --text: #ebe6dc;
    --muted: #a39b8d;
    --line: #38342e;
    --accent: #e39a6c;
    --accent-soft: #3a2a1f;
    --same: #352d44;
    --hit: #b8902a;
    --hit-text: #15130f;
    --attested: #24301f;
    --seg-prefix: #a3a3a3;
    --seg-augment: #f59e0b;
    --seg-redup: #c4b5fd;
    --seg-stem: #93c5fd;
    --seg-formative: #f9a8d4;
    --seg-ending: #6ee7b7;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181715; --surface: #211f1c; --text: #ebe6dc; --muted: #a39b8d; --line: #38342e;
  --accent: #e39a6c; --accent-soft: #3a2a1f; --same: #352d44; --hit: #b8902a; --hit-text: #15130f;
  --attested: #24301f; color-scheme: dark;
  --seg-prefix: #a3a3a3; --seg-augment: #f59e0b; --seg-redup: #c4b5fd; --seg-stem: #93c5fd;
  --seg-formative: #f9a8d4; --seg-ending: #6ee7b7;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  line-height: 1.5;
}
button, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.title { display: flex; flex-direction: column; margin-right: auto; }
.book-gr { font-family: var(--greek); font-size: 1.2rem; letter-spacing: 0.06em; }
.book-en { font-size: 0.8rem; color: var(--muted); }
.chapnav, .settings { display: flex; align-items: center; gap: 0.4rem; }
.toggle { display: flex; align-items: center; gap: 0.3rem; font-size: 0.9rem; cursor: pointer; }

/* ---------- layout ---------- */
#layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 1500px;
  margin: 0 auto;
}
#layout.with-panel { grid-template-columns: minmax(0, 1fr) minmax(380px, 40%); }

#text {
  font-family: var(--greek);
  font-size: var(--text-size);
  line-height: 1.9;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 4rem;
  max-width: 46em;
  margin: 0 auto;
  width: 100%;
}
#text h2 {
  font-family: var(--ui);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1rem;
}
.vnum {
  font-family: var(--ui);
  font-size: 0.55em;
  color: var(--accent);
  vertical-align: super;
  margin: 0 0.15em 0 0.35em;
  user-select: none;
}
.vnum { cursor: pointer; }
.vnum:hover { text-decoration: underline; }
.tr-line {
  display: block;
  font-family: var(--ui); font-size: 0.95rem; line-height: 1.5;
  margin: 0.35rem 0 0.7rem; padding: 0.45rem 0.75rem;
  background: var(--surface); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0;
}
.p-tr { margin: 0.5rem 0; }
.p-tr-show { font-size: 0.85rem; }
.tr-box { font-size: 0.95rem; }
.p-tr .tr-box { padding: 0.45rem 0.6rem; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 6px 6px 0; }
.tr-switch { display: flex; gap: 0.25rem; margin-bottom: 0.3rem; }
.tr-switch button { font-size: 0.7rem; padding: 0.05rem 0.45rem; }
.tr-switch button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.tr-box .hint { font-size: 0.8rem; margin-top: 0.25rem; }
.verse.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.w {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 0.05em;
  transition: background 0.1s;
}
.w:hover { background: var(--accent-soft); }
.w.same { background: var(--same); }
.w.sel { background: var(--hit); color: var(--hit-text); }
.w.phr { box-shadow: inset 0 -2px 0 var(--seg-stem); }
.w.tgt { outline: 2px solid var(--accent); outline-offset: 1px; }

/* interlinear: word over gloss */
body.interlinear #text { line-height: 1.3; }
body.interlinear .wrap {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: top; margin: 0 0.2em 0.9em;
}
body.interlinear .gl {
  display: block;
  font-family: var(--ui);
  font-size: 0.5em;
  color: var(--muted);
  max-width: 9em;
  text-align: center;
  line-height: 1.2;
  margin-top: 0.15em;
}
.gl { display: none; }

/* ---------- panel ---------- */
#panel {
  position: sticky;
  top: var(--bar-h, 4.25rem);
  align-self: start;
  height: calc(100vh - var(--bar-h, 4.25rem));
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 1rem 1.2rem 3rem;
}
.p-head { display: flex; align-items: baseline; gap: 0.75rem; }
.p-form { font-family: var(--greek); font-size: 2rem; line-height: 1.2; }
.p-ref { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.p-close { border: none; font-size: 1.3rem; padding: 0 0.4rem; background: transparent; }
.p-lemma { font-family: var(--greek); font-size: 1.3rem; margin-top: 0.25rem; }
.p-lemma .head { color: var(--muted); font-size: 0.95rem; margin-left: 0.4rem; }
.p-freq { font-size: 0.8rem; color: var(--muted); }
.freq-hint { display: inline-block; margin: 0.2rem 0 0 0.4rem; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.75rem; border: 1px solid var(--line); }
.freq-hint.core { color: var(--seg-ending); border-color: var(--seg-ending); }
.freq-hint.common { color: var(--seg-stem); border-color: var(--seg-stem); }
.freq-hint.rare { color: var(--muted); }
#text p { margin: 0 0 1.1em; }
.chapter-end {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  margin: 2.2rem 0 0; padding-top: 1rem; border-top: 1px solid var(--line);
  font-family: var(--ui); font-size: 1rem;
}
.chapter-end button { padding: 0.45rem 0.9rem; }
.chapter-end .hint { font-size: 0.85rem; color: var(--muted); }
.p-parse {
  margin: 0.8rem 0 0.4rem;
  padding: 0.6rem 0.75rem;
  background: var(--accent-soft);
  border-radius: 8px;
}
.p-parse .pos { font-weight: 600; text-transform: capitalize; }
.p-parse code { font-size: 0.8rem; color: var(--muted); margin-left: 0.4rem; }
.p-parse .alt { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.p-gloss { margin: 0.6rem 0; }
.p-gloss q { font-style: italic; }
.p-def { margin: 0.4rem 0 0.8rem; color: var(--text); }
.p-def .note { color: var(--muted); font-size: 0.85rem; }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-top: 1rem; }
.tabs button {
  border: none; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; padding: 0.4rem 0.7rem; color: var(--muted);
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { padding-top: 0.75rem; }
.model-title { font-weight: 600; }
.model-title .gr { font-family: var(--greek); font-size: 1.1rem; }
.model-note { font-size: 0.9rem; color: var(--muted); margin: 0.3rem 0 0.6rem; }
.scope { display: flex; gap: 0.4rem; margin: 0.4rem 0 0.6rem; font-size: 0.85rem; }
.scope button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

.section { margin: 0.9rem 0 1.2rem; }
.section h3 { font-size: 0.95rem; margin: 0 0 0.35rem; }
.section h4 { font-size: 0.8rem; margin: 0.6rem 0 0.25rem; color: var(--muted); font-weight: 600; }
table.pd {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
table.pd th {
  font-weight: 600; font-size: 0.72rem; color: var(--muted);
  text-align: left; padding: 0.2rem 0.35rem;
  text-transform: uppercase; letter-spacing: 0.04em;
}
table.pd td {
  font-family: var(--greek);
  font-size: 1.05rem;
  padding: 0.2rem 0.35rem;
  border-top: 1px solid var(--line);
  vertical-align: top;
}
table.pd td.empty { color: var(--line); }
table.pd td.hit { background: var(--hit); color: var(--hit-text); font-weight: 700; border-radius: 3px; }
table.pd td.att { cursor: pointer; }
table.pd td.att:hover { background: var(--attested); }
table.pd td.att.hit:hover { background: var(--hit); }
table.pd td.picked { outline: 2px solid var(--accent); outline-offset: -2px; }
.cnt { font-family: var(--ui); font-size: 0.7rem; color: var(--muted); margin-left: 0.2em; }
td.hit .cnt { color: var(--hit-text); }
.inf { font-family: var(--greek); font-size: 1.05rem; }
.inf.hit { background: var(--hit); color: var(--hit-text); font-weight: 700; padding: 0 0.3rem; border-radius: 3px; }

.refs { margin-top: 0.75rem; padding: 0.6rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.85rem; }
.refs .gr { font-family: var(--greek); font-size: 1.05rem; }
.refs a { color: var(--accent); text-decoration: none; margin-right: 0.5rem; white-space: nowrap; }
.refs a:hover { text-decoration: underline; }
.refs span.ext { color: var(--muted); margin-right: 0.5rem; white-space: nowrap; }
.hint { font-size: 0.85rem; color: var(--muted); }

.textcol { min-width: 0; }
#notice {
  margin: 0.8rem clamp(1rem, 4vw, 3rem) 0; padding: 0.55rem 0.9rem;
  border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft);
  font-size: 0.92rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
#notice[hidden] { display: none; }
#notice #tip-close { margin-left: auto; border: none; background: transparent; font-size: 1.1rem; }
.help h3 { font-size: 0.95rem; margin: 1.1rem 0 0.3rem; }
.help p, .help li { font-size: 0.93rem; }
.help ul { padding-left: 1.1rem; margin: 0.3rem 0; }
.help li { margin: 0.25rem 0; }
.help kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; font-size: 0.8rem; }
.help .demo-phr { box-shadow: inset 0 -2px 0 var(--seg-stem); }
.help .demo-tgt { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }
.help .seg { font-weight: 700; }
.help .sources li { font-size: 0.85rem; color: var(--muted); }
.help a, .credits a { color: var(--accent); }
a.fix { font-size: 0.75rem; color: var(--muted); margin-left: 0.4rem; white-space: nowrap; }
a.fix:hover { color: var(--accent); }
.p-fix { font-size: 0.8rem; color: var(--muted); margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 0.6rem; }

/* the sentence */
.p-syn, .p-notes { margin: 0.7rem 0; }
.p-syn ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.syn-key { font-size: 0.75rem; color: var(--muted); margin: 0.1rem 0 0.25rem; }
.key-phr { box-shadow: inset 0 -2px 0 var(--seg-stem); color: var(--text); }
.key-tgt { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; color: var(--text); }
.p-syn li { cursor: pointer; border-radius: 4px; padding: 0 0.2rem; }
.p-syn li:hover, .p-syn li:focus, .p-syn li.pinned { background: var(--accent-soft); outline: none; }
.p-syn li { margin: 0.15rem 0; }
.p-syn [lang="grc"] { font-family: var(--greek); font-size: 1.1em; }
.p-syn a.gk { color: var(--accent); text-decoration: none; border-bottom: 1px dotted var(--accent); }
.p-notes .note-item {
  margin: 0.3rem 0; padding: 0.45rem 0.6rem;
  border-left: 3px solid var(--seg-stem); background: var(--surface);
  border-radius: 0 6px 6px 0; font-size: 0.92rem;
}
.p-notes b[lang="grc"] { font-family: var(--greek); font-size: 1.05rem; }

/* word parts */
.p-parts, .p-pp { margin: 0.7rem 0; }
.bd { font-family: var(--greek); font-size: 1.6rem; margin: 0.15rem 0 0.3rem; }
.bd .dash { color: var(--muted); margin: 0 0.08em; }
.seg { font-weight: 700; }
.seg.prefix { color: var(--seg-prefix); }
.seg.augment { color: var(--seg-augment); }
.seg.redup { color: var(--seg-redup); }
.seg.stem { color: var(--seg-stem); }
.seg.formative { color: var(--seg-formative); }
.seg.ending { color: var(--seg-ending); }
.bd-key { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; color: var(--muted); }
.bd-key li { margin: 0.15rem 0; }
.bd-key .seg { font-family: var(--greek); font-size: 1.05rem; }
.bd-key b { color: var(--text); font-weight: 600; }

.seg-gloss { color: var(--text); }
.seg-gloss [lang="grc"] { font-family: var(--greek); font-size: 1.05em; }

/* built from */
.p-built { margin: 0.5rem 0 0.2rem; }
.p-built > div:nth-child(2) { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.4rem; margin-top: 0.1rem; }
.bf-part [lang="grc"] { font-family: var(--greek); font-size: 1.2rem; }
.bf-as { font-family: var(--greek); color: var(--muted); }
.bf-gloss { font-style: italic; }
.bf-plus { color: var(--muted); }
.p-built .hint { font-size: 0.75rem; margin-top: 0.15rem; }

/* principal parts */
ol.pp {
  list-style: none; padding: 0; margin: 0.25rem 0 0.3rem;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.3rem;
}
ol.pp li {
  border: 1px solid var(--line); border-radius: 6px; padding: 0.2rem 0.4rem;
  font-family: var(--greek); font-size: 1.05rem; line-height: 1.3;
}
ol.pp li.hit { background: var(--hit); color: var(--hit-text); border-color: var(--hit); font-weight: 700; }
.pp-n { display: block; font-family: var(--ui); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
ol.pp li.hit .pp-n { color: var(--hit-text); }

/* Abbott-Smith */
.p-full { margin: 0.4rem 0 0.6rem; font-size: 0.9rem; }
.p-full summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.85rem; }
.as-body { margin-top: 0.4rem; line-height: 1.55; }
.as-body [lang="grc"] { font-family: var(--greek); font-size: 1.05em; }
.as-sense .as-sense { margin: 0.35rem 0 0.35rem 0.9rem; }
.as-n { font-weight: 700; }
.as-body .as-ed { color: var(--muted); font-size: 0.85em; font-style: italic; }
.as-here { font-size: 0.85rem; margin: -0.3rem 0 0.6rem; color: var(--muted); }
.as-here b { color: var(--text); }
.as-body a.here { background: var(--hit); color: var(--hit-text); padding: 0 0.2rem; border-radius: 3px; }
.as-body .ref { color: var(--muted); }
.as-body a { color: var(--accent); }

/* my words */
.seen { font-size: 0.85rem; color: var(--accent); margin: 0.3rem 0; }
ul.lookups { list-style: none; padding: 0; margin: 0.5rem 0; }
ul.lookups li { border-top: 1px solid var(--line); padding: 0.6rem 0; }
.lk-top { display: flex; align-items: baseline; gap: 0.6rem; }
.lk-lemma { font-family: var(--greek); font-size: 1.35rem; }
.lk-n { font-size: 0.8rem; color: var(--muted); }
.lk-known { margin-left: auto; font-size: 0.8rem; }
.lk-gloss { font-size: 0.9rem; }
.lk-forms { font-size: 0.85rem; color: var(--muted); }
.lk-forms [lang="grc"] { font-family: var(--greek); font-size: 1.05rem; color: var(--text); }
.lk-refs a { color: var(--accent); text-decoration: none; margin-right: 0.45rem; font-size: 0.85rem; }
.lk-export { margin-top: 1rem; padding-top: 0.7rem; border-top: 1px solid var(--line); }
.lk-export > div { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.3rem; }
.lk-export button { font-size: 0.85rem; }
.lk-clear { margin-top: 0.8rem; font-size: 0.85rem; }

.credits {
  font-size: 0.75rem; color: var(--muted);
  padding: 1rem; text-align: center; border-top: 1px solid var(--line);
}

/* ---------- small screens: panel becomes a bottom sheet ---------- */
@media (max-width: 860px) {
  #layout.with-panel { grid-template-columns: minmax(0, 1fr); }
  #panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: 62vh;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgb(0 0 0 / 0.15);
    padding: 0.8rem 1rem 2rem;
    z-index: 10;
  }
  #layout.with-panel #text { padding-bottom: 65vh; }
  .bar { gap: 0.5rem; padding: 0.5rem 1rem; }
  .book-en { display: none; }
  table.pd td { font-size: 0.95rem; padding: 0.15rem 0.2rem; }
  table.pd th { padding: 0.15rem 0.2rem; }
}
