/* Rewind UI system: mobile-first, solid surfaces, restrained gold accent. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

:root {
  color-scheme: dark;
  --bg: #07060a;
  --bg-deep: #030304;
  --surface: #100e16;
  --surface-2: #17141d;
  --surface-3: #201c27;
  --surface-hover: #26212e;
  --gold: #c9a227;
  --gold-light: #e8c547;
  --gold-pale: #f5e4b0;
  --gold-dim: rgba(201, 162, 39, 0.18);
  --gold-glow: rgba(201, 162, 39, 0.16);
  --text: #ede8da;
  --text-bright: #fffaf0;
  --muted: #b9b0a1;
  --dim: #8f877a;
  --line: #2c2832;
  --line-strong: #3b3542;
  --success: #70c994;
  --success-bg: rgba(112, 201, 148, 0.12);
  --danger: #ef8b8b;
  --danger-bg: rgba(239, 139, 139, 0.12);
  --info: #9db8de;
  --font-display: "Righteous", sans-serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-panel: 0 8px 24px rgba(0, 0, 0, 0.22);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --safe-top: max(16px, env(safe-area-inset-top));
  --safe-right: max(16px, env(safe-area-inset-right));
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  --safe-left: max(16px, env(safe-area-inset-left));
  --z-background: 0;
  --z-content: 10;
  --z-motion: 20;
  --z-sticky: 30;
  --z-modal-backdrop: 40;
  --z-modal: 50;
  --z-toast: 60;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
summary {
  font: inherit;
}

fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
}

button,
summary,
input[type="range"] {
  touch-action: manipulation;
}

button {
  border: 0;
}

button:not(:disabled),
summary {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

#bg-glow {
  position: fixed;
  inset: 0;
  z-index: var(--z-background);
  pointer-events: none;
  background: var(--bg);
  background:
    radial-gradient(
      circle at 50% 42%,
      color-mix(in srgb, var(--active-player-glow, var(--gold)) 7%, transparent),
      transparent 24rem
    ),
    radial-gradient(circle at 12% 12%, rgba(201, 162, 39, 0.07), transparent 30rem),
    radial-gradient(circle at 88% 90%, rgba(201, 162, 39, 0.04), transparent 34rem),
    linear-gradient(180deg, #0a090d 0%, var(--bg) 46%, var(--bg-deep) 100%);
}

.aurora-orb,
.gradient-mesh,
#noise-overlay {
  display: none;
}

.screen {
  position: relative;
  z-index: var(--z-content);
  display: none;
  width: 100%;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.update-banner {
  position: fixed;
  top: var(--safe-top);
  left: 50%;
  z-index: var(--z-toast);
  display: flex;
  width: min(calc(100% - 32px), 520px);
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px 10px 16px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-3);
  box-shadow: var(--shadow-panel);
  color: var(--text);
}

.btn-update-app {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #151104;
  font-weight: 800;
}

.update-banner:not([hidden]) ~ .screen {
  --safe-top: max(92px, env(safe-area-inset-top));
}

/* Shared controls */
.btn-primary,
.btn-secondary,
.btn-action,
.btn-add-inline {
  min-height: 52px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    color 180ms var(--ease),
    opacity 180ms var(--ease),
    transform 120ms var(--ease);
}

.btn-primary,
.btn-action.primary,
.btn-action.step-draw,
.btn-action.step-next {
  background: var(--gold);
  color: #151104;
}

.btn-primary:hover:not(:disabled),
.btn-action.primary:hover:not(:disabled),
.btn-action.step-draw:hover:not(:disabled),
.btn-action.step-next:hover:not(:disabled) {
  background: var(--gold-light);
}

.btn-secondary {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: rgba(201, 162, 39, 0.55);
  background: var(--surface-hover);
  color: var(--gold-pale);
}

.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-action:active:not(:disabled),
.btn-add-inline:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-action:disabled,
.btn-add-inline:disabled {
  opacity: 0.44;
}

input[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: #0d0b11;
  color: var(--text-bright);
  font-size: 1rem;
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease);
}

input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[type="text"]:hover {
  border-color: #504958;
}

input[type="text"]:focus {
  border-color: var(--gold);
  background: #100d13;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

/* Setup shell */
#screen-setup {
  overflow-y: auto;
  scroll-padding-bottom: calc(104px + env(safe-area-inset-bottom));
}

.setup-container {
  display: flex;
  width: min(100%, 720px);
  min-height: 100dvh;
  flex-direction: column;
  gap: 20px;
  margin: 0 auto;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.btn-back-home {
  display: inline-flex;
  width: fit-content;
  min-width: 92px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  transition:
    border-color 180ms var(--ease),
    color 180ms var(--ease),
    background-color 180ms var(--ease);
}

.btn-back-home:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
}

.btn-back-home svg {
  width: 18px;
  height: 18px;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.logo-text {
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.04em;
}

.logo-sub {
  margin-top: 7px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
}

.home-tagline {
  max-width: 38ch;
  margin-top: 20px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.song-count-wrap {
  display: block;
  margin-top: 10px;
  color: var(--text);
}

.song-count-wrap strong {
  color: var(--gold-light);
  font-family: var(--font-mono);
  font-weight: 700;
}

.home-actions {
  display: grid;
  width: 100%;
  gap: 10px;
  margin-top: 28px;
}

.home-actions .btn-primary,
.home-actions .btn-secondary {
  width: 100%;
}

.btn-how-to-play {
  display: inline-flex;
  width: 100%;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease),
    color 180ms var(--ease);
}

.btn-how-to-play svg {
  color: var(--gold-light);
}

.btn-how-to-play:hover {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--text-bright);
}

.setup-section,
.online-setup {
  min-width: 0;
}

.section-label,
.flow-title {
  color: var(--text-bright);
  font-family: var(--font-body);
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: none;
}

.section-label {
  margin-bottom: 12px;
}

.catalog-picker-intro {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.catalog-tiles {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.catalog-tile {
  min-height: 104px;
}

.catalog-tile-count {
  display: block;
  margin-top: 8px;
  color: var(--gold-light);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.mode-tiles {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.mode-tile {
  position: relative;
  display: grid;
  min-height: 112px;
  grid-template-columns: 52px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease),
    transform 120ms var(--ease);
}

.mode-tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mode-tile-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--muted);
  transition:
    background-color 180ms var(--ease),
    color 180ms var(--ease);
}

.mode-tile-icon svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.mode-tile-title {
  display: block;
  color: var(--text-bright);
  font-size: 1rem;
  font-weight: 800;
}

.mode-tile-description {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.mode-tile-check {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  transition: border-color 160ms var(--ease);
}

.mode-tile-check::after {
  width: 8px;
  height: 8px;
  transform: scale(0);
  border-radius: 50%;
  background: var(--gold-light);
  content: "";
  transition: transform 160ms var(--ease);
}

.mode-tile:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.mode-tile:active {
  transform: scale(0.985);
}

.mode-tile:has(input:focus-visible) {
  outline: 3px solid var(--gold-light);
  outline-offset: 3px;
}

.mode-tile.active,
.mode-tile:has(input:checked) {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.mode-tile.active .mode-tile-icon,
.mode-tile:has(input:checked) .mode-tile-icon {
  background: var(--gold);
  color: #151104;
}

.mode-tile.active .mode-tile-check,
.mode-tile:has(input:checked) .mode-tile-check {
  border-color: var(--gold-light);
}

.mode-tile.active .mode-tile-check::after,
.mode-tile:has(input:checked) .mode-tile-check::after {
  transform: scale(1);
}

#local-setup,
#online-setup {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.player-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.player-list:empty {
  display: none;
}

.player-chip {
  --player-color: var(--gold);
  display: grid;
  min-height: 48px;
  grid-template-columns: 10px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.player-chip .player-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--player-color);
}

.player-chip > span:not(.pill) {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill,
.lobby-you {
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill.you,
.lobby-you {
  color: var(--gold-light);
}

.player-chip button {
  width: 40px;
  min-width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  transition:
    background-color 180ms var(--ease),
    color 180ms var(--ease);
}

.player-chip button:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.add-player-row,
.join-row {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.join-row {
  grid-template-columns: minmax(0, 1fr);
}

.btn-add-inline {
  flex: 0 0 auto;
  padding: 0 18px;
  background: var(--gold);
  color: #151104;
  white-space: nowrap;
}

.btn-add-inline svg {
  width: 17px;
  height: 17px;
  margin-right: 5px;
  vertical-align: -3px;
}

.online-split {
  display: grid;
  gap: 16px;
}

.online-flow {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
}

.flow-title {
  margin-bottom: 2px;
}

.join-hero {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.host-toggle {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.host-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.online-session-actions,
.online-session-actions .btn-secondary,
#btn-join-session {
  width: 100%;
}

.join-error,
.setup-error {
  min-height: 0;
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.45;
}

.join-error:not(:empty),
.setup-error:not(:empty) {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
}

.start-hint {
  min-height: 21px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

.invite-card {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.invite-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.invite-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.invite-code {
  color: var(--gold-light);
  font-family: var(--font-mono);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.invite-url {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invite-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.invite-actions .btn-secondary {
  min-width: 0;
  min-height: 46px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.invite-status,
.session-meta,
.lobby-status {
  color: var(--muted);
  font-size: 0.88rem;
}

.lobby-settings {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--gold-dim);
  color: var(--gold-pale);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.4;
}

.invite-status.ok {
  color: var(--success);
}

.invite-status.err {
  color: var(--danger);
}

.joined-lobby {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lobby-players {
  display: grid;
  gap: 8px;
}

.lobby-label {
  margin-bottom: 2px;
  color: var(--text-bright);
  font-size: 0.95rem;
  font-weight: 800;
}

.lobby-player {
  --player-color: var(--gold);
  position: relative;
  min-height: 48px;
  overflow: hidden;
  padding: 12px 12px 12px 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-player::before {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 9px;
  height: 9px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--player-color);
  content: "";
}

.filter-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.filter-panel > summary {
  display: grid;
  min-height: 58px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 16px;
  padding: 0 17px;
  color: var(--text-bright);
  font-size: 1rem;
  font-weight: 800;
  list-style: none;
}

.filter-panel > summary::-webkit-details-marker {
  display: none;
}

.filter-panel > summary::after {
  color: var(--gold-light);
  font-size: 1.25rem;
  font-weight: 400;
  content: "+";
}

.filter-panel[open] > summary::after {
  content: "−";
}

.options-summary {
  display: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.filter-panel-content {
  display: grid;
  gap: 22px;
  padding: 4px 17px 18px;
  border-top: 1px solid var(--line);
}

.filter-panel-content > .setup-section:first-child {
  padding-top: 18px;
}

.decade-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.decade-tab,
.win-score-tab {
  min-width: 48px;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 700;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease),
    color 180ms var(--ease),
    transform 120ms var(--ease);
}

.decade-tab:hover,
.win-score-tab:hover {
  border-color: #544b5e;
  color: var(--text);
}

.decade-tab.active,
.win-score-tab.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold-pale);
}

.decade-tab:disabled {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.38;
  transform: none;
}

.decade-tab:active,
.win-score-tab:active {
  transform: scale(0.97);
}

.decade-tab[data-count]:not([data-count=""])::after {
  margin-left: 6px;
  color: currentColor;
  content: attr(data-count);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  opacity: 0.68;
}

.filter-pool-meta {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.win-score-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.win-score-tab {
  min-width: 0;
  padding: 0 6px;
}

.start-area {
  position: static;
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 8px 0 var(--safe-bottom);
}

.start-area .btn-primary {
  width: 100%;
  min-height: 56px;
}

/* Home route */
body[data-route="home"] .setup-container {
  width: min(100%, 460px);
  align-items: stretch;
  justify-content: center;
  padding-top: max(28px, env(safe-area-inset-top));
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

body[data-route="home"] .logo {
  align-items: center;
  text-align: center;
}

body[data-route="home"] .logo-text {
  font-size: clamp(3.15rem, 17vw, 4.6rem);
  letter-spacing: 0.045em;
}

body[data-route="home"] .logo-sub {
  font-size: 0.66rem;
}

body[data-route="home"] .home-tagline {
  margin-right: auto;
  margin-left: auto;
}

body[data-route="home"] #btn-back-home,
body[data-route="home"] #catalog-section,
body[data-route="home"] #mode-section,
body[data-route="home"] #local-setup,
body[data-route="home"] #online-setup,
body[data-route="home"] .filter-panel,
body[data-route="home"] .start-area {
  display: none;
}

/* Join route */
body[data-route="join"] .setup-container {
  width: min(100%, 480px);
}

body[data-route="join"] .logo {
  margin: 4px 0 6px;
}

body[data-route="join"] .logo-text {
  font-size: 2rem;
}

body[data-route="join"] .home-tagline,
body[data-route="join"] .home-actions,
body[data-route="join"] #catalog-section,
body[data-route="join"] #mode-section,
body[data-route="join"] #local-setup,
body[data-route="join"] .filter-panel,
body[data-route="join"] .start-area,
body[data-route="join"] #create-flow,
body[data-route="join"] #online-setup > .section-label {
  display: none;
}

body[data-route="host"] .home-actions {
  display: none;
}

body[data-route="join"] #online-setup {
  margin-top: 4px;
}

body[data-route="join"] #join-code-input {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* How to play */
body.dialog-open {
  overflow: hidden;
}

.how-to-play-dialog {
  width: min(calc(100% - 32px), 940px);
  max-width: none;
  height: auto;
  max-height: min(calc(100dvh - 32px), 860px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #0c0a10;
  color: var(--text);
}

.how-to-play-dialog::backdrop {
  background: rgba(3, 3, 4, 0.86);
  backdrop-filter: blur(8px);
}

.how-to-play-dialog[open] {
  animation: how-to-play-enter 220ms var(--ease);
}

@keyframes how-to-play-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.how-to-play-shell {
  max-height: min(calc(100dvh - 34px), 858px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.how-to-play-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 10, 16, 0.96);
  backdrop-filter: blur(16px);
}

.how-to-play-header h2 {
  color: var(--text-bright);
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0.02em;
}

.how-to-play-header p {
  max-width: 52ch;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
  text-wrap: pretty;
}

.how-to-play-close {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease),
    color 180ms var(--ease);
}

.how-to-play-close:hover {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold-light);
}

.how-to-play-close svg {
  width: 22px;
  height: 22px;
}

.how-to-play-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.how-to-play-summary span {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

.how-to-play-steps {
  padding: 0;
  list-style: none;
}

.how-to-play-step {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(260px, 0.92fr);
  align-items: center;
  gap: 32px;
  padding: 32px 24px;
  border-bottom: 1px solid var(--line);
}

.how-to-play-step:nth-child(even) {
  grid-template-columns: minmax(260px, 0.92fr) minmax(0, 1.08fr);
}

.how-to-play-step:nth-child(even) .how-to-play-visual {
  order: 2;
}

.how-to-play-visual {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 35%, rgba(201, 162, 39, 0.09), transparent 55%),
    #08070b;
}

.how-to-play-visual svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 7;
}

.how-to-play-copy {
  display: grid;
  min-width: 0;
  grid-template-columns: 38px minmax(0, 1fr);
  column-gap: 14px;
}

.how-to-play-number {
  display: grid;
  width: 38px;
  height: 38px;
  grid-column: 1;
  grid-row: 1 / 5;
  place-items: center;
  border-radius: 50%;
  background: var(--gold);
  color: #08060a;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
}

.how-to-play-copy h3,
.how-to-play-copy p {
  grid-column: 2;
}

.how-to-play-copy h3 {
  color: var(--text-bright);
  font-size: 1.28rem;
  font-weight: 800;
  line-height: 1.2;
  text-wrap: balance;
}

.how-to-play-copy > p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.58;
  text-wrap: pretty;
}

.how-to-play-copy .how-to-play-note {
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.5;
}

.how-to-play-note strong {
  color: var(--gold-pale);
}

.how-to-play-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
  background: var(--gold-dim);
}

.how-to-play-footer p {
  max-width: 48ch;
  color: var(--gold-pale);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.5;
}

.how-to-play-footer .btn-primary {
  min-width: 210px;
  flex: 0 0 auto;
}

/* Compact UI illustrations */
.how-svg-surface,
.how-svg-muted,
.how-svg-card {
  fill: #15121b;
  stroke: #3b3542;
  stroke-width: 1.5;
}

.how-svg-selected {
  fill: rgba(201, 162, 39, 0.2);
  stroke: #c9a227;
  stroke-width: 1.5;
}

.how-svg-icon,
.how-svg-avatar-one,
.how-svg-avatar-two,
.how-svg-avatar-three,
.how-svg-avatar-four,
.how-svg-avatar-five {
  fill: #c9a227;
}

.how-svg-avatar-two {
  fill: #d56868;
}

.how-svg-avatar-three {
  fill: #5a9bd8;
}

.how-svg-avatar-four {
  fill: #65b987;
}

.how-svg-avatar-five {
  fill: #a16ed0;
}

.how-svg-ink,
.how-svg-avatar-mark {
  fill: none;
  stroke: #08060a;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.how-svg-label {
  fill: #fffaf0;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 800;
}

.how-svg-meta {
  fill: #b9b0a1;
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
}

.how-svg-disc {
  fill: #24202b;
  stroke: #e8c547;
  stroke-width: 2;
}

.how-svg-disc-center {
  fill: #c9a227;
}

.how-svg-play {
  fill: #08060a;
}

.how-svg-progress-track {
  fill: #34303a;
}

.how-svg-progress {
  fill: #e8c547;
}

.how-svg-wave,
.how-svg-arrow,
.how-svg-slot-plus {
  fill: none;
  stroke: #e8c547;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.how-svg-slot {
  fill: rgba(201, 162, 39, 0.14);
  stroke: #e8c547;
  stroke-dasharray: 5 5;
  stroke-width: 2;
}

.how-svg-mystery {
  fill: #c9a227;
}

.how-svg-question {
  fill: #08060a;
  font-family: var(--font-display);
  font-size: 34px;
}

.how-svg-year {
  fill: #fffaf0;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
}

.how-svg-year-large {
  font-size: 30px;
}

.how-svg-success-bg {
  fill: rgba(112, 201, 148, 0.14);
  stroke: #70c994;
  stroke-width: 2;
}

.how-svg-success {
  fill: none;
  stroke: #70c994;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 8;
}

.how-svg-crown {
  fill: rgba(201, 162, 39, 0.18);
  stroke: #e8c547;
  stroke-linejoin: round;
  stroke-width: 2;
}

/* Game shell */
#screen-game.active {
  display: grid;
  height: 100dvh;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top"
    "stage";
  gap: 10px;
  overflow-x: hidden;
  overflow-y: hidden;
  padding:
    var(--safe-top)
    var(--safe-right)
    0
    var(--safe-left);
}

.game-stage {
  grid-area: stage;
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "content"
    "action";
}

.game-stage-content {
  grid-area: content;
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "card"
    "audio"
    "timeline";
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding-bottom: 8px;
}

.top-bar {
  position: relative;
  z-index: var(--z-sticky);
  isolation: isolate;
  grid-area: top;
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg);
}

.player-tabs {
  display: flex;
  min-width: 0;
  flex: 1 1 220px;
  gap: 8px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.player-tabs::-webkit-scrollbar {
  display: none;
}

.player-tab {
  --player-color: var(--gold);
  position: relative;
  display: grid;
  min-width: 128px;
  min-height: 50px;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  scroll-snap-align: center;
  transition:
    background-color 180ms var(--ease),
    border-color 180ms var(--ease);
}

.player-tab.active {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.player-tab.leader:not(.active) {
  border-color: var(--line-strong);
}

.tab-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--player-color);
}

.tab-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-tab.active .tab-name {
  color: var(--text-bright);
}

.tab-score {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

.turn-label {
  position: absolute;
  top: -7px;
  right: 8px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--gold);
  color: #151104;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.session-badge {
  min-height: 36px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--gold-pale);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.btn-end-game {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  transition:
    border-color 180ms var(--ease),
    background-color 180ms var(--ease),
    color 180ms var(--ease);
}

.btn-end-game:hover {
  border-color: rgba(239, 139, 139, 0.55);
  background: var(--danger-bg);
  color: var(--danger);
}

.connection-status {
  order: 5;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
}

.connection-status:empty {
  display: none;
}

.connection-status[data-kind="error"] {
  background: var(--danger-bg);
  color: var(--danger);
}

.connection-status[data-kind="ok"] {
  background: var(--success-bg);
  color: var(--success);
}

.card-area {
  --game-card-width: min(68vw, 34dvh, 272px);
  --game-card-height: min(85vw, 42.5dvh, 340px);
  position: relative;
  isolation: isolate;
  grid-area: card;
  display: flex;
  min-height: calc(var(--game-card-height) + 34px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.card {
  position: relative;
  z-index: 2;
  width: var(--game-card-width);
  aspect-ratio: 4 / 5;
  perspective: 1000px;
}

.card-motion {
  width: 100%;
  height: 100%;
  transform-origin: center;
}

.card.dealing .card-front,
.card.grand-dealing .card-front {
  border-color: var(--gold);
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 360ms var(--ease);
  transform-style: preserve-3d;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  backface-visibility: hidden;
  box-shadow: var(--shadow-panel);
}

.card-back {
  transform: rotateY(180deg);
}

.card-art {
  position: absolute;
  inset: 0;
  background-color: #121016;
  background-position: center;
  background-size: cover;
}

.card-art::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 32%, rgba(7, 6, 10, 0.9) 100%);
  content: "";
}

.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 20px;
  text-align: center;
}

.card-genre {
  margin-bottom: 6px;
  color: var(--gold-pale);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.card-title {
  max-width: 100%;
  color: var(--text-bright);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.15;
  text-wrap: balance;
}

.card-artist {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.9rem;
}

.card-year-hidden,
.card-year-reveal {
  margin-top: 12px;
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 2.2rem;
  line-height: 1;
}

.card-year-reveal.correct {
  color: var(--success);
}

.card-year-reveal.wrong {
  color: var(--danger);
}

.card-turn-info {
  display: flex;
  width: 100%;
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.turn-handoff {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.turn-player {
  max-width: 100%;
  margin-top: 10px;
  overflow: hidden;
  color: var(--gold-light);
  font-size: clamp(2rem, 12vw, 3.75rem);
  font-weight: 800;
  line-height: 1.08;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-hint,
.turn-hint2 {
  max-width: 28ch;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.turn-hint {
  margin-top: 14px;
  color: var(--text);
  font-weight: 700;
}

.turn-hint2 {
  margin-top: 5px;
}

.loading,
.error-msg {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--gold-light);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.loading-text,
.error-msg p {
  color: var(--muted);
  font-size: 0.9rem;
}

.error-msg button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #151104;
  font-weight: 800;
}

.phase-label {
  min-height: 24px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.draw-ready-card {
  display: grid;
  min-height: 100%;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.draw-ready-mark {
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 4.5rem;
  line-height: 0.9;
}

.draw-ready-title {
  color: var(--text-bright);
  font-size: 1.1rem;
  font-weight: 800;
}

.draw-ready-copy {
  color: var(--muted);
  font-size: 0.86rem;
}

.audio-section {
  grid-area: audio;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition:
    opacity 180ms var(--ease),
    visibility 180ms var(--ease);
}

.vinyl-container {
  position: relative;
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--gold-light);
  transition:
    background-color 180ms var(--ease),
    transform 120ms var(--ease);
}

.vinyl-container:hover {
  background: var(--surface-hover);
}

.vinyl-container:active {
  transform: scale(0.96);
}

.vinyl-container:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.vinyl {
  width: 48px;
  height: 48px;
}

.vinyl.spinning {
  animation: spin 3s linear infinite;
}

.vinyl-play-icon {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

.audio-controls,
.progress-bar-container {
  min-width: 0;
}

.progress-bar-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.audio-progress {
  width: 100%;
  min-width: 0;
  accent-color: var(--gold);
}

.audio-time {
  min-width: 38px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-align: right;
}

.audio-status {
  grid-column: 1 / -1;
  min-height: 1em;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.timeline-section {
  grid-area: timeline;
  min-width: 0;
  transition:
    opacity 180ms var(--ease),
    visibility 180ms var(--ease);
}

.timeline-section .section-label {
  margin-bottom: 8px;
  font-size: 0.92rem;
}

.timeline-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding: 10px 2px 14px;
  scrollbar-color: var(--line-strong) transparent;
  scroll-padding-inline: 24px;
  scroll-snap-type: x proximity;
}

.timeline-track {
  display: flex;
  width: max-content;
  min-width: 100%;
  min-height: 118px;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.timeline-card {
  display: flex;
  width: 104px;
  min-width: 104px;
  min-height: 112px;
  flex-direction: column;
  justify-content: center;
  padding: 12px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  scroll-snap-align: center;
  text-align: center;
}

.timeline-card.starter-pending {
  border-style: dashed;
  border-color: rgba(201, 162, 39, 0.48);
  background: rgba(201, 162, 39, 0.05);
}

.starter-slot-mark {
  color: var(--gold-pale);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tc-year {
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 1.55rem;
  line-height: 1;
}

.tc-title {
  display: -webkit-box;
  margin-top: 9px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tc-artist {
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-slot {
  width: 56px;
  min-width: 56px;
  min-height: 96px;
  border: 1px dashed rgba(201, 162, 39, 0.58);
  border-radius: var(--radius-md);
  background: rgba(201, 162, 39, 0.07);
  color: var(--gold-light);
  font-size: 1.8rem;
  font-weight: 400;
  scroll-snap-align: center;
  transition:
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    opacity 160ms var(--ease),
    transform 120ms var(--ease);
}

.timeline-slot:hover:not(:disabled),
.timeline-slot:focus-visible {
  border-color: var(--gold-light);
  background: var(--gold-dim);
}

.timeline-slot:active:not(:disabled) {
  transform: scale(0.97);
}

.timeline-slot:disabled {
  opacity: 0.34;
}

.timeline-empty {
  width: 100%;
  padding: 20px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

.action-bar {
  position: static;
  z-index: var(--z-sticky);
  grid-area: action;
  display: grid;
  gap: 8px;
  padding: 8px 0 var(--safe-bottom);
  background: var(--bg);
}

.btn-action {
  width: 100%;
  min-height: 64px;
  padding: 8px 18px;
}

.action-primary-label,
.action-secondary-label {
  display: block;
}

.action-primary-label {
  font-size: 1rem;
  font-weight: 800;
}

.action-secondary-label {
  margin-top: 1px;
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.72;
}

.step-indicator {
  display: flex;
  min-height: 8px;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.step-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.step-dot.done {
  background: var(--muted);
}

.step-dot.active {
  width: 18px;
  border-radius: 999px;
  background: var(--gold-light);
}

.action-status {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

#screen-game.handoff-active .game-stage-content {
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

#screen-game.handoff-active .audio-section,
#screen-game.handoff-active .timeline-section {
  display: none;
}

#screen-game.handoff-active .card-area {
  --game-card-width: min(82vw, 46dvh, 320px);
  --game-card-height: min(102.5vw, 57.5dvh, 400px);
  width: 100%;
  height: 100%;
}

#screen-game.handoff-active .card {
  width: var(--game-card-width);
}

#screen-game.handoff-active .card-front {
  border: 2px solid var(--gold);
  background: var(--surface-2);
}

#screen-game.handoff-active .step-indicator {
  display: none;
}

#screen-game.handoff-active .btn-action {
  min-height: 72px;
}

#screen-game.audio-locked:not(.handoff-active) .audio-section {
  opacity: 0.52;
}

#screen-game.ui-transition-active .audio-section {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

#screen-game.starter-transition-active .game-stage-content {
  overflow-anchor: none;
}

.card.correct-flash .card-back {
  border-color: var(--success);
}

.card.wrong-flash .card-back {
  border-color: var(--danger);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Winner */
#screen-win {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.win-container {
  position: relative;
  display: grid;
  width: min(100%, 560px);
  min-height: min(680px, calc(100dvh - 32px));
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.win-content {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(100%, 420px);
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  text-align: center;
}

.win-crown {
  color: var(--gold-light);
  font-size: 3.4rem;
  line-height: 1;
}

.win-title {
  margin-top: 16px;
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 12vw, 4rem);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.win-name {
  margin-top: 10px;
  color: var(--text-bright);
  font-size: 1.6rem;
  font-weight: 800;
}

.win-scores {
  display: grid;
  width: 100%;
  gap: 8px;
  margin: 28px 0;
}

.win-score-row {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.ws-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ws-score {
  color: var(--gold-light);
  font-family: var(--font-mono);
  font-weight: 700;
}

.win-content .btn-primary {
  width: 100%;
}

@media (max-width: 680px) {
  .how-to-play-dialog {
    width: 100%;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .how-to-play-shell {
    max-height: 100dvh;
  }

  .how-to-play-header {
    padding:
      max(18px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      18px
      max(16px, env(safe-area-inset-left));
  }

  .how-to-play-header h2 {
    font-size: 1.7rem;
  }

  .how-to-play-header p {
    font-size: 0.9rem;
  }

  .how-to-play-summary {
    padding: 14px var(--safe-right) 14px var(--safe-left);
  }

  .how-to-play-summary span {
    min-height: 32px;
    font-size: 0.74rem;
  }

  .how-to-play-step,
  .how-to-play-step:nth-child(even) {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
    padding: 24px var(--safe-right) 28px var(--safe-left);
  }

  .how-to-play-step:nth-child(even) .how-to-play-visual {
    order: 0;
  }

  .how-to-play-visual {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
  }

  .how-to-play-copy {
    grid-template-columns: 34px minmax(0, 1fr);
    column-gap: 12px;
  }

  .how-to-play-number {
    width: 34px;
    height: 34px;
  }

  .how-to-play-copy h3 {
    font-size: 1.16rem;
  }

  .how-to-play-footer {
    align-items: stretch;
    flex-direction: column;
    padding:
      22px
      var(--safe-right)
      max(22px, env(safe-area-inset-bottom))
      var(--safe-left);
  }

  .how-to-play-footer .btn-primary {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 420px) {
  .setup-container {
    gap: 16px;
  }

  #local-setup,
  #online-setup {
    padding: 16px;
  }

  .invite-actions {
    grid-template-columns: 1fr;
  }

  .invite-actions .btn-secondary {
    min-height: 44px;
  }

  .player-tab {
    min-width: 122px;
  }

  #screen-game.active {
    padding-right: 12px;
    padding-left: 12px;
  }

  .card-area {
    --game-card-width: min(68vw, 34dvh, 264px);
    --game-card-height: min(85vw, 42.5dvh, 330px);
  }
}

@media (min-width: 560px) {
  .mode-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-tile {
    min-height: 124px;
    grid-template-columns: 48px minmax(0, 1fr) 20px;
    padding: 14px;
  }

  .mode-tile-icon {
    width: 48px;
    height: 48px;
  }

  .lobby-players {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .options-summary {
    display: block;
  }

  .filter-panel > summary {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .filter-panel > summary::after {
    grid-column: 3;
  }
}

@media (min-width: 900px) {
  .catalog-tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .catalog-tile {
    display: flex;
    min-height: 148px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
  }

  .catalog-tile .mode-tile-icon {
    width: 44px;
    height: 44px;
  }

  .catalog-tile .mode-tile-check {
    position: absolute;
    top: 14px;
    right: 14px;
  }

  .setup-container {
    display: grid;
    width: min(calc(100% - 48px), 1080px);
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    grid-template-areas:
      "back back"
      "brand brand"
      "catalog catalog"
      "mode options"
      "setup options"
      "start options";
    grid-auto-rows: auto;
    align-content: start;
    align-items: start;
    column-gap: 24px;
    row-gap: 18px;
    padding-top: 24px;
    padding-bottom: 32px;
  }

  .btn-back-home {
    grid-area: back;
  }

  .logo {
    grid-area: brand;
  }

  #mode-section {
    grid-area: mode;
  }

  #catalog-section {
    grid-area: catalog;
  }

  #local-setup,
  #online-setup {
    grid-area: setup;
  }

  .filter-panel {
    position: sticky;
    top: 24px;
    grid-area: options;
  }

  .start-area {
    position: static;
    grid-area: start;
    padding: 0;
    background: none;
  }

  body[data-route="home"] .setup-container,
  body[data-route="join"] .setup-container {
    display: flex;
  }

  body[data-route="home"] .setup-container {
    width: min(100%, 480px);
  }

  body[data-route="join"] .setup-container {
    width: min(100%, 500px);
    padding-top: 28px;
  }

  .game-stage,
  .game-stage-content {
    display: contents;
  }

  #screen-game.active {
    height: 100dvh;
    min-height: 0;
    grid-template-columns: minmax(300px, 420px) minmax(420px, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top top"
      "card timeline"
      "audio action";
    gap: 16px 24px;
    overflow-y: hidden;
    padding: 20px 24px 24px;
  }

  .top-bar {
    flex-wrap: nowrap;
  }

  .player-tab {
    min-width: 140px;
  }

  .card-area {
    --game-card-width: min(29vw, 44dvh, 310px);
    --game-card-height: min(36.25vw, 55dvh, 387.5px);
    min-height: 0;
  }

  .audio-section {
    align-self: end;
  }

  .timeline-section {
    display: flex;
    min-height: 0;
    flex-direction: column;
    justify-content: center;
  }

  .timeline-scroll {
    padding: 16px 2px 20px;
  }

  .timeline-card {
    width: 118px;
    min-width: 118px;
    min-height: 132px;
  }

  .timeline-slot {
    min-height: 112px;
  }

  .action-bar {
    position: static;
    align-self: end;
    padding: 0;
    background: none;
  }

  #screen-game.handoff-active {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top"
      "card"
      "action";
  }

  #screen-game.handoff-active .card-area {
    --game-card-width: min(36vw, 48dvh, 360px);
    --game-card-height: min(45vw, 60dvh, 450px);
  }

  #screen-game.handoff-active .action-bar {
    width: min(100%, 720px);
    justify-self: center;
  }
}

@media (min-width: 1200px) {
  #screen-game.active {
    grid-template-columns: minmax(340px, 460px) minmax(520px, 1fr);
    padding-right: 36px;
    padding-left: 36px;
  }
}

@media (min-width: 900px) and (max-height: 600px) {
  #screen-game.active {
    gap: 10px 16px;
    overflow-y: auto;
    padding: 10px 16px 12px;
  }

  .card-area {
    --game-card-width: min(25vw, 36dvh, 260px);
    --game-card-height: min(31.25vw, 45dvh, 325px);
  }

  #screen-game.handoff-active .card-area {
    --game-card-width: min(30vw, 40dvh, 280px);
    --game-card-height: min(37.5vw, 50dvh, 350px);
  }

  .btn-action,
  #screen-game.handoff-active .btn-action {
    min-height: 52px;
  }

  .action-secondary-label {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 600px) and (max-width: 899px) {
  #screen-game.active {
    gap: 6px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .game-stage-content {
    grid-template-columns: minmax(150px, 0.8fr) minmax(260px, 1.2fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "card timeline"
      "audio timeline";
    gap: 8px 12px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .card-area {
    --game-card-width: min(28dvh, 150px);
    --game-card-height: min(35dvh, 187.5px);
    grid-area: card;
    min-height: 0;
  }

  .phase-label {
    min-height: 18px;
    font-size: 0.78rem;
  }

  .audio-section {
    grid-area: audio;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 8px;
    padding: 4px 8px;
  }

  .vinyl-container {
    width: 44px;
    height: 44px;
  }

  .vinyl {
    width: 40px;
    height: 40px;
  }

  .timeline-section {
    grid-area: timeline;
    display: flex;
    min-height: 0;
    flex-direction: column;
    justify-content: center;
  }

  .timeline-track,
  .timeline-card {
    min-height: 92px;
  }

  .timeline-slot {
    min-height: 82px;
  }

  .action-bar {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding-top: 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .step-indicator {
    min-width: 54px;
  }

  .btn-action,
  #screen-game.handoff-active .btn-action {
    min-height: 48px;
  }

  .action-secondary-label,
  .audio-status {
    display: none;
  }

  #screen-game.handoff-active .game-stage-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #screen-game.handoff-active .card-area {
    --game-card-width: min(38dvh, 180px);
    --game-card-height: min(47.5dvh, 225px);
  }
}

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

/* Critical route visibility. Keep these last and in sync with routing behavior. */
body[data-route="home"] #screen-setup {
  display: flex !important;
}

body[data-route="home"] #screen-game,
body[data-route="home"] #screen-win {
  display: none !important;
}
