:root {
  --ink: #0c0c0e;
  --ink-raised: #18181c;
  --paper: #ebe7de;
  --mist: #9d9ba3;
  --gold: #c6a35e;
  --gold-soft: rgb(198 163 94 / 0.16);
  --line: rgb(255 255 255 / 0.09);
  --glass: rgb(255 255 255 / 0.06);
  --danger: #d98a7a;
  --gutter-l: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  --serif: 'Cormorant Garamond', 'Times New Roman', serif;
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--paper);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: 0.35; cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--ink);
}
.backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.2);
  filter: blur(32px) grayscale(0.35) brightness(0.32);
}
.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgb(12 12 14 / 0.2), var(--ink) 85%);
}

.masthead {
  padding: calc(env(safe-area-inset-top) + 14px) var(--gutter-r) 10px var(--gutter-l);
  text-align: center;
}
.masthead h1 {
  margin: 0;
  font: 700 26px/1.1 var(--serif);
  letter-spacing: 0.04em;
  color: var(--gold);
}
.masthead p { margin: 2px 0 0; font-size: 13px; color: var(--mist); letter-spacing: 0.08em; }

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--gutter-r) calc(96px + env(safe-area-inset-bottom)) var(--gutter-l);
}

.player { display: grid; gap: 14px; padding-bottom: 20px; }

.notice {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: var(--gold-soft);
}

.resume {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid rgb(198 163 94 / 0.5);
  border-radius: 12px;
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}
.resume::before { content: '▶\FE0E'; margin-right: 10px; font-size: 13px; }

.cover {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(135deg, #26262b, #111114);
  box-shadow: 0 18px 40px rgb(0 0 0 / 0.55), 0 0 0 1px var(--line);
}
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 48px;
  border: 3px solid rgb(255 255 255 / 0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s;
  animation: spin 0.9s linear infinite;
}
[data-status='loading'] .spinner { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.ep-title {
  margin: 4px 0 0;
  font: 700 32px/1.1 var(--serif);
  font-variant-numeric: lining-nums;
  text-align: center;
}
.ep-title small { font-size: 18px; color: var(--mist); font-weight: 600; }

.seek input {
  --track: linear-gradient(to right, var(--gold) calc(var(--fill, 0) * 100%), rgb(255 255 255 / 0.18) 0);
  display: block;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
}
.seek input::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--track); }
.seek input::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
.seek input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 0 0 4px rgb(198 163 94 / 0.35);
}
.seek input::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--paper); }
.times {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}

.controls { display: flex; align-items: center; justify-content: space-between; max-width: 400px; width: 100%; margin: 0 auto; }

.icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition: background 0.15s, transform 0.1s;
}
.icon:active { transform: scale(0.94); background: var(--glass); }
.icon svg { width: 30px; height: 30px; fill: currentColor; }
.icon text { font-size: 6.4px; font-weight: 700; text-anchor: middle; font-family: inherit; }
.icon.play { width: 76px; height: 76px; background: var(--gold); color: var(--ink); box-shadow: 0 8px 24px rgb(198 163 94 / 0.3); }
.icon.play svg { width: 36px; height: 36px; }

.i-pause { display: none; }
[data-status='playing'] .i-pause, [data-status='loading'] .i-pause { display: block; }
[data-status='playing'] .i-play, [data-status='loading'] .i-play { display: none; }

.error {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgb(217 138 122 / 0.5);
  border-radius: 12px;
  background: rgb(217 138 122 / 0.12);
}
.error p { margin: 0; flex: 1; font-size: 14px; }
[data-status='error'] .error { display: flex; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chip[aria-pressed='true'] { border-color: rgb(198 163 94 / 0.6); background: var(--gold-soft); color: var(--gold); }
.chip.danger { color: var(--danger); }

.tabs {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 2;
  display: flex;
  margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
  background: rgb(12 12 14 / 0.88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1;
  min-height: 48px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--mist);
  font-weight: 600;
}
.tabs [aria-selected='true'] { color: var(--gold); border-bottom-color: var(--gold); }

.goto { display: flex; align-items: center; gap: 10px; padding: 12px 0; color: var(--mist); }
.goto input {
  width: 96px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass);
  font-size: 16px;
}

.episodes { list-style: none; margin: 0; padding: 0; }
.episodes button {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 20px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.episodes .n { font-weight: 600; }
.episodes .dur, .episodes .ago { color: var(--mist); font-size: 14px; }
.episodes .tick { color: var(--gold); visibility: hidden; text-align: center; }
.episodes .done .tick { visibility: visible; }
.episodes .done .n { color: var(--mist); }
.episodes .bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--gold);
  opacity: 0.7;
  transform: scaleX(var(--p, 0));
  transform-origin: left;
}
.episodes [aria-current] button { background: var(--gold-soft); border-radius: 8px 8px 0 0; }
.episodes [aria-current] .n { color: var(--gold); }
#history button { grid-template-columns: auto 1fr auto; }
#history .dur { text-align: right; }
.empty { color: var(--mist); text-align: center; padding: 24px 0; }
#clear-history { display: block; margin: 20px auto 0; }

.mini {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px var(--gutter-r) calc(8px + env(safe-area-inset-bottom)) var(--gutter-l);
  background: rgb(18 18 22 / 0.9);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  transform: translateY(110%);
  transition: transform 0.25s ease;
}
.mini::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  height: 2px;
  width: calc(var(--fill, 0) * 100%);
  background: var(--gold);
}
.mini-on .mini { transform: none; }
.mini img { width: 64px; height: 36px; border-radius: 4px; object-fit: cover; background: #222; }
.mini-title {
  flex: 1;
  min-height: 44px;
  border: 0;
  background: none;
  text-align: left;
  font: 700 20px var(--serif);
  font-variant-numeric: lining-nums;
}

.sheet {
  width: 100%;
  max-width: 440px;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--ink-raised);
  color: var(--paper);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.6); }
.sheet-body {
  display: grid;
  gap: 6px;
  padding: 16px var(--gutter-r) calc(16px + env(safe-area-inset-bottom)) var(--gutter-l);
}
.sheet h3 { margin: 0 0 6px; font: 700 22px var(--serif); color: var(--gold); text-align: center; }
.sheet button {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--glass);
}
#sleep-sheet button { text-align: left; }

.account {
  display: block;
  max-width: 100%;
  min-height: 44px;
  margin: 2px auto -6px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--gold);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth { display: grid; gap: 6px; }
.auth p { margin: 0; }
.auth strong { overflow-wrap: anywhere; }
.hint { color: var(--mist); font-size: 14px; }
.auth label { margin-top: 6px; font-size: 14px; font-weight: 600; }
.auth input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass);
  font-size: 16px;
}
.form-error { color: var(--danger); font-size: 14px; }
.auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.sheet .primary { background: var(--gold); color: var(--ink); font-weight: 600; }
.sheet button:disabled { opacity: 0.6; }
#logout { margin-top: 6px; color: var(--danger); }
.sheet-close { width: 100%; margin-top: 6px; color: var(--mist); }

@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 18px; }
}

@media (min-width: 900px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(360px, 440px) 1fr;
    gap: 48px;
    align-items: start;
    padding-bottom: 48px;
  }
  .player { position: sticky; top: 16px; }
  .tabs { margin: 0; padding: 0; }
  .mini { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .spinner { animation-duration: 3s; }
}
