@font-face {
  font-family: "Bricolage";
  src: url("/fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson";
  src: url("/fonts/atkinson-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson";
  src: url("/fonts/atkinson-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #f6f5fa;
  --surface: #ffffff;
  --ink: #1e1a2b;
  --muted: #6b6680;
  --line: #e3dfee;
  --accent: #5b3e9e;
  --accent-ink: #ffffff;
  --accent-soft: #ece6f8;
  --sun: #e9a23b;
  --danger: #b3261e;
  --ok: #2e6b4f;
  --radius-s: 6px;
  --radius-l: 14px;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.4rem;
  --step-4: clamp(2.4rem, 6vw, 4.2rem);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15121f;
    --surface: #1f1a2e;
    --ink: #edeaf5;
    --muted: #a9a3bd;
    --line: #322b47;
    --accent: #a88bea;
    --accent-ink: #15121f;
    --accent-soft: #2a2240;
    --danger: #f2a39d;
    --ok: #8fd1b0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* The hidden attribute must win over component display rules (e.g. .btn, form.stack). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 "Atkinson", system-ui, sans-serif;
}
h1, h2, h3 { font-family: "Bricolage", system-ui, sans-serif; line-height: 1.1; margin: 0 0 0.5rem; font-weight: 700; }
h1 { font-size: var(--step-3); letter-spacing: -0.02em; }
h2 { font-size: var(--step-2); letter-spacing: -0.01em; }
h3 { font-size: var(--step-1); }
p { margin: 0 0 1rem; max-width: 68ch; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; }
.skip:focus { left: 1rem; z-index: 10; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.brand { font: 700 var(--step-1)/1 "Bricolage", sans-serif; color: var(--ink); text-decoration: none; letter-spacing: -0.02em; }
.topbar nav { display: flex; gap: clamp(0.75rem, 2.5vw, 1.75rem); flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 700; padding: 0.25rem 0; }
.topbar nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }

main { padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2.5rem) 4rem; max-width: 1080px; margin: 0 auto; }
main:focus { outline: none; }
.lede { color: var(--muted); font-size: var(--step-1); max-width: 52ch; }

/* Library: episode list */
.library-head { margin-bottom: 2rem; }
.library-head h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.035em; max-width: 14ch; }
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.row { border-bottom: 1px solid var(--line); }
.row a {
  display: grid; grid-template-columns: 88px 1fr auto; gap: 1rem; align-items: center;
  padding: 0.9rem 0.25rem; color: inherit; text-decoration: none;
}
.row a:hover .row-title { color: var(--accent); }
.thumb {
  width: 88px; aspect-ratio: 16 / 10; border-radius: var(--radius-s); object-fit: cover;
  background: var(--accent-soft); display: grid; place-items: center; color: var(--accent);
}
.thumb svg { width: 28px; height: 28px; }
.row-title { font-weight: 700; font-size: var(--step-1); line-height: 1.25; }
.row-meta { color: var(--muted); font-size: var(--step--1); }
.badge { font-size: var(--step--1); font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 999px; white-space: nowrap; }
.badge.free { background: var(--accent-soft); color: var(--accent); }
.badge.locked { border: 1px solid var(--line); color: var(--muted); }
.badge.draft { background: var(--sun); color: #2b1d05; }

/* Player */
.player-title { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.04em; line-height: 0.98; margin: 0.5rem 0 1.25rem; max-width: 18ch; }
.stage { background: var(--ink); border-radius: var(--radius-l); overflow: hidden; margin-bottom: 1.5rem; }
.stage video { width: 100%; display: block; max-height: 70vh; background: #000; }
.stage.audio { background: var(--accent); padding: clamp(1.25rem, 4vw, 2.5rem); display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: center; }
.stage.audio img, .stage.audio .disc { width: clamp(96px, 18vw, 180px); aspect-ratio: 1; border-radius: var(--radius-s); object-fit: cover; background: var(--accent-soft); }
.stage.audio audio { width: 100%; }
.stage.playing { box-shadow: 0 0 0 4px var(--sun); }
.locked-panel { border: 2px dashed var(--line); border-radius: var(--radius-l); padding: clamp(1.5rem, 4vw, 2.5rem); margin-bottom: 1.5rem; }
.back { display: inline-block; margin-bottom: 0.5rem; color: var(--muted); text-decoration: none; font-weight: 700; }

/* Forms and buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font: 700 var(--step-0)/1 "Atkinson", sans-serif; padding: 0.8rem 1.2rem; min-height: 44px;
  border-radius: var(--radius-s); border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  cursor: pointer; text-decoration: none;
}
.btn.secondary { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
form.stack, .stack { display: grid; gap: 1rem; max-width: 30rem; }
label { display: grid; gap: 0.35rem; font-weight: 700; }
label .hint { font-weight: 400; color: var(--muted); font-size: var(--step--1); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0.7rem 0.8rem; min-height: 44px; width: 100%;
}
input[type="checkbox"] { width: auto; min-height: 0; }
.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 400; }
.code-input { font-size: var(--step-2); letter-spacing: 0.3em; max-width: 12rem; }
.error { color: var(--danger); font-weight: 700; }
.muted { color: var(--muted); }

/* Plans */
.switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 4px; margin: 0 0.75rem 1.5rem 0; background: var(--surface); }
.switch button { font: 700 var(--step--1) "Atkinson", sans-serif; border: 0; background: none; color: var(--muted); padding: 0.5rem 1rem; border-radius: 999px; cursor: pointer; min-height: 36px; }
.switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.25rem; }
.tier { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.tier.top { border: 2px solid var(--accent); }
.price { font: 800 var(--step-3)/1 "Bricolage", sans-serif; letter-spacing: -0.03em; }
.price small { font: 400 var(--step-0) "Atkinson", sans-serif; color: var(--muted); letter-spacing: 0; }
.pay-option { border-top: 1px solid var(--line); padding-top: 1rem; display: grid; gap: 0.5rem; }
.pay-option p { margin: 0; color: var(--muted); font-size: var(--step--1); }

/* Account and admin */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.5rem; margin-bottom: 1.5rem; }
.status-line { font-size: var(--step-1); font-weight: 700; }
.status-ok { color: var(--ok); }
.status-warn { color: var(--danger); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 1rem 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 700; }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; overflow-x: auto; }
.tabs button { font: 700 var(--step-0) "Atkinson", sans-serif; background: none; border: 0; color: var(--muted); padding: 0.75rem 1rem; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.table-wrap { overflow-x: auto; }
.table-wrap + .panel, .empty + .panel { margin-top: 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: var(--step--1); }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 700; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }
.empty { padding: 2.5rem 0; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%) translateY(150%);
  background: var(--ink); color: var(--paper); padding: 0.8rem 1.2rem; border-radius: var(--radius-s);
  font-weight: 700; max-width: calc(100% - 2rem); transition: transform 0.2s ease, visibility 0.2s;
  visibility: hidden;
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
#toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 560px) {
  .row a { grid-template-columns: 64px 1fr; }
  .row a .badge { grid-column: 2; justify-self: start; }
  .thumb { width: 64px; }
  .stage.audio { grid-template-columns: 1fr; }
  dl.facts { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Renewal / payment notice */
.notice { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
  border-left: 4px solid var(--sun); background: var(--surface); padding: 1rem 1.25rem; border-radius: var(--radius-s); margin-bottom: 1.5rem; }
.notice p { margin: 0; font-weight: 700; }
.more { margin-top: 1.25rem; }
.turnstile { min-height: 65px; }
