:root {
  --ink: #14110d;
  --ink-soft: #1d1914;
  --ink-line: #33291f;
  --paper: #ece3d2;
  --paper-dim: #a99c86;
  --jade: #6f9b82;
  --vermilion: #b23a26;
  --gold: #c9a44c;
  --frame-w: min(clamp(300px, 34vw, 430px), calc((100svh - 6rem) * 0.5625));
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 80% at 88% -10%, rgba(111, 155, 130, 0.17), transparent 60%),
    radial-gradient(90% 70% at 4% 104%, rgba(178, 58, 38, 0.16), transparent 62%),
    linear-gradient(168deg, #17140f 0%, #12100c 48%, #0f0d0a 100%);
  color: var(--paper);
  font-family: 'Noto Serif SC', 'Songti SC', serif;
  -webkit-font-smoothing: antialiased;
  /* clip, not hidden: hidden would turn body into a scroll container and kill
     the sticky video on mobile. */
  overflow-x: clip;
}

.grain {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- layout ---------- */

.stage {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(2rem, 6vw, 6rem);
  padding: clamp(1.5rem, 4vw, 4.5rem) clamp(1.25rem, 5vw, 5rem);
}

.rail {
  grid-area: 1 / 1;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 3vh, 2.5rem);
}

.rail > * {
  opacity: 0;
  transform: translateY(14px);
  animation: rise 0.8s var(--ease) forwards;
}

.rail > *:nth-child(2) { animation-delay: 0.08s; }
.rail > *:nth-child(3) { animation-delay: 0.16s; }
.rail > *:nth-child(4) { animation-delay: 0.24s; }
.rail > *:nth-child(5) { animation-delay: 0.32s; }

@keyframes rise {
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- category picker ---------- */

.picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-top: 1px solid var(--ink-line);
  border-bottom: 1px solid var(--ink-line);
  padding: 0.55rem 0;
}

.picker__item {
  appearance: none;
  border: 0;
  background: none;
  color: var(--paper-dim);
  cursor: pointer;
  font-family: inherit;
  padding: 0.6rem 1rem 0.55rem;
  display: grid;
  gap: 0.2rem;
  justify-items: start;
  position: relative;
  transition: color 0.3s var(--ease), transform 0.3s var(--ease);
}

.picker__item::after {
  content: '';
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 0.2rem;
  height: 2px;
  background: var(--vermilion);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s var(--ease);
}

.picker__item:hover {
  color: var(--paper);
  transform: translateY(-2px);
}

.picker__item.is-on {
  color: var(--paper);
}

.picker__item.is-on::after {
  transform: scaleX(1);
}

.picker__cn {
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.picker__en {
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* ---------- shuffle button ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
}

.shuffle {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  flex: none;
  border: 0;
  border-radius: 2px;
  padding: 0.72rem 1.7rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--ink);
  background: linear-gradient(100deg, var(--gold) 0%, #e2c882 60%, var(--paper) 100%);
  transition: transform 0.18s var(--ease), opacity 0.2s var(--ease);
}

.shuffle:hover {
  transform: translateY(-2px);
}

.shuffle:active {
  transform: translateY(1px);
}

.shuffle[disabled] {
  cursor: progress;
  opacity: 0.55;
}

.controls__hint {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  line-height: 1.7;
  color: var(--paper-dim);
}

/* ---------- readout ---------- */

.readout {
  margin: 0;
  display: grid;
  gap: 0.15rem;
}

.readout__row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.42rem 0;
  border-bottom: 1px dashed rgba(236, 227, 210, 0.1);
}

.readout dt {
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  color: var(--paper-dim);
}

.readout dd {
  margin: 0 0 0 auto;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  color: var(--jade);
}

.fineprint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.8;
  color: rgba(169, 156, 134, 0.7);
}

.fineprint code {
  font-family: ui-monospace, 'SFMono-Regular', monospace;
  font-size: 0.72rem;
  color: var(--gold);
}

/* ---------- theatre ---------- */

.theatre {
  grid-area: 1 / 2;
  display: flex;
  justify-content: flex-end;
}

.frame {
  position: relative;
  width: var(--frame-w);
  aspect-ratio: 9 / 16;
  border-radius: 3px;
  overflow: hidden;
  background: #0b0a08;
  border: 1px solid rgba(236, 227, 210, 0.14);
  box-shadow:
    0 36px 80px -30px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(201, 164, 76, 0.1) inset;
  transform: rotate(-0.7deg);
  opacity: 0;
  animation: rise 0.9s 0.1s var(--ease) forwards;
}

.screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.45s var(--ease);
  background: #0b0a08;
}

.screen.is-live {
  opacity: 1;
}

.tap {
  position: absolute;
  inset: 0;
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
}

/* skeleton */

.skeleton {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.7rem;
  padding: 2rem 1.6rem 4rem;
  background: linear-gradient(180deg, #16130f, #0d0c09);
}

.frame.is-loading .skeleton {
  display: flex;
}

.skeleton__bar {
  height: 0.7rem;
  border-radius: 2px;
  background: linear-gradient(
    100deg,
    rgba(236, 227, 210, 0.05) 12%,
    rgba(236, 227, 210, 0.16) 38%,
    rgba(236, 227, 210, 0.05) 62%
  );
  background-size: 260% 100%;
  animation: sweep 1.5s linear infinite;
}

.skeleton__bar:nth-child(1) { width: 72%; }
.skeleton__bar:nth-child(2) { width: 46%; animation-delay: 0.12s; }
.skeleton__bar:nth-child(3) { width: 58%; animation-delay: 0.24s; }

@keyframes sweep {
  from { background-position: 180% 0; }
  to { background-position: -80% 0; }
}

.skeleton__note {
  margin: 0.5rem 0 0;
  font-size: 0.74rem;
  letter-spacing: 0.5em;
  color: var(--jade);
}

/* fault */

.fault {
  position: absolute;
  inset: auto 1.2rem 1.2rem;
  z-index: 3;
  padding: 1.25rem 1.3rem;
  border: 1px solid rgba(178, 58, 38, 0.5);
  border-left: 3px solid var(--vermilion);
  background: rgba(16, 13, 10, 0.94);
  backdrop-filter: blur(6px);
}

.fault[hidden] {
  display: none;
}

.fault__title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.fault__body {
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--paper-dim);
}

.fault__retry {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  padding: 0.5rem 1.1rem;
  color: var(--paper);
  background: var(--vermilion);
  border: 0;
  border-radius: 2px;
  transition: transform 0.2s var(--ease), filter 0.2s var(--ease);
}

.fault__retry:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

/* hud */

.hud {
  position: absolute;
  inset: 0 0 auto;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(180deg, rgba(8, 7, 6, 0.8), transparent);
  pointer-events: none;
}

.hud__title {
  margin: 0;
  flex: 1;
  font-size: 0.85rem;
  line-height: 1.6;
  max-height: 3.2em;
  overflow: hidden;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.hud__sound {
  pointer-events: auto;
  appearance: none;
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  padding: 0.38rem 0.65rem;
  color: var(--paper);
  background: rgba(12, 10, 8, 0.6);
  border: 1px solid rgba(236, 227, 210, 0.22);
  border-radius: 999px;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease);
}

.hud__sound:hover {
  background: rgba(178, 58, 38, 0.72);
  border-color: transparent;
}

.hud__sound-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paper-dim);
}

.hud__sound[aria-pressed='true'] .hud__sound-icon {
  background: var(--jade);
  box-shadow: 0 0 0 3px rgba(111, 155, 130, 0.25);
}

/* Sound was refused until the first tap — ask for that tap. */
.hud__sound.is-blocked {
  border-color: var(--gold);
}

.hud__sound.is-blocked .hud__sound-icon {
  background: var(--gold);
  animation: blink 1.4s var(--ease) infinite;
}

@keyframes blink {
  50% { opacity: 0.25; }
}

/* pause badge */

.pause-badge {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 0.8rem;
  justify-items: center;
  background: rgba(10, 9, 7, 0.42);
  pointer-events: none;
}

.pause-badge[hidden] {
  display: none;
}

.pause-badge span {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 15px 0 15px 26px;
  border-color: transparent transparent transparent var(--paper);
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
}

.pause-badge p {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.4em;
  color: var(--paper);
}

/* progress + seal */

.progress {
  position: absolute;
  inset: auto 0 0;
  z-index: 2;
  height: 3px;
  background: rgba(236, 227, 210, 0.14);
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--jade), var(--gold));
}

.seal {
  position: absolute;
  z-index: 3;
  right: -14px;
  bottom: 48px;
  width: 48px;
  height: 48px;
  display: grid;
  place-content: center;
  font-family: 'Ma Shan Zheng', serif;
  font-size: 1.7rem;
  color: #f4ece0;
  background: var(--vermilion);
  border-radius: 6px;
  transform: rotate(6deg);
  box-shadow: 0 8px 20px -6px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.frame.is-swapping .seal {
  animation: stamp 0.55s var(--ease);
}

@keyframes stamp {
  0% { transform: rotate(6deg) scale(1); }
  35% { transform: rotate(-4deg) scale(1.22); }
  100% { transform: rotate(6deg) scale(1); }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  :root {
    --frame-w: min(100%, 26rem);
  }

  .stage {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    padding: 0.75rem 1.25rem 3rem;
  }

  /* The player rides along as a floating pane while the lists scroll under it. */
  .theatre {
    position: sticky;
    top: 0;
    z-index: 5;
    justify-content: center;
    margin: 0 -1.25rem;
    padding: 0.75rem 1.25rem 1rem;
    background: linear-gradient(180deg, var(--ink) 0%, var(--ink) 74%, rgba(20, 17, 13, 0));
  }

  .rail {
    grid-area: auto;
    max-width: none;
    gap: 1.4rem;
  }

  .frame {
    transform: none;
    aspect-ratio: 9 / 15;
    max-height: 56svh;
  }

  .seal {
    right: 10px;
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .rail > *,
  .frame {
    opacity: 1;
    transform: none;
  }
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
