/* Olles memoarer. Admin theme by default, narrator theme on body.narrator (spec 14). */

@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/AtkinsonHyperlegible-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/fonts/AtkinsonHyperlegible-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #5a5a5a;
  --line: #d7d4cd;
  --accent: #1f4e79;
  --accent-text: #ffffff;
  --danger: #a4262c;
  --warn-bg: #fff4ce;
  --warn-line: #c19c00;
  --crit-bg: #fde7e9;
  --ok: #107c10;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #1b1b1d;
    --surface: #242427;
    --text: #ececec;
    --muted: #b0b0b0;
    --line: #3d3d42;
    --accent: #8cb8e8;
    --accent-text: #0e1a26;
    --danger: #ff8f94;
    --warn-bg: #3b3210;
    --warn-line: #c19c00;
    --crit-bg: #4a1c20;
    --ok: #6ccb5f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 0.5rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; word-break: break-all; }
.hidden { display: none; }

button, .button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  min-height: 2.5rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button:disabled { opacity: 0.6; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--warn-line);
  outline-offset: 2px;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  min-height: 2.5rem;
  width: 100%;
}

label { display: block; margin: 0.75rem 0 0.25rem; font-weight: 700; }
.field-error { color: var(--danger); font-size: 0.9rem; margin-top: 0.25rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: 0.75rem; }

/* auth pages */
.auth-page { max-width: 26rem; margin: 3rem auto; padding: 0 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.form-actions { margin-top: 1.25rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.notice { border-left: 4px solid var(--accent); background: var(--surface); padding: 0.75rem 1rem; margin: 0.75rem 0; }
.notice.error { border-color: var(--danger); background: var(--crit-bg); }
.notice.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.notice.ok { border-color: var(--ok); }

/* admin shell */
.admin-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
  padding: 0.75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.admin-header .brand { font-weight: 700; font-size: 1.1rem; }
.admin-nav { display: flex; gap: 0.25rem; flex-wrap: wrap; padding: 0 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.admin-nav a { padding: 0.6rem 0.8rem; text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; }
.admin-nav a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 700; }
.banners { padding: 0 1.25rem; }
.admin-main { padding: 1.25rem; max-width: 72rem; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); }
td .row { gap: 0.35rem; }
td button { min-height: 2rem; padding: 0.25rem 0.6rem; font-size: 0.9rem; }

.link-box { background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.qr { background: #fff; padding: 1rem; display: inline-block; margin-top: 0.75rem; }
.qr svg { width: 18rem; height: 18rem; display: block; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.5rem; align-items: end; margin-bottom: 1rem; }
.filters label { margin: 0 0 0.25rem; }

/* tables become cards on small screens (spec 14) */
@media (max-width: 700px) {
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 0.75rem; background: var(--surface); }
  td { border: none; padding: 0.35rem 0.75rem; }
  td[data-label]::before { content: attr(data-label); display: block; font-size: 0.8rem; color: var(--muted); }
}

/* ---- narrator (spec 14): huge, high contrast, few choices ---- */
body.narrator {
  --n-bg: #000000;
  --n-text: #ffffff;
  --n-primary: #ffe600;
  --n-primary-text: #000000;
  --n-secondary-line: #ffffff;
  background: var(--n-bg);
  color: var(--n-text);
  font-size: calc(28px * var(--text-scale, 1)); /* spec 14, times the chosen text size */
}
/* high contrast off (phase 5 preference) */
html.narrator-light body.narrator {
  --n-bg: #ffffff;
  --n-text: #000000;
  --n-primary: #1a1a1a;
  --n-primary-text: #ffffff;
  --n-secondary-line: #000000;
}

.narrator-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.narrator-page h1 { font-size: 1.6em; line-height: 1.2; margin: 0.3em 0 0.8em; }
.narrator-page p { font-size: 1em; line-height: 1.45; margin: 0 0 1em; }
.narrator-page .big-note {
  font-size: 1.1em;
  border: 4px solid var(--n-secondary-line);
  border-radius: 12px;
  padding: 1.5rem;
}
.narrator-actions { display: flex; flex-direction: column; gap: 1.25rem; margin-top: 1.5rem; }
.narrator-page button, .narrator-page .button {
  width: 100%;
  min-height: 88px;
  min-width: 64px;
  font-size: 1.3em; /* 36 px+ primary action text */
  font-weight: 700;
  border-radius: 14px;
  border: 4px solid var(--n-primary);
  background: var(--n-primary);
  color: var(--n-primary-text);
  padding: 1rem 1.25rem;
}
.narrator-page button.secondary, .narrator-page .button.secondary {
  background: transparent;
  color: var(--n-text);
  border-color: var(--n-secondary-line);
}
.narrator-page button:focus-visible, .narrator-page .button:focus-visible {
  outline: 6px solid var(--n-text);
  outline-offset: 4px;
}
.narrator-footer { margin-top: auto; padding-top: 3rem; }
.narrator-status { min-height: 2em; font-size: 1.1em; }

/* session-expired screen covers everything else */
.overlay {
  position: fixed;
  inset: 0;
  max-width: none;
  z-index: 100;
  overflow: auto;
  background: #000000;
  color: #ffffff;
  font-size: 28px;
  padding: 2rem max(1rem, calc((100vw - 720px) / 2));
}

/* ---- phase 2: stories, recorder, import ---- */
input[type="checkbox"] { width: auto; min-height: 0; margin-right: 0.5rem; }
input[type="file"] { padding: 0.35rem; }
label.check { display: flex; align-items: center; font-weight: 400; }
label.inline { display: inline; margin: 0; }
audio { width: 100%; max-width: 36rem; margin: 0.5rem 0; }

.chip { display: inline-block; font-size: 0.8rem; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); margin-right: 0.25rem; }
.chip.bad { border-color: var(--danger); color: var(--danger); }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs a { padding: 0.5rem 0.9rem; text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 700; }
.toolbar { margin-bottom: 1rem; }
.toolbar select { width: auto; }
.recording { margin-top: 1rem; }
.recording.removed { opacity: 0.7; }
.transcript { border-top: 1px solid var(--line); margin-top: 0.75rem; padding-top: 0.5rem; }
.transcript.old { color: var(--muted); }
.transcript-text { white-space: pre-wrap; }
.small-button { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.danger-zone { border-color: var(--danger); margin-top: 1.5rem; }
.import textarea { font-family: inherit; }
.admin-recorder { margin: 1rem 0; }
.admin-recorder .narrator-actions { flex-direction: row; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.admin-recorder .rec-time { font-size: 1.4rem; }

/* level meter: big and plain, so Olle sees that it hears him */
.level { height: 2.5rem; border: 3px solid currentColor; border-radius: 8px; overflow: hidden; margin: 1rem 0; }
.level-fill { height: 100%; background: var(--accent); transition: width 80ms linear; }
body.narrator .level { height: 64px; }
body.narrator .level-fill { background: var(--n-primary); }
.rec-time { font-variant-numeric: tabular-nums; }
body.narrator .rec-time { font-size: 2em; }
.rec-durability { font-variant-numeric: tabular-nums; }
.rec-warning { border: 4px solid var(--warn-line); border-radius: 12px; padding: 1rem; font-weight: 700; }

.narrator-actions.top { margin: 0 0 1rem; }
.row-stack { display: flex; flex-direction: column; gap: 1.25rem; }
.helper-link { color: var(--n-text); font-size: 0.8em; text-align: center; padding: 1rem; display: block; min-height: 64px; }
.story-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.story-item {
  display: block; min-height: 88px; padding: 1rem 1.25rem; border: 4px solid var(--n-secondary-line);
  border-radius: 14px; color: var(--n-text); text-decoration: none;
}
.story-item:focus-visible { outline: 6px solid var(--n-text); outline-offset: 4px; }
.story-date { display: block; font-weight: 700; font-size: 1.1em; }
.story-preview { display: block; }
.story-text { font-size: 1.1em; line-height: 1.6; margin-top: 1.5rem; }
.story-text p { white-space: pre-wrap; }

/* helper mode (spec 14): normal size, clear */
body.helper { font-size: 20px; }
.helper-page { max-width: 48rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.big-back { width: 100%; min-height: 64px; font-size: 1.2em; font-weight: 700; margin-bottom: 1rem; }
.story-text-small { white-space: pre-wrap; }

/* phase 3: long hashes and paths, command output */
.break { overflow-wrap: anywhere; word-break: break-all; }
button.small { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
pre.mono { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 16rem; overflow: auto; }

/* phase 4: search, text editor, suggestions, history, glossary */
.search { margin: 0.5rem 0; }
.search input { flex: 1 1 16rem; width: auto; }
.filter-chips { margin-bottom: 1rem; }
.chip-button { min-height: 2rem; padding: 0.2rem 0.8rem; border-radius: 999px; font-size: 0.9rem; background: transparent; color: var(--accent); }
.chip-button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.chip.suggestion { border-color: var(--warn-line); background: var(--warn-bg); }
.snippet { margin: 0.25rem 0 0; color: var(--muted); }
mark { background: var(--warn-bg); color: var(--text); font-weight: 700; padding: 0 0.1rem; }

.text-section { margin: 1.5rem 0; }
.editor-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .editor-layout { grid-template-columns: minmax(0, 1fr); } }
.body-editor { font-size: 1.05rem; line-height: 1.6; min-height: 24rem; resize: vertical; }
.dirty { color: var(--danger); font-weight: 700; }
.push-right { margin-left: auto; }
.side-panel .raw { border-top: 1px solid var(--line); padding-top: 0.5rem; margin-top: 0.5rem; }
.side-panel h4 { margin: 0.25rem 0; }
.side-panel .story-time { margin-bottom: 1rem; }
.notes-card { margin-top: 1rem; }
.notes-card h4, .suggestion h4, .conflict h4 { margin: 0.75rem 0 0.25rem; }
.missing { font-weight: 700; }
.side-by-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 0.75rem; }
@media (max-width: 700px) { .side-by-side { grid-template-columns: minmax(0, 1fr); } }
.side-by-side > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; }
.text-block { white-space: pre-wrap; line-height: 1.55; max-height: 32rem; overflow: auto; }
ins { background: #dff6dd; color: #0b3d0b; text-decoration: underline; }
del { background: #fde7e9; color: #6b0f14; text-decoration: line-through; }
@media (prefers-color-scheme: dark) {
  :root:not(.light) ins { background: #173d17; color: #d6f5d3; }
  :root:not(.light) del { background: #4a1c20; color: #ffd6d9; }
}
.history { margin-top: 1rem; }
.history-table input[type="radio"] { width: auto; min-height: 0; }
.diff { margin-top: 1rem; }
.glossary-add .filters { align-items: end; }
.story-sub { font-size: 0.8em; opacity: 0.85; }

/* phase 5: listening (spec 10) */
.reading-page { padding-bottom: max(320px, 55vh); } /* the fixed bar never hides the last buttons */
.unit-title { cursor: pointer; }
.reading-text {
  font-size: calc(32px * var(--text-scale, 1));
  line-height: 1.6;
  max-width: 45ch; /* long lines are hard with central vision loss */
  margin-top: 1rem;
}
@media (max-width: 700px) { .reading-text { max-width: 30ch; } }
.reading-text p { margin: 0 0 1em; }
.unit { cursor: pointer; border-radius: 6px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.unit.current, .unit-title.current {
  background: #ffe600;
  color: #000000;
  border-left: 0.3em solid var(--n-text);
  padding: 0.05em 0.15em;
}
.end-panel {
  border: 4px solid var(--n-primary);
  border-radius: 14px;
  padding: 1.25rem;
  margin: 1.5rem 0 0;
}
.end-panel h2 { font-size: 1.2em; font-weight: 700; margin: 0 0 0.5em; }
.bar-panel p, .narrator-page .bar-note { font-size: 1em; font-weight: 700; margin: 0 0 0.25em; }
.bar-panel .narrator-actions { margin-top: 0.5rem; gap: 12px; }
.control-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px max(1rem, calc((100vw - 720px) / 2)) max(12px, env(safe-area-inset-bottom));
  background: var(--n-bg);
  border-top: 4px solid var(--n-secondary-line);
  font-size: calc(28px * min(var(--text-scale, 1), 1.25)); /* the bar stays on screen at large text */
  max-height: 50vh;
  overflow-y: auto;
}
.control-row { display: flex; gap: 12px; }
.control-row > * { flex: 1 1 0; }
.narrator-page .control-bar button { min-height: 88px; }
.story-item.reading-now { background: var(--n-primary); color: var(--n-primary-text); border-color: var(--n-primary); }
.setting { border-top: 3px solid var(--n-secondary-line); margin-top: 1.5rem; padding-top: 1rem; }
.setting h2 { font-size: 1.2em; margin: 0 0 0.5em; }
.setting-value { font-weight: 700; }
.setting-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.setting-row > * { flex: 1 1 12rem; }
.narrator-page button:disabled { opacity: 0.45; }

/* share links (phase 6) */
.shares { margin-top: 2rem; }
.share-link { width: 100%; }
.share-list { list-style: none; padding: 0; margin: 0; }
.share-item { border-top: 1px solid var(--line); padding: 0.75rem 0; }
.share-item.revoked { opacity: 0.75; }
.share-sheet .row, .share-item .row { margin: 0.5rem 0; }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
label.check input { width: 1.4rem; height: 1.4rem; }
.story-shared { font-weight: 700; }
