:root {
  --bg: #0d0d12;
  --surface: #17171f;
  --surface-2: #22222d;
  --line: #2e2e3a;
  --text: #f4f4f7;
  --muted: #9a9aab;
  --accent: #ff3d6e;
  --accent-2: #ffb341;
  --ok: #3ccf8e;
  --danger: #ff5a5a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 999px; font-weight: 600;
  background: var(--surface-2); transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-sm { padding: 7px 12px; font-size: 13px; }

.coin {
  display: inline-block; width: 1em; height: 1em; border-radius: 50%; vertical-align: -0.12em;
  background: radial-gradient(circle at 35% 35%, #ffe08a, var(--accent-2) 60%, #c47a00);
  box-shadow: inset 0 0 0 1.5px #b36b00;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(var(--bg) 70%, transparent);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.logo span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.nav-link { color: var(--muted); font-weight: 600; font-size: 14px; }
.nav-link.active { color: var(--text); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; background: var(--surface-2); font-weight: 700; font-size: 14px;
}

.page { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 20% 10%, #3b0a45 0, transparent 45%),
              radial-gradient(circle at 90% 90%, #0b3d5c 0, transparent 45%), var(--bg);
}
.login-card { width: 100%; max-width: 420px; }
.login-card .logo { font-size: 34px; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.portals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.portal {
  padding: 14px; border-radius: var(--radius); background: var(--surface);
  border: 2px solid transparent; text-align: left;
}
.portal strong { display: block; font-size: 16px; }
.portal small { color: var(--muted); }
.portal.selected { border-color: var(--accent); }
.portal .emoji { font-size: 24px; display: block; margin-bottom: 6px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 16px; }
.login-card .btn-primary { width: 100%; }

/* ---------- home ---------- */
.hero {
  position: relative; border-radius: 20px; overflow: hidden;
  display: flex; align-items: center; gap: 24px; padding: 24px; margin-bottom: 28px;
}
.hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(120deg, transparent, rgba(0,0,0,.7)); }
.hero > * { position: relative; }
.hero .text { flex: 1; min-width: 0; }
.hero .poster {
  flex: none; width: 150px; aspect-ratio: 9 / 16; border-radius: 12px;
  background-size: cover; background-position: center; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
@media (max-width: 560px) { .hero { flex-direction: column; align-items: flex-start; } .hero .poster { width: 110px; } }
.hero .genre { color: var(--accent-2); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.hero h1 { font-size: clamp(26px, 5vw, 40px); margin: 6px 0 8px; }
.hero p { margin: 0 0 16px; max-width: 520px; color: #ddd; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.rail { margin-bottom: 26px; }
.rail h2 { font-size: 18px; margin-bottom: 12px; }
.rail-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 148px; gap: 12px;
  overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 6px; scrollbar-width: thin;
}
.card { scroll-snap-align: start; }
.card .thumb {
  position: relative; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden;
  background-size: cover; background-position: center; transition: transform .15s;
}
.card:hover .thumb { transform: translateY(-3px); }
.card .badge {
  position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 700; background: rgba(0,0,0,.6);
}
.card .resume { position: absolute; left: 8px; bottom: 8px; right: 8px; font-size: 12px; font-weight: 600; text-shadow: 0 1px 3px #000; }
.card h3 { font-size: 14px; margin-top: 8px; }
.card small { color: var(--muted); font-size: 12px; }

/* ---------- feed ---------- */
.feed-wrap { position: fixed; inset: 0; background: #000; }
.feed {
  height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory;
  scrollbar-width: none; overscroll-behavior: contain;
}
.feed::-webkit-scrollbar { display: none; }
.slide {
  position: relative; height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always;
  display: grid; place-items: center; overflow: hidden;
}
.stage {
  position: relative; height: 100%; width: min(100%, calc(100dvh * 9 / 16));
  background-size: cover; background-position: center;
}
.stage video { width: 100%; height: 100%; object-fit: cover; display: block; background: transparent; }
.stage .tap { position: absolute; inset: 0; }
.paused-icon {
  position: absolute; left: 50%; top: 50%; width: 76px; height: 76px; margin: -38px 0 0 -38px;
  border-radius: 50%; background: rgba(0,0,0,.45); display: none; place-items: center; pointer-events: none;
}
.paused-icon::after { content: ""; border-left: 26px solid #fff; border-top: 16px solid transparent; border-bottom: 16px solid transparent; margin-left: 8px; }
.slide.paused .paused-icon { display: grid; }

.feed-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0,0,0,.55), transparent);
  transition: opacity .35s;
}
.feed-top .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0,0,0,.35); font-size: 18px;
}
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; background: rgba(0,0,0,.35); padding: 6px 10px; border-radius: 999px; }
.switch { width: 34px; height: 20px; border-radius: 999px; background: #555; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle.on .switch { background: var(--accent); }
.toggle.on .switch::after { transform: translateX(14px); }

.info {
  position: absolute; left: 0; right: 70px; bottom: 0; padding: 18px 16px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  transition: opacity .35s; pointer-events: none;
}
.info::before { content: ""; position: absolute; inset: -60px -70px 0 0; background: linear-gradient(transparent, rgba(0,0,0,.7)); z-index: -1; }
.info .ep { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.18); margin-bottom: 6px; }
.info h2 { font-size: 18px; }
.info p { margin: 4px 0 0; font-size: 14px; color: #e4e4e4; }

.rail-actions {
  position: absolute; right: 8px; bottom: 90px; display: flex; flex-direction: column; gap: 16px;
  align-items: center; transition: opacity .35s;
}
.rail-actions button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; text-shadow: 0 1px 3px #000; }
.rail-actions .ic { width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.4); display: grid; place-items: center; font-size: 20px; }
.rail-actions .on .ic { background: var(--accent); }

.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.2); }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); }

.feed-wrap.idle .feed-top,
.feed-wrap.idle .info,
.feed-wrap.idle .rail-actions { opacity: 0; pointer-events: none; }

/* paywall */
.info, .rail-actions { z-index: 2; }
.lock {
  position: absolute; inset: 0; z-index: 1; display: none; place-items: center; padding: 20px;
  background: rgba(10,10,16,.55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.slide.locked .lock { display: grid; }
.feed-wrap.idle .slide.locked .info,
.feed-wrap.idle .slide.locked .rail-actions { opacity: 1; }
.feed-wrap.idle .slide.locked .rail-actions { pointer-events: auto; }
.paywall { width: 100%; max-width: 320px; text-align: center; background: rgba(23,23,31,.92); border-radius: 18px; padding: 22px 18px; }
.paywall .lock-ic { font-size: 34px; }
.paywall h3 { font-size: 19px; margin: 6px 0 4px; }
.paywall p { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.paywall .btn { width: 100%; }
.paywall .balance { margin-top: 12px; font-size: 13px; color: var(--muted); }
.paywall .balance a { color: var(--accent-2); font-weight: 600; }

/* episode sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; max-height: 70dvh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.ep-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.ep-cell { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--surface-2); font-weight: 700; display: grid; place-items: center; }
.ep-cell.current { outline: 2px solid var(--accent); }
.ep-cell .tag { position: absolute; top: 3px; right: 5px; font-size: 10px; }
.ep-cell .free { position: absolute; bottom: 3px; font-size: 9px; color: var(--ok); font-weight: 700; }

/* ---------- wallet / studio ---------- */
.section-title { font-size: 22px; margin: 8px 0 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.stat small { color: var(--muted); font-size: 13px; display: block; }
.stat strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 26px; }
.pack { background: var(--surface); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.pack strong { font-size: 22px; }
.pack .bonus { color: var(--ok); font-size: 13px; font-weight: 600; min-height: 18px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 26px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.plus { color: var(--ok); }
.minus { color: var(--danger); }
.struck { text-decoration: line-through; opacity: .55; }
.mini-thumb { width: 32px; height: 56px; border-radius: 6px; background-size: cover; background-position: center; display: inline-block; vertical-align: middle; margin-right: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.empty { color: var(--muted); padding: 12px 0; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px);
}
.toast {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: #23232e; box-shadow: 0 8px 24px rgba(0,0,0,.4); font-size: 14px; animation: up .2s ease-out;
}
.toast .msg { flex: 1; }
.toast .undo { color: var(--accent-2); font-weight: 700; }
.toast.error { background: #3a1820; }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  .rail-row { grid-auto-columns: 124px; }
}
