:root {
  --ink: #1f1d1a;
  --muted: #77706a;
  --paper: #fbf8f2;
  --rule: #e4ddd0;
  --accent: #8c2f1b;      /* terracotta – red-figure pottery */
  --hl: #f6e2b8;
  --hl-strong: #efc976;
  --english: #3b4f63;
  --greek: "Gentium Book Plus", "Gentium Plus", "GFS Didot", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
}

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(251, 248, 242, 0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
}
.top-inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
h1 {
  margin: 0;
  font-family: var(--greek);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}
.subtitle { margin: 0.1rem 0 0; font-size: 0.8rem; color: var(--muted); text-wrap: balance; }

/* Toggle switch */
.switch { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.slider {
  width: 2.6rem; height: 1.5rem; border-radius: 1rem;
  background: #cfc6b8; position: relative; transition: background 0.15s;
  flex: none;
}
.slider::after {
  content: ""; position: absolute; top: 0.2rem; left: 0.2rem;
  width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #fff;
  transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(1.1rem); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: 0.9rem; }

.controls { display: flex; align-items: center; gap: 1rem; }
.quiz-button {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--accent); background: #fff;
  border: 1px solid var(--accent); border-radius: 1rem;
  padding: 0.3rem 0.9rem; cursor: pointer;
}
.quiz-button:hover { background: #f8ece6; }

/* Text */
.text {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 1rem;
}
.intro, .gap {
  font-size: 0.92rem;
  line-height: 1.5;
  color: #4a4540;
  background: #f3eee4;
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 0 0 1.5rem;
  border-radius: 0 6px 6px 0;
}
.gap { margin: 1.75rem 0; }
.gap strong, .intro strong { color: var(--accent); }

.line {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  column-gap: 0.5rem;
  margin: 0 0 0.35rem;
}
.num {
  grid-row: 1 / span 2;
  font-size: 0.75rem;
  color: #b3aa9d;
  text-align: right;
  padding-top: 0.5rem;
  background: none;
  border: 0;
  font-family: var(--ui);
  cursor: pointer;
  align-self: start;
}
.num.five { color: var(--muted); font-weight: 600; }
.num:hover { color: var(--accent); }

.greek {
  font-family: var(--greek);
  font-size: 1.3rem;
  line-height: 1.6;
  margin: 0.2rem 0;
  padding-left: 1.2em;     /* a wrapped line is indented, so it can't be mistaken for the next line */
  text-indent: -1.2em;
}
.w {
  cursor: pointer;
  border-radius: 3px;
  padding: 0.05em 0.08em;
  margin: 0 -0.08em;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.w:hover { background: #efe8da; }
.w.hl { background: var(--hl); }
.w.hl.tapped { background: var(--hl-strong); }

.english {
  display: none;
  margin: 0 0 0.6rem;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--english);
}
body.show-english .english,
.line.reveal .english { display: block; }

.loading, .error { color: var(--muted); }
.error { color: #a12; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }

.foot {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1rem 1rem 14rem;   /* room for the panel */
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
}
.source { font-size: 0.75rem; }

/* Word panel – a bottom sheet on every screen size */
.panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(46rem, 100%);
  max-height: 45vh;
  overflow-y: auto;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--rule);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
  padding: 1rem 2.75rem calc(1rem + env(safe-area-inset-bottom)) 1.25rem;
}
.panel[hidden] { display: none; }
.panel-close {
  position: absolute; top: 0.4rem; right: 0.5rem;
  width: 2.25rem; height: 2.25rem;
  border: 0; background: none; font-size: 1.6rem; line-height: 1;
  color: var(--muted); cursor: pointer;
}
.gloss + .gloss { border-top: 1px solid var(--rule); margin-top: 0.75rem; padding-top: 0.75rem; }
.gloss-greek { font-family: var(--greek); font-size: 1.3rem; margin: 0; color: var(--accent); }
.gloss-lit { font-size: 1.1rem; margin: 0.2rem 0 0; font-weight: 600; }
.gloss-note { font-size: 0.9rem; line-height: 1.45; margin: 0.35rem 0 0; color: #4a4540; }
.gloss-empty { color: var(--muted); font-style: italic; }
.panel-line { font-size: 0.75rem; color: var(--muted); margin: 0 0 0.4rem; }

/* Quiz */
body.quizzing .english { display: none !important; }
body.quizzing .w { cursor: default; }
body.quizzing .w:hover:not(.hl) { background: none; }
.qtitle { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.4rem; }
.qhelp { font-size: 0.9rem; color: #4a4540; margin: 0 0 0.9rem; line-height: 1.45; }
.qrow { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 0 0 0.9rem; font-size: 0.95rem; }
.qselect { font: inherit; padding: 0.25rem 0.4rem; border: 1px solid var(--rule); border-radius: 6px; background: #fff; }
.qcheck { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.qhead { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin: 0 0 0.35rem; }
.qbar { height: 4px; background: var(--rule); border-radius: 2px; margin: 0 0 0.8rem; overflow: hidden; }
.qfill { height: 100%; background: var(--accent); transition: width 0.2s; }
.qgreek { font-size: 1.6rem; }
.qanswer { margin: 0.2rem 0 0; }
.qline { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 0.9rem; color: var(--english); margin: 0.5rem 0 0; }
.qactions { display: flex; gap: 0.75rem; margin-top: 0.9rem; }
.qbtn {
  font: inherit; font-size: 1rem; font-weight: 600;
  padding: 0.65rem 1.2rem; min-width: 7rem;
  border-radius: 8px; border: 1px solid var(--rule); background: #fff; color: var(--ink);
  cursor: pointer;
}
.qbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.qbtn.primary:disabled { opacity: 0.4; cursor: default; }
.qbtn.no { border-color: #c98a7c; color: #8c2f1b; flex: 1; }
.qbtn.yes { background: #3f6e48; border-color: #3f6e48; color: #fff; flex: 1; }

@media (max-width: 520px) {
  .greek { font-size: 1.08rem; }
  .english { font-size: 0.92rem; }
  .num { padding-top: 0.35rem; }
  .line { grid-template-columns: 2rem 1fr; column-gap: 0.4rem; }
  h1 { font-size: 1.15rem; }
  .controls { gap: 0.6rem; }
  .switch-label { font-size: 0.85rem; }
}

@media print {
  .top { position: static; }
  .panel, .foot p:first-child { display: none; }
  body.show-english .english { display: block; }
}
