:root {
  color-scheme: light;
  --ink: #181512;
  --muted: #6f675d;
  --paper: #fffdf8;
  --panel: #ffffff;
  --line: #e8dfd2;
  --accent: #007f7a;
  --accent-dark: #005f5b;
  --coral: #e85d4f;
  --warm: #fff2cf;
  --soft: #f7fbf7;
  --shadow: 0 16px 42px rgba(33, 26, 18, 0.1);
  --shadow-soft: 0 8px 22px rgba(33, 26, 18, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #e8fbf7 0%, var(--paper) 42%, #fff7dd 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: rgba(0, 127, 122, 0.18);
}

a {
  color: inherit;
  text-underline-offset: 0.18em;
}

button,
.button-link {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  font: inherit;
  font-weight: 800;
  padding: 0.85rem 1.1rem;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.primary-action {
  min-height: 3.15rem;
  width: 100%;
}

.text-button {
  background: transparent;
  color: inherit;
  padding: 0;
}

.text-button:hover {
  background: transparent;
  color: var(--accent-dark);
}

button:hover,
.button-link:hover {
  background: var(--accent-dark);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  padding: 0.8rem 0.9rem;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 127, 122, 0.16);
  outline: none;
}

label,
fieldset {
  display: grid;
  gap: 0.45rem;
  font-weight: 750;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

legend {
  font-weight: 900;
  padding: 0 0.25rem;
}

fieldset > label {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 0.65rem;
  font-weight: 650;
}

fieldset > label > input {
  width: auto;
}

fieldset > label.stack-label,
.team-name-grid label {
  align-items: stretch;
  display: grid;
  flex-direction: column;
}

fieldset > label.stack-label select,
.team-name-grid input {
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.9rem;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.centered-page {
  align-items: center;
  display: grid;
  justify-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.login-panel,
.settings-card,
.player-panel,
.timeline-panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  gap: 1.5rem;
  max-width: 470px;
  padding: 2rem;
}

.login-panel h1,
.settings-layout h1,
.results-layout h1 {
  font-size: clamp(2.2rem, 6vw, 4.6rem);
  line-height: 0.96;
  margin: 0;
}

.stack,
.settings-card,
.guess-form {
  display: grid;
  gap: 1rem;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
}

.lede {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.55;
  margin: 1rem 0 0;
  max-width: 56ch;
}

.hint,
.error {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
}

.error {
  color: #b42318;
}

.topbar {
  align-items: center;
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(14px);
  display: flex;
  justify-content: space-between;
  padding: calc(1rem + env(safe-area-inset-top)) clamp(1rem, 4vw, 3rem) 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: grid;
  gap: 0.05rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
}

.brand small {
  color: var(--accent-dark);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar nav {
  align-items: center;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar nav a,
.topbar nav button {
  white-space: nowrap;
}

.settings-layout,
.results-layout,
.lobby-layout {
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  margin: 0 auto;
  max-width: 1120px;
  padding: clamp(1rem, 4vw, 4rem);
  padding-left: max(clamp(1rem, 4vw, 4rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 4vw, 4rem), env(safe-area-inset-right));
}

.settings-card {
  padding: 1.25rem;
}

.setup-intro,
.lobby-hero {
  align-self: start;
  position: sticky;
  top: 6rem;
}

.setup-steps {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.4rem;
}

.setup-steps article {
  align-items: start;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.15rem 0.7rem;
  grid-template-columns: auto 1fr;
  padding: 0.8rem;
}

.setup-steps span {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: #ffffff;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 950;
  height: 1.65rem;
  justify-content: center;
  width: 1.65rem;
}

.setup-steps strong,
.setup-steps small {
  grid-column: 2;
}

.setup-steps small {
  color: var(--muted);
  line-height: 1.35;
}

.option-grid {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.option-card {
  align-items: start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 0.18rem;
  grid-template-columns: auto 1fr;
  min-height: 4.2rem;
  padding: 0.85rem;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.option-card:hover {
  background: var(--soft);
}

.option-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(0, 127, 122, 0.35), var(--shadow-soft);
}

.option-card input {
  margin: 0.18rem 0 0;
  width: auto;
}

.option-card span {
  font-weight: 900;
}

.option-card small {
  color: var(--muted);
  grid-column: 2;
  line-height: 1.25;
}

.option-card.wide {
  min-height: 4.8rem;
}

.lobby-hero h1 {
  font-size: clamp(2.2rem, 6vw, 4.6rem);
  line-height: 0.96;
  margin: 0;
}

.lobby-card {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.lobby-card .feedback {
  min-height: auto;
}

.lobby-card h2 {
  font-size: 2.3rem;
  margin: 0;
}

.invite-box {
  display: grid;
  gap: 0.45rem;
}

.lobby-actions {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: 1fr 1fr;
}

.team-lobby-list {
  display: grid;
  gap: 0.75rem;
}

.team-lobby-row {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.85rem;
}

.team-lobby-row.you {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(0, 127, 122, 0.35);
}

.team-lobby-row small {
  color: var(--muted);
  display: block;
  margin-top: 0.1rem;
}

.team-lobby-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.status-pill {
  background: #f4eee4;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 850;
  padding: 0.35rem 0.55rem;
  white-space: nowrap;
}

.status-pill.ready {
  background: #e4f8ef;
  color: var(--accent-dark);
}

.disabled-link {
  opacity: 0.7;
  pointer-events: none;
}

.game-shell {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
  margin: 0 auto;
  max-width: 1220px;
  padding: clamp(1rem, 3vw, 2rem);
  padding-bottom: calc(clamp(1rem, 3vw, 2rem) + env(safe-area-inset-bottom));
  padding-left: max(clamp(1rem, 3vw, 2rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 3vw, 2rem), env(safe-area-inset-right));
}

.room-banner {
  align-items: center;
  background: #ffffff;
  border: 1px solid rgba(0, 127, 122, 0.28);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  display: flex;
  gap: 1rem;
  grid-column: 1 / -1;
  justify-content: space-between;
  padding: 0.85rem 1rem;
}

.room-banner span {
  color: var(--muted);
}

.player-panel,
.timeline-panel {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2.5vw, 1.5rem);
}

.player-panel {
  align-items: start;
  grid-template-columns: minmax(280px, 0.82fr) minmax(320px, 1fr);
}

.player-panel .guess-form {
  align-self: stretch;
}

.song-stage {
  display: grid;
  gap: 1rem;
}

.player-panel h1 {
  font-size: clamp(2rem, 5vw, 3.7rem);
  line-height: 0.96;
  margin: 0;
}

.album-art {
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  width: min(100%, 290px);
}

.album-art.empty {
  background:
    linear-gradient(135deg, rgba(29, 185, 84, 0.22), rgba(255, 242, 207, 0.9)),
    repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(24, 21, 18, 0.08) 21px);
}

audio {
  width: 100%;
}

.playback-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

.guess-form {
  background: rgba(247, 251, 247, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  grid-template-columns: 1fr;
  padding: 1rem;
}

.form-heading {
  display: grid;
  gap: 0.25rem;
}

.form-heading h2 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  line-height: 1;
  margin: 0;
}

.guess-form.locked {
  opacity: 0.62;
}

.bonus-grid {
  display: grid;
  gap: 0.8rem;
}

.team-turn {
  color: var(--accent-dark);
  font-weight: 900;
  margin: 0.8rem 0 0;
}

.team-name-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: 1fr;
}

.feedback {
  background: var(--warm);
  border-radius: 8px;
  line-height: 1.45;
  min-height: 3rem;
  padding: 1rem;
}

.bonus-results {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
}

.score-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-width: min(720px, calc(100vw - 2rem));
  padding: 1.25rem;
  width: 720px;
}

.score-dialog::backdrop {
  background: rgba(24, 21, 18, 0.32);
}

.dialog-heading,
.score-total,
.score-round {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-heading h2,
.score-breakdown h3 {
  margin: 0;
}

.score-breakdown {
  display: grid;
  gap: 1rem;
}

.score-total {
  background: var(--warm);
  border-radius: 8px;
  padding: 1rem;
}

.score-total span {
  font-size: 2rem;
  font-weight: 950;
}

.score-rounds {
  display: grid;
  gap: 0.65rem;
}

.team-scores,
.team-score-list {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.team-chip,
.team-score-row {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.7rem 0.8rem;
}

.team-chip span,
.team-score-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.team-chip.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.team-chip.you {
  background: #f7fffb;
}

.score-round {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  padding: 0.8rem;
}

.reveal-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: min(520px, calc(100vw - 2rem));
  padding: 1rem;
  width: 520px;
}

.reveal-dialog::backdrop {
  background: rgba(24, 21, 18, 0.38);
  backdrop-filter: blur(4px);
}

.reveal-card,
.flying-reveal-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
}

.reveal-card h2 {
  font-size: clamp(2rem, 6vw, 3.6rem);
  line-height: 0.92;
  margin: 0;
}

.reveal-meta {
  color: var(--muted);
  margin: 0;
}

.reveal-year {
  color: var(--accent-dark);
  font-size: 3rem;
  font-weight: 950;
}

.reveal-points {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(4, 1fr);
  margin: 0;
}

.reveal-points div {
  background: var(--warm);
  border-radius: 8px;
  display: grid;
  gap: 0.15rem;
  padding: 0.7rem;
}

.reveal-points dt {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.reveal-points dd {
  font-size: 1.4rem;
  font-weight: 900;
  margin: 0;
}

.flying-reveal-card {
  margin: 0;
  pointer-events: none;
  position: fixed;
  transform-origin: top left;
  z-index: 9999;
}

.section-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.timeline-panel {
  margin-top: 0.25rem;
  position: relative;
  z-index: 1;
}

.timeline-board {
  display: grid;
  gap: 1rem;
}

.team-timeline-row {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0.8rem;
  padding: 0.9rem;
}

.team-timeline-row.active {
  border-color: rgba(0, 127, 122, 0.55);
  box-shadow: inset 0 0 0 1px rgba(0, 127, 122, 0.35), var(--shadow-soft);
}

.team-timeline-heading {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.team-timeline-heading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.timeline {
  align-items: stretch;
  display: flex;
  gap: 0.8rem;
  min-height: 132px;
  overflow-x: auto;
  padding: 0.1rem 0.1rem 0.45rem;
  scroll-snap-type: x proximity;
}

.timeline-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  display: grid;
  gap: 0.25rem;
  padding: 1rem;
}

.timeline-card {
  flex: 0 0 184px;
  font: inherit;
  justify-content: stretch;
  min-height: 126px;
  scroll-snap-align: start;
  text-align: left;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button.timeline-card.selectable:hover {
  background: #f7fffb;
  color: var(--ink);
}

.team-timeline-row:not(.active) .timeline-card {
  cursor: default;
}

.timeline-card.selectable {
  cursor: pointer;
}

.timeline-card.selected {
  border-color: var(--coral);
  box-shadow: 0 0 0 2px rgba(232, 93, 79, 0.22), 0 12px 30px rgba(33, 26, 18, 0.08);
  transform: translateY(-2px);
}

.starter-card {
  background: linear-gradient(180deg, #fffdf8 0%, #eafaf4 100%);
}

.timeline-card em {
  align-self: end;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.timeline-card-pending {
  opacity: 0;
  transform: translateY(14px) scale(0.96);
}

.timeline-card-arrived {
  animation: timeline-arrive 520ms cubic-bezier(.2,.82,.2,1) both;
}

.timeline-card span {
  color: var(--accent-dark);
  font-size: 1.4rem;
  font-weight: 950;
}

.timeline-card small {
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  min-height: 9rem;
  place-items: center;
  text-align: center;
}

.results-layout {
  grid-template-columns: 1fr;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .settings-layout,
  .lobby-layout,
  .game-shell {
    grid-template-columns: 1fr;
  }

  .player-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
    position: static;
  }

  .setup-intro,
  .lobby-hero {
    position: static;
  }

  .option-grid,
  .option-grid.compact {
    grid-template-columns: 1fr;
  }

  .reveal-points {
    grid-template-columns: repeat(2, 1fr);
  }

  .lobby-actions,
  .room-banner,
  .team-lobby-row {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .team-lobby-status {
    justify-content: flex-start;
  }

  .timeline-card {
    flex-basis: 168px;
  }
}

@media (max-width: 520px) {
  .settings-layout,
  .lobby-layout,
  .game-shell {
    gap: 1rem;
    padding-top: 0.75rem;
  }

  .login-panel,
  .settings-card,
  .lobby-card,
  .player-panel,
  .timeline-panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    margin-left: calc(-1 * max(clamp(1rem, 4vw, 4rem), env(safe-area-inset-left)));
    margin-right: calc(-1 * max(clamp(1rem, 4vw, 4rem), env(safe-area-inset-right)));
  }

  .player-panel,
  .timeline-panel,
  .settings-card,
  .lobby-card {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .topbar nav {
    gap: 0.7rem;
  }
}

@keyframes timeline-arrive {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  65% {
    opacity: 1;
    transform: translateY(-5px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
