:root {
  color-scheme: light;
  --font-family-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-size-small: 13px;
  --font-size-brand: 20px;
  --font-size-screen-title: 24px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --radius-field: 6px;
  --radius-card: 8px;
  --radius-pill: 999px;
  --control-height-icon: 42px;
  --surface-background: #f5f6f3;
  --surface-panel: #ffffff;
  --surface-muted-control: #e8ece8;
  --surface-disabled-control: #c7cec8;
  --color-ink: #202724;
  --color-muted: #63716b;
  --color-line: #d6ddd7;
  --color-accent: #1f7a5c;
  --color-accent-ink: #ffffff;
  --color-danger: #9d2d2d;
  --color-notice-ink: #174d3b;
  --color-notice-bg: #e7f1ec;
  --color-notice-line: #c5ded2;
  --bg: var(--surface-background);
  --panel: var(--surface-panel);
  --ink: var(--color-ink);
  --muted: var(--color-muted);
  --line: var(--color-line);
  --accent: var(--color-accent);
  --accent-ink: var(--color-accent-ink);
  --danger: var(--color-danger);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-family-body);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: var(--space-lg);
}

.app-shell.is-playing {
  padding: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  max-width: 760px;
  margin: 0 auto 12px;
}

.brand {
  font-size: var(--font-size-brand);
  font-weight: 800;
}

.login-panel,
.panel,
.deck-card,
.track-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.login-panel {
  max-width: 420px;
  margin: 10vh auto;
  padding: 18px;
}

.panel {
  padding: var(--space-lg);
}

.stack {
  display: grid;
  gap: var(--space-md);
}

.main-content,
.screen {
  max-width: 760px;
  margin: 0 auto;
}

.screen {
  display: grid;
  gap: 14px;
}

.screen.wide {
  max-width: 900px;
}

.screen h1 {
  margin: 0;
  font-size: var(--font-size-screen-title);
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.year-edit span {
  color: var(--muted);
  font-size: var(--font-size-small);
  font-weight: 650;
}

.screen-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  padding: 10px 12px;
  background: var(--surface-panel);
  color: var(--ink);
}

.button,
.icon-button {
  border: 0;
  border-radius: var(--radius-field);
  padding: 10px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 750;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button.secondary,
.icon-button {
  background: var(--surface-muted-control);
  color: var(--ink);
}

.icon-button {
  width: var(--control-height-icon);
  height: var(--control-height-icon);
  padding: 0;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.icon {
  width: 21px;
  height: 21px;
}

.button:disabled,
.icon-button:disabled {
  background: var(--surface-disabled-control);
  color: #6b766f;
  cursor: not-allowed;
  opacity: 0.72;
}

.error {
  color: var(--danger);
  background: #fff1f1;
  border: 1px solid #f0caca;
  border-radius: var(--radius-field);
  padding: 10px;
}

.error-details {
  margin-top: 8px;
  color: #5f1e1e;
}

.error-details summary {
  cursor: pointer;
  font-weight: 800;
}

.error-details pre {
  max-height: 220px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 8px;
  border-radius: var(--radius-field);
  background: #fffafa;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.notice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-notice-ink);
  background: var(--color-notice-bg);
  border: 1px solid var(--color-notice-line);
  border-radius: var(--radius-field);
  padding: 10px;
}

.status-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px 9px;
  color: var(--muted);
  background: var(--surface-panel);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-chip.running,
.status-chip.pending {
  border-color: #d5c27a;
  background: #fff8da;
  color: #685818;
}

.status-chip.complete {
  border-color: #b9d8ca;
  background: var(--color-notice-bg);
  color: var(--color-notice-ink);
}

.status-chip.failed {
  border-color: #f0caca;
  background: #fff1f1;
  color: var(--danger);
}

.spinner {
  width: 14px;
  height: 14px;
  display: inline-block;
  border: 2px solid rgba(31, 122, 92, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

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

.deck-list,
.track-list {
  display: grid;
  gap: 10px;
}

.deck-card {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-md);
}

.deck-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.deck-card-main,
.track-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.track-title {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
}

.track-title-separator {
  color: var(--muted);
  font-weight: 650;
}

.track-sources {
  grid-column: 1 / -1;
  min-width: 0;
}

.deck-progress {
  display: grid;
  gap: 5px;
}

.deck-progress-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.deck-status {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  color: var(--muted);
  background: var(--surface-panel);
  font-size: 12px;
  font-weight: 800;
}

.deck-status.pending,
.deck-status.running {
  border-color: #d5c27a;
  background: #fff8da;
  color: #685818;
}

.deck-status.failed {
  border-color: #f0caca;
  background: #fff1f1;
  color: var(--danger);
}

.deck-status.missing,
.status-chip.missing {
  border-color: #d5c27a;
  background: #fff8da;
  color: #685818;
}

.deck-progress-count,
.deck-progress-current {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.deck-progress-current {
  max-width: min(58vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-progress-bar {
  width: min(240px, 58vw);
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: #e5eae5;
}

.deck-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.play-mode-choice {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.play-mode-choice .button {
  min-height: 58px;
  font-size: 18px;
}

.muted,
.sources {
  color: var(--muted);
  font-size: var(--font-size-small);
}

.empty-state {
  color: var(--muted);
  padding: 18px 0;
}

.track-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) max-content;
  align-items: start;
  column-gap: 10px;
  row-gap: 8px;
  padding: var(--space-md);
}

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

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

.blur-toggle {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: var(--font-size-small);
  font-weight: 750;
}

.track-number {
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
  line-height: 1.25;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
}

.blurred-text {
  filter: blur(5px);
  user-select: none;
}

.run-log {
  display: grid;
  gap: 6px;
  padding: 10px;
  background: var(--surface-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.run-log-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.run-log-list {
  max-height: 158px;
  overflow: auto;
  display: grid;
  gap: 4px;
}

.run-log-entry {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
}

.year-edit {
  display: grid;
  gap: 4px;
}

.year-edit.inline {
  grid-template-columns: minmax(72px, 1fr) 42px 42px;
  grid-column: 1 / -1;
  align-items: center;
  gap: 6px;
}

.clear-override-button {
  grid-column: 1 / -1;
  min-height: 38px;
}

.year-display {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  align-self: start;
}

.year-display-value {
  min-width: 56px;
  text-align: center;
  font-size: 20px;
  font-weight: 850;
}

.manual-year-marker {
  width: 16px;
  height: 16px;
  color: var(--accent);
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.manual-year-marker .icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.5;
}

.play-screen {
  height: 100svh;
  min-height: 520px;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr) 44px;
  gap: 4px;
  padding: max(6px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.play-top {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.game-card {
  position: relative;
  width: min(94vw, 410px);
  height: 100%;
  align-self: center;
  justify-self: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  place-items: center;
  padding: 42px 18px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.card-count {
  position: absolute;
  top: 14px;
  right: 16px;
  color: var(--muted);
  font-size: clamp(20px, 5.4vw, 28px);
  font-weight: 900;
  letter-spacing: 0;
}

.qr-side {
  width: 100%;
  flex: 1;
  display: grid;
  place-items: center;
}

.local-side {
  width: 100%;
  flex: 1;
  display: grid;
  place-items: center;
}

.local-play-main {
  display: grid;
  justify-items: center;
  align-content: center;
}

.play-launch-button {
  width: min(230px, 62vw);
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 50%;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: end;
  gap: 10px;
  padding: 48px 24px 42px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 12px 28px rgba(31, 122, 92, 0.28);
  cursor: pointer;
}

.play-launch-icon {
  display: grid;
  place-items: center;
  align-self: end;
  transform: translateX(5px);
}

.play-launch-icon .icon {
  width: clamp(78px, 21vw, 112px);
  height: clamp(78px, 21vw, 112px);
}

.play-launch-label {
  font-size: 22px;
  font-weight: 850;
}

.qr {
  width: min(292px, 74vw);
  height: min(292px, 74vw);
}

.answer {
  min-height: 0;
  flex: 1;
  width: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: clamp(18px, 5vh, 42px);
}

.answer-main {
  min-height: 0;
  display: grid;
  align-content: center;
  gap: clamp(18px, 4.5vh, 42px);
}

.answer .artist {
  font-size: clamp(30px, 9vw, 42px);
  font-weight: 850;
  line-height: 1.05;
}

.answer .song {
  color: var(--muted);
  font-size: clamp(20px, 5.4vw, 27px);
  line-height: 1.15;
}

.year-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.answer .year {
  font-size: clamp(76px, 21vw, 108px);
  font-weight: 900;
  line-height: 1;
}

.found-years {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.year-source {
  min-width: 0;
  display: grid;
  gap: 1px;
  padding: 6px 8px;
  background: #f0f3f0;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
}

.year-source-provider {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.year-source-value {
  font-size: 17px;
  font-weight: 850;
}

.play-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.play-controls .icon-button {
  width: 52px;
  height: 42px;
}

.year-editor-screen {
  height: 100svh;
  min-height: 520px;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.year-editor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.year-editor-panel {
  align-self: center;
  justify-self: center;
  width: min(94vw, 410px);
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.year-editor-panel .artist {
  font-size: clamp(25px, 7vw, 34px);
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
}

.year-editor-panel .song {
  color: var(--muted);
  font-size: clamp(18px, 5vw, 23px);
  line-height: 1.15;
  text-align: center;
}

.year-editor-input {
  font-size: 26px;
  font-weight: 850;
  text-align: center;
}

.save-button {
  min-height: 46px;
}

@media (max-width: 560px) {
  .app-shell {
    padding: var(--space-md);
  }

  .topbar {
    margin-bottom: 10px;
  }

  .deck-card {
    align-items: stretch;
  }

  .play-mode-choice {
    grid-template-columns: 1fr;
  }

  .track-row {
    grid-template-columns: 34px minmax(0, 1fr) max-content;
    gap: 8px;
    padding: 10px;
  }

  .game-card {
    width: min(94vw, 370px);
    height: 100%;
    padding: 46px 14px 12px;
  }

  .qr {
    width: min(286px, 73vw);
    height: min(286px, 73vw);
  }

  .found-years {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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