@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400..800&family=Martian+Mono:wght@400;500;600&display=swap');

:root {
  --paper: #ece7d9;
  --paper-2: #e2dccb;
  --ink: #14130f;
  --ink-soft: #4a473d;
  --ink-faint: #8a857440;
  --line: #14130f;
  --acid: #c8f23a;
  --acid-deep: #a6cf1f;
  --flag: #ff5a1f;
  --good: #1f9d55;
  --display: 'Syne', sans-serif;
  --mono: 'Martian Mono', ui-monospace, monospace;
  /* text on a lime (acid) surface — always dark, in both themes */
  --on-acid: #14130f;
  /* "inverted" chips (logo box, submit, mp3, kindtag·audio): dark fill + lime text in
     light mode, lime fill + dark text in dark mode */
  --chip-bg: var(--ink);
  --chip-fg: var(--acid);
}

/* ── dark theme (data-theme set by the head script: saved choice, else OS preference) ── */
:root[data-theme="dark"] {
  --paper: #17160f;
  --paper-2: #211f16;
  --ink: #ece7d9;
  --ink-soft: #b4ae9b;
  --ink-faint: #ece7d926;
  --line: #ece7d9;
  /* a calmer lime in the dark — the full-bright acid is harsh on a dark ground */
  --acid: #a9c93b;
  --acid-deep: #8fad2c;
  --flag: #ff7a45;
  --good: #36c074;
  --chip-bg: var(--acid);
  --chip-fg: var(--on-acid);
}
:root[data-theme="dark"] body {
  background-image:
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(236,231,217,0.025) 18px 19px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
html, body { max-width: 100%; overflow-x: hidden; }

/* on-brand scrollbars everywhere (acid thumb, ink border, flag on hover) */
* { scrollbar-width: thin; scrollbar-color: var(--acid-deep) var(--paper-2); }
::-webkit-scrollbar { width: 13px; height: 13px; }
::-webkit-scrollbar-track { background: var(--paper-2); }
::-webkit-scrollbar-thumb {
  background: var(--acid); border: 2px solid var(--ink); border-radius: 7px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--flag); }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 500;
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  background-image:
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(20,19,15,0.018) 18px 19px);
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ── header / manifest bar ── */
.topbar {
  display: flex;
  align-items: stretch;
  border-bottom: 2.5px solid var(--ink);
  margin-bottom: 0;
}
.topbar .logo {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.04em;
  padding: 18px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
}
.topbar .logo .box {
  background: var(--chip-bg);
  color: var(--chip-fg);
  padding: 2px 9px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
}
.topbar nav {
  margin-left: auto;
  display: flex;
  align-items: stretch;
}
.topbar nav a {
  display: flex;
  align-items: center;
  padding: 0 22px;
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  color: var(--ink);
  border-left: 2.5px solid var(--ink);
  transition: background 0.15s, color 0.15s;
}
.topbar nav a:hover, .topbar nav a.active { background: var(--chip-bg); color: var(--chip-fg); }

/* ── theme toggle (light / dark) ── */
.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  padding: 0 18px;
  background: transparent;
  border: none;
  border-left: 2.5px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--chip-bg); color: var(--chip-fg); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }

/* ── hero ── */
.hero { padding: 44px 0 32px; position: relative; }
.hero .stamp {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  border: 2px solid var(--ink);
  padding: 5px 12px;
  border-radius: 4px;
  margin-bottom: 26px;
  transform: rotate(-1.5deg);
}
.hero .stamp-tr {
  position: absolute;
  top: 40px;
  right: 0;
  margin-bottom: 0;
  transform: rotate(2.5deg);
  background: var(--acid);
  color: var(--on-acid);
}
.hero h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.2rem, 10vw, 4.6rem);
  line-height: 0.94;
  letter-spacing: -0.05em;
  margin-bottom: 22px;
  overflow-wrap: break-word;
}
.hero h1 .mark {
  background: var(--acid);
  color: var(--on-acid);
  padding: 0 0.12em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.hero p.lede {
  font-size: 1.15rem;
  color: var(--ink-soft);
  max-width: 44ch;
  margin-bottom: 40px;
}

/* compact hero once a fetch starts: drop heading, lede and the sticker;
   the input rises right under the header */
.hero.compact { padding-top: 24px; }
.hero.compact h1,
.hero.compact .lede,
.hero.compact .stamp-tr { display: none; }
.reset-link {
  display: none;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 14px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.reset-link:hover { color: var(--flag); }
.hero.compact .reset-link { display: inline-block; }
/* booted from a ?v= link: collapse the hero before app.js runs (mirrors .compact) */
html.booting .hero { padding-top: 24px; }
html.booting .hero h1,
html.booting .hero .lede,
html.booting .hero .stamp-tr { display: none; }
html.booting .hero .reset-link { display: inline-block; }

/* ── fetch form ── */
.fetchbar {
  display: flex;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: var(--paper-2);
  overflow: hidden;
  max-width: 680px;
  box-shadow: 6px 6px 0 var(--ink);
}
.fetchbar input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.92rem;
  padding: 18px 20px;
}
.fetchbar input::placeholder { color: var(--ink-soft); opacity: 0.7; }
.fetchbar .paste-btn {
  background: transparent;
  border: none;
  border-left: 2px solid var(--ink);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  padding: 0 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fetchbar .paste-btn:hover { background: var(--acid); color: var(--on-acid); }
.fetchbar button[type="submit"] {
  background: var(--chip-bg);
  color: var(--chip-fg);
  border: none;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1rem;
  padding: 0 32px;
  cursor: pointer;
  letter-spacing: -0.02em;
  transition: background 0.15s, color 0.15s;
}
.fetchbar button[type="submit"]:hover { background: var(--acid); color: var(--on-acid); }
.fetchbar button[type="submit"]:disabled { opacity: 0.55; cursor: wait; }
.fetchbar button[type="submit"] .sm { display: none; }

.platforms {
  margin-top: 18px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.note { color: var(--flag); font-family: var(--mono); font-size: 0.82rem; margin-top: 14px; min-height: 1.2em; }

/* ── result card ── */
.result { padding: 8px 0 80px; }
.result[hidden] { display: none; }

.ticket {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--paper-2);
  box-shadow: 8px 8px 0 var(--ink);
  overflow: hidden;
  margin-top: 8px;
}
.ticket-head {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 20px;
  padding: 22px;
  border-bottom: 2.5px dashed var(--ink);
}
.ticket-head .thumb {
  width: 160px; height: 90px;
  object-fit: cover;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
}
.ticket-head .meta h3 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ticket-head .meta .sub {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  display: flex; gap: 14px; flex-wrap: wrap;
}
.ticket-head .meta .expiry {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--flag);
  margin-top: 8px;
}
.ticket-head .meta .platform-badge {
  display: inline-block;
  background: var(--acid);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 1px 8px;
  font-weight: 600;
  color: var(--on-acid);
  text-transform: uppercase;
}

.formats { padding: 18px 22px; display: flex; flex-direction: column; gap: 0; }
.fmt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-bottom: 1.5px solid var(--ink-faint);
}
.fmt:last-child { border-bottom: none; }
.fmt .kindtag {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  padding: 3px 7px;
}
.fmt .kindtag.audio { background: var(--chip-bg); color: var(--chip-fg); }
.fmt .kindtag.transcript { background: var(--ink-soft); color: var(--paper); border-color: var(--ink-soft); }

/* in-page debug log */
#dbg {
  position: fixed;
  left: 8px; bottom: 8px;
  z-index: 9999;
  margin: 0;
  max-width: min(92vw, 520px);
  max-height: 22px;
  overflow: hidden;
  background: #14130f;
  color: #c8f23a;
  font-family: var(--mono, monospace);
  font-size: 11px;
  line-height: 1.4;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0.82;
  cursor: pointer;
  white-space: pre-wrap;
  word-break: break-word;
}
#dbg.open { max-height: 45vh; overflow-y: auto; opacity: 0.97; }
.fmt .lbl { font-weight: 600; font-size: 1rem; }
.fmt .size { font-family: var(--mono); font-size: 0.76rem; color: var(--ink-soft); margin-left: auto; }
.fmt .grab {
  background: var(--acid);
  color: var(--on-acid);
  border: 2px solid var(--ink);
  border-radius: 7px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.88rem;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 3px 3px 0 var(--ink);
}
.fmt .grab:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.fmt .grab:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.fmt .grab[data-state="run"] { background: var(--paper); color: var(--ink); cursor: wait; }
.fmt .grab[data-state="done"] { background: var(--good); color: var(--paper); }
/* direct download link styled as a grab button */
.fmt a.grab { display: inline-block; text-decoration: none; color: var(--on-acid); }
.fmt .lbl .muted { color: var(--ink-soft); font-weight: 400; font-size: 0.85em; }
/* in-browser MP3 convert (primary) + the raw m4a/opus link (secondary, ghost) */
.fmt .grab.mp3 { background: var(--chip-bg); color: var(--chip-fg); }
.fmt .grab.mp3:hover { background: var(--chip-bg); }
.fmt a.grab.ghost {
  background: transparent; color: var(--ink); box-shadow: none; border-width: 1.5px;
  font-size: 0.76rem; padding: 7px 11px; margin-left: 8px;
}
.fmt a.grab.ghost:hover { background: var(--acid); color: var(--on-acid); transform: none; box-shadow: none; }

.loading {
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--ink-soft);
  padding: 36px 0;
  display: flex; align-items: center; gap: 14px;
}
.belt {
  width: 60px; height: 14px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 8px, transparent 8px 16px);
  background-size: 16px 100%;
  animation: belt 0.7s linear infinite;
}
@keyframes belt { to { background-position: 16px 0; } }

footer {
  border-top: 2.5px solid var(--ink);
  padding: 22px 0 44px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
footer a { color: var(--ink); text-decoration: none; border-bottom: 1.5px solid var(--ink); }

.reveal { animation: rise 0.5s cubic-bezier(0.2,0.9,0.2,1) both; }
@keyframes rise { from { opacity:0; transform: translateY(16px); } to { opacity:1; transform:none; } }

/* ── mobile ── */
@media (max-width: 560px) {
  .topbar .logo { font-size: 1.2rem; padding: 14px 0; }
  .topbar nav a { padding: 0 12px; font-size: 0.66rem; }
  .hero { padding: 40px 0 28px; }
  .hero h1 { font-size: clamp(2.4rem, 11vw, 4rem); text-wrap: balance; }
  .hero h1 br { display: none; }
  .fetchbar button[type="submit"] { padding: 0 18px; }
  .fetchbar button[type="submit"] .lg { display: none; }
  .fetchbar button[type="submit"] .sm { display: inline; }
  .fetchbar { box-shadow: 4px 4px 0 var(--ink); }
  .fetchbar button { padding: 0 20px; }
  .ticket-head { grid-template-columns: 1fr; }
  .ticket-head .thumb { width: 100%; height: auto; aspect-ratio: 16/9; }
}

/* ── tabs (YouTube: Download | Transcript) ── */
.tabs { display: flex; gap: 0; border-bottom: 2.5px dashed var(--ink); padding: 0 22px; }
.tab {
  background: none; border: none; cursor: pointer;
  font-family: var(--display); font-weight: 800; font-size: 0.95rem;
  letter-spacing: -0.01em; color: var(--ink-soft);
  padding: 14px 18px; border-bottom: 3px solid transparent; margin-bottom: -2.5px;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--flag); }
.panel[hidden] { display: none; }

/* ── transcript ── */
.tr-wrap { display: grid; grid-template-columns: minmax(0, 360px) 1fr; gap: 20px; padding: 20px 22px; align-items: start; }
.tr-player { position: sticky; top: 16px; }
.tr-player > div, .tr-player iframe {
  width: 100%; aspect-ratio: 16 / 9; border: 2px solid var(--ink); border-radius: 8px; background: #000; display: block;
}
.tr-side { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.tr-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tr-actions .grab {
  background: var(--acid); border: 2px solid var(--ink); border-radius: 7px;
  font-family: var(--display); font-weight: 700; font-size: 0.85rem; padding: 9px 16px;
  cursor: pointer; box-shadow: 3px 3px 0 var(--ink); transition: transform 0.1s, box-shadow 0.1s; color: var(--on-acid);
}
.tr-actions .grab:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.tr-actions .grab:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.tr-actions .grab.ghost { background: transparent; color: var(--ink); box-shadow: none; }
.tr-actions .grab.ghost:hover { background: var(--acid); color: var(--on-acid); transform: none; box-shadow: none; }

.tr-list {
  max-height: 60vh; overflow-y: auto;
  border: 1.5px solid var(--ink-faint); border-radius: 8px;
  /* on-brand scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--acid-deep) var(--paper);
}
.tr-list::-webkit-scrollbar { width: 13px; }
.tr-list::-webkit-scrollbar-track { background: var(--paper); border-left: 1.5px solid var(--ink-faint); }
.tr-list::-webkit-scrollbar-thumb {
  background: var(--acid); border: 2px solid var(--ink); border-radius: 7px;
  background-clip: padding-box;
}
.tr-list::-webkit-scrollbar-thumb:hover { background: var(--flag); }
.tr-seg {
  display: flex; gap: 12px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--ink-faint);
  padding: 9px 12px; cursor: pointer; font-family: var(--display); font-size: 0.92rem; color: var(--ink);
  transition: background 0.1s;
}
.tr-seg:last-child { border-bottom: none; }
.tr-seg:hover { background: var(--acid); color: var(--on-acid); }
.tr-seg .tr-t { flex-shrink: 0; font-family: var(--mono); font-size: 0.74rem; color: var(--flag); padding-top: 2px; min-width: 44px; }
.tr-seg:hover .tr-t { color: var(--on-acid); }
.tr-seg .tr-x { line-height: 1.35; }
.tr-empty { padding: 22px 12px; color: var(--ink-soft); font-family: var(--mono); font-size: 0.85rem; }

@media (max-width: 720px) {
  .tr-wrap { grid-template-columns: 1fr; }
  .tr-player { position: static; }
}

/* transcript without timestamps (kome fallback) — plain readable paragraphs */
.tr-list.tr-plain { padding: 6px 14px; }
.tr-list .tr-line { font-family: var(--display); font-size: 0.92rem; line-height: 1.5; padding: 5px 0; border-bottom: 1px solid var(--ink-faint); }
.tr-list .tr-line:last-child { border-bottom: none; }
