/* Old English Reader — reader-spec §4.5 */

:root {
  --ink: #1f2430;
  --ink-soft: #4b5563;
  --paper: #faf7f0;
  --panel: #ffffff;
  --rule: #e2ddd2;
  --accent: #7c5a2e;
  --hl: #fef3c7;
  --hl-word: #e0f2fe;
  --error: #b3261e;
  --warn: #92400e;
  --oe-serif: 'Cardo', 'Cambria', Georgia, 'Times New Roman', serif;
  --me-serif: Georgia, 'Times New Roman', serif;
  --runic: 'Noto Sans Runic', 'Segoe UI Historic', 'Junicode', 'Apple Symbols', serif;
  --oe-scale: 1;
}

@font-face {
  font-family: 'Noto Sans Runic';
  src: url('fonts/NotoSansRunic-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+16A0-16FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--me-serif);
}

body { display: flex; flex-direction: column; }

/* ---------- masthead ---------- */
#masthead {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
#masthead h1 {
  font-size: 1.15rem;
  margin: 0;
  font-family: var(--oe-serif);
  letter-spacing: 0.02em;
  color: var(--accent);
  flex: 1 1 auto;
  white-space: nowrap;
}
#sidebar-toggle {
  display: none;
  font-size: 1.2rem;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
}
#search-form { display: flex; gap: 0.35rem; flex: 0 1 26rem; }
#search-input {
  flex: 1;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  background: var(--paper);
}
#search-form button {
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  font: inherit;
}
#search-form button:hover { background: var(--hl); }

/* ---------- layout ---------- */
#layout { display: flex; flex: 1; min-height: 0; }

#sidebar {
  width: 16.5rem;
  flex: 0 0 16.5rem;
  border-right: 1px solid var(--rule);
  background: var(--panel);
  overflow-y: auto;
  padding: 0.75rem 0.75rem 1.5rem;
}
#sidebar h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 0.25rem 0.4rem 0.6rem;
}
#text-list { list-style: none; margin: 0; padding: 0; }
#text-list li {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 0.15rem;
}
#text-list li:hover { background: #f3efe6; }
#text-list li.selected { background: var(--hl); }
#text-list .t-title { font-weight: 700; display: block; }
#text-list .t-meta { font-size: 0.8rem; color: var(--ink-soft); }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#status {
  padding: 0 1.25rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
#status.error { color: #b3261e; padding: 0.75rem 1.25rem; }

/* ---------- search hits ---------- */
#search-hits {
  list-style: none;
  margin: 0;
  padding: 0.25rem 1.25rem;
  max-height: 34vh;
  overflow-y: auto;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}
#search-hits li {
  padding: 0.5rem 0.5rem;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
}
#search-hits li:hover { background: #f1f5f9; }
#search-hits mark { background: #fef08a; }
#search-hits .hit-source {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#search-hits .hit-oe { font-family: var(--oe-serif); }
#search-hits .hit-me { color: var(--ink-soft); font-size: 0.92em; }

/* ---------- panes ---------- */
#panes {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#pane-heads {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}
.head {
  padding: 0.4rem 1.25rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}
.head.me-head { border-left: 1px solid var(--rule); }

/* Single shared scroll container => perfect line-for-line sync */
#scroll {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
}
#oe-pane, #rune-pane, #me-pane { padding: 1.1rem 1.25rem 4rem; min-width: 0; }
#me-pane, #rune-pane { border-left: 1px solid var(--rule); }

#oe-pane {
  font-family: var(--oe-serif);
  font-size: calc(1.22rem * var(--oe-scale));
  line-height: 1.9;
}
#rune-pane {
  font-family: var(--runic);
  font-size: calc(1.35rem * var(--oe-scale));
  line-height: 1.9;
}
#me-pane {
  font-family: var(--me-serif);
  font-size: calc(1.02rem * var(--oe-scale));
  line-height: 1.9;
  color: #333;
}

/* Mode visibility (desktop): two columns, third pane hidden */
.mode-latin #rune-pane { display: none; }
.mode-latin #pane-heads .rune-head { display: none; }
.mode-futhorc #oe-pane { display: none; }
.mode-futhorc #pane-heads .latin-head { display: none; }
.mode-parallel #me-pane { display: none; }
.mode-parallel #pane-heads .me-head { display: none; }

.line { padding: 0.1rem 0.4rem; border-radius: 4px; }
.line .lnum {
  display: inline-block;
  width: 2.6rem;
  text-align: right;
  margin-right: 0.6rem;
  color: #b0a891;
  font-size: 0.72em;
  user-select: none;
}
.line.active { background: var(--hl); }
.line.flash { animation: flash 2.2s ease-out; }
@keyframes flash {
  0% { background: #fde68a; }
  100% { background: transparent; }
}
.lacuna {
  text-align: center;
  color: #b0a891;
  letter-spacing: 0.3em;
  padding: 0.6rem 0;
  font-size: 0.8rem;
}

/* tokens */
.token.glossable {
  cursor: pointer;
  border-bottom: 1px dotted #94a3b8;
  transition: background 0.15s;
  border-radius: 2px;
}
.token.glossable:hover,
.token.glossable:focus { background: var(--hl-word); outline-offset: 2px; }
.token.selected { background: #bae6fd; }
.token.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

/* ---------- gloss popover ---------- */
#gloss-popover {
  position: absolute;
  z-index: 100;
  max-width: 340px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 1rem;
}
#gloss-popover.hidden { display: none; }
#gloss-header { display: flex; align-items: baseline; gap: 0.5rem; }
.gloss-lemma { font-weight: 700; font-size: 1.15rem; font-family: var(--oe-serif); }
.gloss-pos { font-style: italic; color: #64748b; font-size: 0.9em; }
#gloss-text { margin: 0.5rem 0 0.25rem; }
#gloss-example {
  margin: 0.5rem 0;
  padding-left: 0.7rem;
  border-left: 3px solid var(--rule);
  font-family: var(--oe-serif);
  color: var(--ink-soft);
}
#gloss-example::before { content: "e.g. "; font-style: italic; }
#gloss-close {
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 6px;
  padding: 0.25rem 0.8rem;
  cursor: pointer;
  font: inherit;
}
#gloss-close:hover { background: #f1f5f9; }

.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- mobile (spec §4.3.5) ---------- */
@media (max-width: 899px) {
  #sidebar-toggle { display: block; }
  #sidebar {
    position: fixed;
    z-index: 50;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }

  /* stack panes; a tab switches which is visible */
  #pane-heads { grid-template-columns: 1fr 1fr; }
  #scroll { grid-template-columns: 1fr; }
  #me-pane, #rune-pane { border-left: none; }
  .mode-latin #oe-pane { display: block; }
  .mode-latin #me-pane { display: none; }
  .mode-latin #rune-pane { display: none; }
  .mode-latin.show-me #oe-pane { display: none; }
  .mode-latin.show-me #me-pane { display: block; }
  .mode-futhorc #rune-pane { display: block; }
  .mode-futhorc #me-pane { display: none; }
  .mode-futhorc #oe-pane { display: none; }
  .mode-futhorc.show-me #rune-pane { display: none; }
  .mode-futhorc.show-me #me-pane { display: block; }
  .mode-parallel #oe-pane { display: block; }
  .mode-parallel #rune-pane { display: none; }
  .mode-parallel #me-pane { display: none; }
  .mode-parallel.show-rune #oe-pane { display: none; }
  .mode-parallel.show-rune #rune-pane { display: block; }
  .oe-head, .latin-head, .me-head, .rune-head { border: none; }
  .head { cursor: pointer; text-align: center; }
  .head.on { color: var(--ink); font-weight: 700; border-bottom: 2px solid var(--accent); }
  #oe-pane { font-size: calc(1.25rem * var(--oe-scale)); }
}
@media (min-width: 900px) {
  .head { cursor: default; }
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}
#mode-toggle, #read-controls { display: flex; gap: 0.3rem; flex-wrap: wrap; }
#mode-toggle button, #read-controls button, .side-btn {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
}
#mode-toggle button[aria-pressed="true"],
#read-controls button[aria-pressed="true"] {
  background: var(--hl);
  border-color: var(--accent);
  color: var(--ink);
}
#mode-toggle button:focus-visible,
#read-controls button:focus-visible,
.side-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#work-meta {
  padding: 0.75rem 1.25rem 0.25rem;
}
#work-meta h2 {
  margin: 0;
  font-family: var(--oe-serif);
  font-size: 1.35rem;
}
#work-byline { margin: 0.2rem 0 0.4rem; color: var(--ink-soft); font-size: 0.9rem; }
#editorial-banner {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 48rem;
}
#font-fallback {
  margin: 0;
  padding: 0.4rem 1.25rem;
  background: #fff7ed;
  color: #9a3412;
  font-size: 0.85rem;
}

.runic, .token.runic, .gloss-runes, #chart-table td.runic {
  font-family: var(--runic);
  /* The bundled NotoSansRunic face is Regular-only (no Bold variant).
     Force bold rendering with font-synthesis (modern, no layout shift)
     plus a -webkit-text-stroke fallback for older WebKit engines. */
  font-weight: 700;
  font-synthesis: bold;
  -webkit-text-stroke: 0.4px currentColor;
}
.token.rune-warn { outline: 1px dashed #b45309; }
.gloss-runes { margin: 0.35rem 0 0; font-size: 1.25rem; }
.gloss-mapping { margin: 0.25rem 0 0; font-size: 0.78rem; color: var(--ink-soft); }

.side-btn { margin: 0.75rem 0.4rem; width: calc(100% - 0.8rem); }
#source-notes {
  padding: 0.75rem 1.25rem 2rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}
#source-notes dl { display: grid; grid-template-columns: 8rem 1fr; gap: 0.2rem 0.8rem; }
#source-notes dt { font-weight: 700; color: var(--ink); }
#source-notes dd { margin: 0; }

#chart-panel {
  position: fixed;
  z-index: 120;
  top: 8vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(52rem, 94vw);
  max-height: 84vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  padding: 1rem 1.2rem 1.4rem;
}
#chart-header { display: flex; justify-content: space-between; align-items: center; }
#chart-header h2 { margin: 0; font-size: 1.1rem; }
#chart-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
#chart-table th, #chart-table td {
  text-align: left;
  border-bottom: 1px solid var(--rule);
  padding: 0.35rem 0.4rem;
  vertical-align: top;
}
#chart-table td.runic { font-size: 1.35rem; }

/* ---------- custom-text transcription (in the Futhorc chart panel) ---------- */
#custom-transcribe {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
#transcribe-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
}
#transcribe-toggle::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
  border: 1px solid var(--rule);
  background: var(--paper);
  transition: background 0.15s ease, border-color 0.15s ease;
}
#transcribe-toggle[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
}
#transcribe-toggle[aria-expanded="true"]::before {
  background: var(--accent);
  border-color: var(--accent);
}
#transcribe-toggle:hover { background: var(--hl); }
#transcribe-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#transcribe-body {
  margin-top: 0.75rem;
}
#transcribe-body label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}
#transcribe-input {
  width: 100%;
  min-height: 4rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
#transcribe-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#transcribe-controls {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
#transcribe-controls button {
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 6px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
}
#transcribe-controls button:hover { background: var(--hl); }
#transcribe-controls button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#transcribe-keys {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
#transcribe-keys button {
  border: 1px solid var(--rule);
  background: var(--panel);
  border-radius: 6px;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
  font: inherit;
  font-size: 1.05rem;
}
#transcribe-keys button:hover { background: var(--hl); }
#transcribe-keys button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
#transcribe-status {
  margin-top: 0.5rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}
#transcribe-status.error { color: var(--error, #b3261e); }
#transcribe-output {
  margin-top: 0.6rem;
  padding: 0.75rem 0.9rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  line-height: 1.7;
}
#transcribe-output p {
  margin: 0 0 0.35rem;
}
#transcribe-output p:last-child { margin-bottom: 0; }
#transcribe-output .runic {
  font-size: 1.5rem;
  font-weight: 700;
  word-break: break-word;
}
#transcribe-warnings {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--warn, #92400e);
}

body.roomy #oe-pane,
body.roomy #rune-pane,
body.roomy #me-pane { line-height: 2.35; }

body.high-contrast {
  --ink: #000;
  --ink-soft: #222;
  --paper: #fff;
  --panel: #fff;
  --rule: #000;
  --accent: #000;
  --hl: #ffea00;
  --hl-word: #00e5ff;
  --error: #7a1310;
  --warn: #6e3a0a;
}
body.high-contrast #oe-pane,
body.high-contrast #me-pane,
body.high-contrast #rune-pane { color: #000; }

/* ---------- voluntary payment widget (t_b0f26b32 item 6) ---------- */
#donat {
  margin-top: 1.25rem;
  padding: 0.75rem 0.6rem 0.9rem;
  border-top: 1px solid var(--rule);
}
#donat .donat-msg {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0.4rem 0.5rem;
  line-height: 1.45;
}
#donat form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0 0.4rem;
  flex-wrap: wrap;
}
#donat label {
  font-size: 0.8rem;
  color: var(--ink-soft);
}
#donat input[type="number"] {
  width: 4.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  background: var(--paper);
  color: var(--ink);
}
#donat .donat-cta {
  margin: 0;
  width: auto;
  flex: 1 1 auto;
}
#donat .donat-fine {
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin: 0.5rem 0.4rem 0;
  line-height: 1.4;
}

