/* Tartine: lake-mist paper, deep ink, and one yellow marker that follows the voice. */

:root {
  --paper: #e9eef0;
  --surface: #f7f9f9;
  --ink: #17222c;
  --muted: #5c6b76;
  --rule: #cdd6db;
  --lake: #2e5e74;
  --lake-ink: #ffffff;
  --marker: #f4cd4f;
  --marker-soft: rgba(244, 205, 79, 0.45);
  --danger: #a33a2c;

  --serif: 'Newsreader', 'Iowan Old Style', 'Georgia', serif;
  --sans: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --measure: 36rem;
  --gutter: clamp(1.1rem, 5vw, 2rem);

  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141c24;
    --surface: #1b2530;
    --ink: #e4eaee;
    --muted: #93a3ae;
    --rule: #2b3844;
    --lake: #8ec3d8;
    --lake-ink: #0f2330;
    --marker: #c9a634;
    --marker-soft: rgba(201, 166, 52, 0.38);
    --danger: #f08b7c;
  }
}

*, *::before, *::after { box-sizing: inherit; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}
body.has-player { padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); }
body.has-journal { padding-bottom: calc(10rem + env(safe-area-inset-bottom, 0px)); }

#app {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 3rem;
}

a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--lake); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }

.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- buttons ---------- */

.btn {
  font: 500 0.95rem/1 var(--sans);
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--lake); border-color: var(--lake); color: var(--lake-ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn .icon { width: 1.1em; height: 1.1em; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.75rem; height: 2.75rem;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn .icon { width: 1.4rem; height: 1.4rem; }
.icon-btn.spinning .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.text-btn { font: 500 0.85rem var(--sans); background: none; border: 0; padding: 0.5rem; color: var(--muted); cursor: pointer; }
.text-btn.danger { color: var(--danger); }

/* ---------- masthead ---------- */

.masthead { padding: 0.75rem 0 1.25rem; }
.mast-row { display: flex; align-items: center; justify-content: space-between; }
.mast-actions { display: flex; margin-right: -0.6rem; }
.hello {
  font: 500 2.6rem/1.05 var(--serif);
  font-variation-settings: 'opsz' 72;
  letter-spacing: -0.02em;
  margin: 0;
}
.date { font: 400 1.05rem var(--sans); color: var(--muted); margin: 0.35rem 0 0; }
.date::first-letter { text-transform: uppercase; }



/* ---------- feed ---------- */

.feed { display: flex; flex-direction: column; }

.story {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1.35rem 0;
  border-top: 1px solid var(--rule);
  text-decoration: none;
}
.story:first-child { border-top: 0; padding-top: 0; }
.story.lead { grid-template-columns: 1fr; }

.meta { font: 400 0.84rem/1.4 var(--sans); color: var(--muted); margin: 0 0 0.35rem; }

.headline {
  font: 600 1.3rem/1.22 var(--serif);
  font-variation-settings: 'opsz' 36;
  letter-spacing: -0.005em;
  margin: 0 0 0.4rem;
}
.lead .headline { font-size: 1.85rem; line-height: 1.12; font-variation-settings: 'opsz' 60; letter-spacing: -0.015em; }

.dek { font-size: 1.02rem; line-height: 1.5; color: var(--muted); margin: 0; }
.lead .dek { font-size: 1.1rem; color: var(--ink); }

.story.read .headline { color: var(--muted); font-weight: 500; }

.lead-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; margin-bottom: 0.3rem; background: var(--rule); }
.thumb { width: 5.5rem; height: 5.5rem; object-fit: cover; border-radius: 8px; background: var(--rule); margin-top: 1.6rem; }

.end { font: 400 0.9rem var(--sans); color: var(--muted); padding: 2rem 0; border-top: 1px solid var(--rule); margin: 0; }

.empty { padding: 2.5rem 0; font-size: 1.15rem; }
.empty p { margin: 0 0 1.25rem; max-width: 28rem; }

/* ---------- the marker: follows the voice ---------- */

.hl, .tapped {
  background-image: linear-gradient(var(--marker-soft), var(--marker-soft));
  background-repeat: no-repeat;
  background-position: 0 85%;
  background-size: 100% 72%;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  border-radius: 2px;
}
.hl { animation: sweep 0.45s cubic-bezier(0.3, 0.7, 0.2, 1) both; }
.tapped { background-image: linear-gradient(var(--marker), var(--marker)); color: #17222c; }
@keyframes sweep { from { background-size: 0% 72%; } }

/* ---------- reader ---------- */

.reader-nav { margin: 0 0 1.5rem -0.4rem; }
.back { display: inline-flex; align-items: center; gap: 0.2rem; font: 500 0.95rem var(--sans); color: var(--muted); text-decoration: none; padding: 0.5rem 0.4rem; }

.reader-title {
  font: 600 2.1rem/1.12 var(--serif);
  font-variation-settings: 'opsz' 60;
  letter-spacing: -0.015em;
  margin: 0.2rem 0 1.25rem;
}
.reader-fig { margin: 0 0 1.4rem; }
.reader-fig img { width: 100%; border-radius: 10px; max-height: 60vh; object-fit: cover; }
.reader-dek { font-size: 1.3rem; line-height: 1.45; margin: 0 0 1.5rem; font-style: italic; }
.reader-body p { margin: 0 0 1.15rem; line-height: 1.68; }

.w { cursor: pointer; border-radius: 2px; }
@media (hover: hover) { .w:hover { background: var(--marker-soft); } }

.note { font: 400 0.92rem/1.5 var(--sans); color: var(--muted); }
.original { display: inline-block; font: 500 0.95rem var(--sans); color: var(--lake); margin-top: 2rem; }

/* ---------- speak-back ---------- */

.retell { margin-top: 2.5rem; padding-top: 1.75rem; border-top: 1px solid var(--rule); }
.retell-q { font-size: 1.25rem; font-weight: 500; margin: 0 0 1rem; }
.retell-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.retell-write { display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; margin-top: 0.8rem; }
.retell-write textarea { width: 100%; }
.btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.recording .icon { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.retell-live {
  margin: 1.2rem 0 0; padding: 0 0 0 1rem;
  border-left: 3px solid var(--marker);
  font-style: italic; color: var(--muted);
}
.retell-out { margin-top: 1.2rem; display: flex; flex-direction: column; gap: 1.1rem; align-items: flex-start; }
.bubble { background: var(--surface); border-radius: 4px 16px 16px 16px; padding: 0.9rem 1.1rem; }
.bubble p, .said-better p { margin: 0 0 0.5rem; }
.small-label { font: 500 0.85rem var(--sans); color: var(--muted); margin: 0 0 0.25rem !important; }
.better { font-size: 1.15rem; }
.say { display: inline-flex; align-items: center; gap: 0.35rem; font: 500 0.85rem var(--sans); color: var(--lake); background: none; border: 0; padding: 0.3rem 0; cursor: pointer; }
.say .icon { width: 1.1rem; height: 1.1rem; }
.fixes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.fix-row { display: flex; flex-wrap: wrap; gap: 0.2rem 0.7rem; }
.fix-row s { color: var(--muted); text-decoration-color: var(--danger); }
.fix-note { display: block; font: 400 0.85rem/1.4 var(--sans); color: var(--muted); }
.thinking .dots, .dots { font: 600 1.4rem var(--sans); color: var(--muted); animation: pulse 1s ease-in-out infinite; }

/* ---------- player bar ---------- */

#player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; align-items: center; gap: 0.75rem;
  padding: 0.75rem var(--gutter) calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--rule);
}
.play-btn {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font: 600 1rem var(--sans);
  padding: 0.8rem 1.6rem; border-radius: 999px; border: 0;
  background: var(--ink); color: var(--paper); cursor: pointer;
}
.rate-btn { font: 500 0.9rem var(--sans); background: none; border: 1px solid var(--rule); color: var(--muted); border-radius: 999px; padding: 0.6rem 0.9rem; cursor: pointer; min-width: 4rem; }

/* ---------- word popover ---------- */

#pop {
  position: fixed; z-index: 20;
  max-width: min(18rem, calc(100vw - 20px));
  background: var(--ink); color: var(--paper);
  border-radius: 12px;
  padding: 0.65rem 0.9rem 0.75rem;
  box-shadow: 0 10px 30px -12px rgba(10, 20, 30, 0.55);
  animation: pop-in 0.14s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(4px); } }
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.pop-word { font: 600 1.2rem/1.2 var(--serif); }
.pop-say { background: none; border: 0; color: var(--marker); padding: 0.25rem; margin: -0.25rem -0.3rem -0.25rem 0; cursor: pointer; display: inline-grid; }
.pop-say .icon { width: 1.35rem; height: 1.35rem; }
.pop-lemma { font: italic 400 0.95rem var(--serif); opacity: 0.7; }
.pop-en { font: 500 1rem/1.35 var(--sans); margin-top: 0.2rem; }

/* ---------- forms & settings ---------- */

input[type='text'], input[type='url'], input[type='password'], textarea, select {
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  width: 100%;
}
textarea { font-family: var(--serif); font-size: 1.05rem; resize: vertical; }

.login { max-width: 22rem; margin: 18vh auto 0; display: flex; flex-direction: column; gap: 0.5rem; }
.login label { font: 500 0.95rem var(--sans); color: var(--muted); margin-top: 1rem; }
.login .btn { align-self: flex-start; }
.login-sub { font-size: 1.15rem; color: var(--muted); margin: 0 0 1.5rem; }
.form-msg { font: 400 0.92rem/1.45 var(--sans); color: var(--muted); margin: 0; min-height: 1.2em; }

.settings-title { font: 500 2.2rem/1.1 var(--serif); letter-spacing: -0.015em; margin: 0 0 0.5rem; }
.settings section { padding: 1.5rem 0; border-top: 1px solid var(--rule); }
.settings section:first-of-type { border-top: 0; }
.settings h2 { font: 600 1.2rem var(--serif); margin: 0 0 0.75rem; }
.hint { font: 400 0.92rem/1.5 var(--sans); color: var(--muted); margin: 0.6rem 0; }
.inline { display: flex; gap: 0.6rem; align-items: center; }
.inline input[type='url'] { flex: 1; }
.add-source .form-msg { margin-top: 0.6rem; }

.source-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.source-list li { padding: 0.85rem 0; border-top: 1px solid var(--rule); }
.source-row { display: flex; align-items: center; gap: 0.85rem; }
.source-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.source-title { font-weight: 500; line-height: 1.3; }
.source-meta { font: 400 0.82rem var(--sans); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.switch { position: relative; display: inline-block; flex: none; width: 2.6rem; height: 1.5rem; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; background: var(--rule); border-radius: 999px; transition: background 0.15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: calc(1.5rem - 6px); height: calc(1.5rem - 6px); border-radius: 50%; background: var(--surface); transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch input:checked + .track { background: var(--lake); }
.switch input:checked + .track::after { transform: translateX(1.1rem); }
.switch input:focus-visible + .track { outline: 2px solid var(--lake); outline-offset: 2px; }

.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.seg { font: 500 0.95rem var(--sans); padding: 0.55rem 0.85rem; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); cursor: pointer; min-width: 3.2rem; }
.seg.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.check-row { display: flex; gap: 0.85rem; align-items: flex-start; font: 400 0.95rem/1.45 var(--sans); margin-top: 1rem; cursor: pointer; }
.check-row .switch { margin-top: 0.1rem; }

.voice { display: flex; flex-direction: column; gap: 0.9rem; align-items: flex-start; }
.voice input[type='range'] { flex: 1; accent-color: var(--lake); }
.voice .inline { width: 100%; }
.voice output { font: 500 0.9rem var(--sans); color: var(--muted); min-width: 3.2rem; text-align: right; }

@media (prefers-reduced-motion: reduce) {
  .hl { animation: none; }
  #pop { animation: none; }
  .icon-btn.spinning .icon, .btn.recording .icon, .dots { animation: none; }
}

@media (min-width: 40rem) {
  .hello { font-size: 3rem; }
  .lead .headline { font-size: 2.2rem; }
  .reader-title { font-size: 2.5rem; }
  .thumb { width: 7rem; height: 7rem; }
}

/* ---------- tag filter ---------- */

.tagbar {
  display: flex; gap: 0.45rem;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)) 1.5rem;
  padding: 0.15rem var(--gutter);
  scroll-padding-inline: var(--gutter);
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%);
}
.tagbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  font: 500 0.92rem/1 var(--sans);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* ---------- journal player ---------- */

#player.journal { flex-direction: column; align-items: stretch; gap: 0.6rem; padding-top: 0.85rem; }
.jp-controls { display: flex; align-items: center; justify-content: center; gap: 0.6rem; }
.jp-main {
  display: inline-flex; align-items: center; gap: 0.65rem;
  min-width: 13.5rem; justify-content: center;
  font: 600 1rem/1.15 var(--sans);
  padding: 0.75rem 1.5rem; border-radius: 999px; border: 0;
  background: var(--ink); color: var(--paper); cursor: pointer;
}
.jp-main .icon { width: 1.3rem; height: 1.3rem; }
.jp-label { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.jp-label small { font: 400 0.8rem var(--sans); opacity: 0.75; }
.jp-skip {
  display: inline-grid; place-items: center;
  width: 2.9rem; height: 2.9rem; border-radius: 50%;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink); cursor: pointer;
}
.jp-skip .icon { width: 1.2rem; height: 1.2rem; }
.jp-stop { color: var(--muted); }
.jp-now { max-width: var(--measure); margin: 0 auto; width: 100%; }
.jp-where { font: 500 0.8rem var(--sans); color: var(--muted); margin: 0; }
.jp-caption {
  font: 400 1.05rem/1.4 var(--serif); margin: 0.15rem 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.8em;
}

.story.on-air { position: relative; }
.story.on-air::before {
  content: ''; position: absolute; left: calc(-1 * var(--gutter) + 0.35rem); top: 1.35rem; bottom: 1.35rem;
  width: 4px; border-radius: 4px; background: var(--marker);
}
.story.lead.on-air::before, .story.on-air:first-child::before { top: 0; }

/* ---------- tags on sources ---------- */

.tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin: 0.55rem 0 0 3.45rem; }
.tag {
  display: inline-flex; align-items: center; gap: 0.1rem;
  font: 500 0.82rem var(--sans);
  padding: 0.2rem 0.25rem 0.2rem 0.65rem;
  border-radius: 999px; background: var(--marker-soft); color: var(--ink);
}
.tag-x { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border: 0; background: none; color: var(--muted); border-radius: 50%; cursor: pointer; }
.tag-x .icon { width: 0.85rem; height: 0.85rem; }
input.tag-input {
  font: 400 0.85rem var(--sans); width: 7rem;
  padding: 0.3rem 0.6rem; border-radius: 999px;
  border: 1px dashed var(--rule); background: transparent; color: var(--ink);
}
.add-source > input[type='text'] { margin-top: 0.6rem; }
.row-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ---------- admin ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.7rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border-radius: 12px; padding: 0.85rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
.stat-value { font: 600 1.7rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.stat-label { font: 500 0.85rem/1.3 var(--sans); }
.stat-sub { font: 400 0.78rem/1.35 var(--sans); color: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 0.3rem; height: 9rem; padding-top: 1.2rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 0.25rem; min-width: 0; }
.bar { width: 100%; min-height: 2px; background: var(--lake); border-radius: 4px 4px 1px 1px; }
.bar-n { font: 500 0.7rem var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-day { font: 500 0.72rem var(--sans); color: var(--muted); text-transform: uppercase; }

.plain-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.45rem 0; border-top: 1px solid var(--rule); font: 400 0.95rem var(--sans); overflow-wrap: anywhere; }
.admin input[type='email'] { flex: 1; }
.admin .small-label { margin-top: 1rem !important; }

.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 0.7rem 0; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 0.2rem; }
.person-main { display: flex; flex-direction: column; min-width: 0; }
.person-meta { font: 400 0.82rem var(--sans); color: var(--muted); }
