/* ============================================================
   The Narrating Sessions — single shared stylesheet.
   Colour tokens on :root; dark theme via data-theme or system preference.
   ============================================================ */
:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d8;
  --ink: #2a2521;
  --muted: #6f655b;
  --line: #ddd2bf;
  --accent: #8a4b2a;          /* leather brown */
  --accent-ink: #fffaf2;
  --accent-soft: #f1dfd1;
  --onair: #c62828;           /* record light */
  --onair-soft: #fbe3e1;
  --ok: #2e7d4f;
  --ok-soft: #e1f2e7;
  --warn: #a15c00;
  --warn-soft: #fbeed8;
  --err: #b3261e;
  --err-soft: #fbe4e2;
  --sidebar: #2b2420;
  --sidebar-ink: #efe6d8;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --font-ui: 'DM Sans', system-ui, sans-serif;
  --font-read: 'Literata', Georgia, serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #181513;
  --surface: #221e1b;
  --surface-2: #2c2723;
  --ink: #ece4d8;
  --muted: #a99d8f;
  --line: #3b342e;
  --accent: #d99a6c;
  --accent-ink: #1d1512;
  --accent-soft: #3a2a20;
  --onair: #ef5350;
  --onair-soft: #3d1f1d;
  --ok: #6fcf97;
  --ok-soft: #1d3326;
  --warn: #f0b35a;
  --warn-soft: #3a2c16;
  --err: #f28b82;
  --err-soft: #3c1f1c;
  --sidebar: #120f0d;
  --sidebar-ink: #e5dccf;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #181513; --surface: #221e1b; --surface-2: #2c2723; --ink: #ece4d8; --muted: #a99d8f;
    --line: #3b342e; --accent: #d99a6c; --accent-ink: #1d1512; --accent-soft: #3a2a20; --onair: #ef5350;
    --onair-soft: #3d1f1d; --ok: #6fcf97; --ok-soft: #1d3326; --warn: #f0b35a; --warn-soft: #3a2c16;
    --err: #f28b82; --err-soft: #3c1f1c; --sidebar: #120f0d; --sidebar-ink: #e5dccf;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: var(--font-ui); background: var(--bg); color: var(--ink); line-height: 1.55; min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-read); font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; margin-bottom: .6rem; }
h3 { font-size: 1.05rem; margin-bottom: .4rem; }
p + p { margin-top: .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.skip-nav { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-nav:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons: every button has a solid, visible hit target at rest ---------- */
.btn, .icon-btn, .chip, .nav-btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: var(--radius-sm); transition: background .15s, border-color .15s, transform .05s;
}
.btn { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem 1rem; font-weight: 600; font-size: .95rem; text-decoration: none; }
.btn:hover, .icon-btn:hover, .chip:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-record { background: var(--onair); border-color: var(--onair); color: #fff; }
.btn-danger { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
/* shared icon-button hit target (close ×, thumbs, small utility buttons) */
.icon-btn { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip { padding: .3rem .75rem; font-size: .85rem; border-radius: 999px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { font-family: var(--font-read); font-size: 1.35rem; font-weight: 700; padding: 4px 8px 18px; display: flex; align-items: center; gap: .5rem; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--onair); box-shadow: 0 0 0 3px rgba(239, 83, 80, .25); }
.nav-btn { width: 100%; text-align: left; display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem;
  color: var(--sidebar-ink); background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); margin-bottom: 4px; }
.nav-btn:hover { background: rgba(255, 255, 255, .12); }
.nav-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.nav-sep { border-top: 1px solid rgba(255, 255, 255, .12); margin: 10px 4px; }
.sidebar .who { margin-top: auto; padding: 10px 8px 0; font-size: .85rem; opacity: .85; display: flex; align-items: center; gap: .5rem; }
.sidebar .who img { width: 28px; height: 28px; border-radius: 50%; }
.sidebar .who form { margin-left: auto; }
.sidebar .who .btn { color: var(--sidebar-ink); background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .14); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#main { flex: 1; padding: 28px clamp(16px, 4vw, 44px) 24px; max-width: 1180px; width: 100%; }
.mobile-bar { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 50; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .mobile-bar { display: flex; align-items: center; gap: .75rem; padding: 10px 16px; background: var(--sidebar); color: var(--sidebar-ink); position: sticky; top: 0; z-index: 40; }
  .mobile-bar .icon-btn { color: var(--sidebar-ink); background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .14); }
  #main { padding: 18px 16px; }
}

/* ---------- Surfaces ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head p { color: var(--muted); max-width: 60ch; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .num { font-size: 1.7rem; font-weight: 700; font-family: var(--font-read); }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.notice { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); margin: 8px 0; }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }
.notice.error { background: var(--err-soft); border-color: var(--err); color: var(--ink); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.pill { display: inline-block; font-size: .75rem; padding: .1rem .55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.accent { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill.good { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.pill.low { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.pill.medium { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.pill.high { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.list-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: none; }
.list-row .grow { flex: 1; min-width: 0; }

/* piece tiles */
.tile { display: flex; flex-direction: column; gap: 6px; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer; font: inherit; color: inherit; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile .t { font-family: var(--font-read); font-weight: 650; font-size: 1.02rem; }
.tile .meta { display: flex; flex-wrap: wrap; gap: 6px; }
.tile .excerpt { font-family: var(--font-read); color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.done-mark { color: var(--ok); font-weight: 700; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters select, .filters input { max-width: 260px; }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input[type=text], input[type=search], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .65rem; }
textarea { min-height: 110px; resize: vertical; }
textarea.script { font-family: var(--font-read); min-height: 320px; line-height: 1.7; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.range-row { display: grid; grid-template-columns: minmax(90px, 220px) 1fr 64px; gap: 10px; align-items: center; }
.range-row .val { font-size: .85rem; color: var(--muted); }
.help { font-size: .82rem; color: var(--muted); margin-top: 3px; }

/* ---------- The script / reading view ---------- */
.script-view { font-family: var(--font-read); font-size: 1.12rem; line-height: 1.95; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 26px; box-shadow: var(--shadow); max-height: 62vh; overflow-y: auto; }
.script-view.big { font-size: 1.3rem; }
.seg-char { background: color-mix(in srgb, var(--spk) 13%, transparent); border-bottom: 2px solid var(--spk); border-radius: 3px; padding: 0 1px; }
.cast { display: flex; flex-wrap: wrap; gap: 8px; }
.cast-card { border: 1px solid var(--line); border-left: 5px solid var(--spk); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface); min-width: 200px; flex: 1; }
.cast-card .n { font-weight: 700; color: var(--spk); }
.cast-card .h { font-size: .85rem; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--spk); margin-right: 4px; vertical-align: middle; }

/* ---------- Recorder ---------- */
.recorder { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.recorder.live { border-color: var(--onair); box-shadow: 0 0 0 3px var(--onair-soft); }
.rec-top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.rec-light { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.recorder.live .rec-light { background: var(--onair); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5rem; }
.meter { flex: 1; min-width: 120px; height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--warn) 75%, var(--onair)); transition: width .05s; }
.rec-after { margin-top: 12px; display: grid; gap: 10px; }
.rec-after audio { width: 100%; }
.rec-status { font-size: .9rem; color: var(--muted); margin-top: 8px; min-height: 1.3em; }
.rec-status.warn { color: var(--ink); background: var(--warn-soft); border: 1px solid var(--warn); border-radius: var(--radius-sm); padding: 8px 12px; }
.mic-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.mic-row label { margin: 0; font-size: .85rem; white-space: nowrap; }
.mic-row select { max-width: 360px; padding: .35rem .5rem; font-size: .9rem; }
.teleprompt-toggle { margin-left: auto; }

/* ---------- Take review ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.metric .v { font-size: 1.3rem; font-weight: 700; font-family: var(--font-read); }
.metric .k { font-size: .8rem; color: var(--muted); }
.metric .note { font-size: .78rem; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.score-ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.score-ring span { width: 72px; height: 72px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; font-family: var(--font-read); }
.coach-card { border-left: 5px solid var(--accent); }
.coach-head { display: flex; gap: 18px; align-items: center; }
.coach-head .headline { font-family: var(--font-read); font-size: 1.15rem; }
.focus-box { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 14px; }
.focus-box b { color: var(--accent); }
ul.clean { list-style: none; }
ul.clean li { padding: 6px 0 6px 22px; position: relative; }
ul.clean li::before { content: "•"; position: absolute; left: 6px; color: var(--accent); font-weight: 700; }
ul.clean.good li::before { content: "✓"; color: var(--ok); left: 2px; }
.improve { padding: 10px 0; border-top: 1px solid var(--line); }
.improve:first-child { border-top: none; }
.diff del { background: var(--err-soft); color: var(--err); text-decoration: line-through; padding: 0 3px; border-radius: 3px; }
.diff ins { background: var(--ok-soft); color: var(--ok); text-decoration: none; padding: 0 3px; border-radius: 3px; }

/* charts */
.chart { width: 100%; height: auto; display: block; color: var(--muted); }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1.2; }
.chart .tick, .chart .label { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); }
.chart .point-label { font-size: 12px; font-weight: 700; font-family: var(--font-ui); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.sparkline { display: block; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > div { height: 100%; background: var(--accent); }

/* ---------- Modal, toast, busy overlay, feedback bar ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 14, 10, .45); display: grid; place-items: center; z-index: 200; padding: 16px; }
.modal-back[hidden] { display: none; }
.modal { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); width: min(520px, 100%); padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); position: relative; }
.modal .close { position: absolute; top: 12px; right: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 300; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .92rem; }
.toast.error { background: var(--err); color: #fff; }
.busy { position: fixed; inset: 0; background: rgba(20, 14, 10, .35); display: grid; place-items: center; z-index: 250; }
.busy[hidden] { display: none; }
.busy .box { background: var(--surface); border-radius: var(--radius); padding: 22px 28px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); max-width: 90vw; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.feedback-bar { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px clamp(16px, 4vw, 44px) 18px; color: var(--muted); font-size: .85rem; max-width: 1180px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login .art { background: var(--sidebar); color: var(--sidebar-ink); padding: clamp(28px, 6vw, 72px); display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.login .art h1 { font-size: clamp(2rem, 4vw, 3rem); }
.login .art blockquote { font-family: var(--font-read); font-size: 1.15rem; line-height: 1.8; border-left: 3px solid var(--onair); padding-left: 16px; opacity: .92; }
.login .art .q1 { color: #f0a988; } .login .art .q2 { color: #8fd3c7; }
.login .panel { display: grid; place-items: center; padding: 24px 16px; }
.login .box { width: min(380px, 100%); display: grid; gap: 14px; }
.login ul { list-style: none; display: grid; gap: 6px; color: var(--muted); }
@media (max-width: 800px) { .login { grid-template-columns: 1fr; } }

.hidden, [hidden] { display: none !important; }
