:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  --ink: #241f27;
  --paper: #fff1ea;
  --white: #fffdfa;
  --line: #ddcfc7;
  --red: #dc4c3c;
  --yellow: #f2b544;
  --blue: #197f87;
  --muted: #746a69;
  --shadow: 0 12px 32px rgba(91, 48, 44, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 10px clamp(16px, 4vw, 52px);
  border-bottom: 1px solid rgba(24, 24, 22, 0.16);
  background: rgba(255, 241, 234, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}

.brand-logo { display: block; width: 46px; height: 46px; object-fit: cover; }

.brand-copy { display: grid; text-align: left; line-height: 1.05; }
.brand-copy small { margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }

.stage-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.page { padding: clamp(24px, 5vw, 68px) clamp(16px, 5vw, 72px) 72px; }
.page-inner { width: min(1180px, 100%); margin: 0 auto; }

.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  align-items: start;
  gap: clamp(32px, 7vw, 94px);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--red);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  max-width: 700px;
  margin-bottom: 16px;
  font-size: clamp(38px, 7vw, 82px);
  line-height: 0.98;
  letter-spacing: 0;
}

.lede {
  max-width: 620px;
  margin-bottom: 34px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 28px;
  border: 1px solid var(--ink);
}

.mode-tab {
  min-height: 54px;
  padding: 10px;
  border: 0;
  border-right: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-weight: 900;
}
.mode-tab:last-child { border-right: 0; }
.mode-tab.is-active { background: var(--ink); color: var(--white); }

.section-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 900;
}

.source-sections { display: grid; gap: 8px; margin-bottom: 26px; }
.source-section { border: 1px solid var(--line); background: var(--white); }
.source-section.is-open { border-color: var(--blue); }
.source-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
.source-toggle {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.source-toggle.is-on { border-color: var(--blue); box-shadow: inset 4px 0 0 var(--blue); }
.source-toggle span:last-child { color: var(--muted); font-size: 12px; }
.source-action { min-width: 88px; border: 0; border-left: 1px solid var(--line); background: var(--yellow); cursor: pointer; font-weight: 900; }
.source-inline-panel { border-top: 1px solid var(--line); }
.source-inline-panel .album-selector { margin: 0; border: 0; }
.source-inline-panel .collection-selector { border: 0; }

.album-selector {
  margin: -12px 0 26px;
  border: 1px solid var(--ink);
  background: var(--white);
}
.album-list { display: grid; }
.album-entry { border-bottom: 1px solid var(--line); }
.album-entry:last-child { border-bottom: 0; }
.album-entry.is-complete { box-shadow: inset 4px 0 0 var(--blue); }
.album-entry.is-partial { box-shadow: inset 4px 0 0 var(--yellow); }
.album-entry-head { display: grid; grid-template-columns: minmax(0, 1fr) 66px; align-items: stretch; }
.album-select-all {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.album-select-all img { width: 42px; height: 42px; object-fit: cover; }
.album-select-all span { display: grid; min-width: 0; gap: 4px; }
.album-select-all strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-select-all small { color: var(--muted); }
.album-expand {
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}
.album-tracks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.album-track {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  min-height: 42px;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f2f0ea;
  cursor: pointer;
  text-align: left;
}
.album-track:nth-child(even) { border-right: 0; }
.album-track span { color: var(--muted); font-size: 11px; }
.album-track strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.album-track.is-selected { background: var(--white); box-shadow: inset 3px 0 0 var(--red); }

.collection-selector { background: #fff9f5; }
.collection-selector-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.collection-selector-head small { color: var(--muted); font-size: 11px; }
.collection-list { display: grid; }
.collection-entry { border-bottom: 1px solid var(--line); }
.collection-entry:last-child { border-bottom: 0; }
.collection-entry.is-complete { box-shadow: inset 4px 0 0 var(--blue); }
.collection-entry.is-partial { box-shadow: inset 4px 0 0 var(--yellow); }
.collection-entry-head { display: grid; grid-template-columns: minmax(0, 1fr) 66px; align-items: stretch; }
.collection-select-all { display: flex; min-width: 0; padding: 12px 14px; border: 0; background: transparent; cursor: pointer; text-align: left; }
.collection-select-all span { display: grid; gap: 4px; }
.collection-select-all strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection-select-all small { color: var(--muted); }

.primary-button, .secondary-button {
  min-height: 52px;
  padding: 12px 20px;
  border: 1px solid var(--ink);
  cursor: pointer;
  font-weight: 900;
}
.primary-button { background: var(--red); color: white; }
.primary-button:hover { background: #d92f22; }
.primary-button:disabled { cursor: not-allowed; opacity: 0.45; }
.secondary-button { background: transparent; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.cover-wall {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  transform: rotate(1.5deg);
}
.cover-wall img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  box-shadow: var(--shadow);
}
.cover-wall img:nth-child(2), .cover-wall img:nth-child(5) { transform: translateY(28px); }

.selection-panel {
  margin-top: 32px;
  padding-top: 26px;
  border-top: 2px solid var(--ink);
}
.selection-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  margin-bottom: 14px;
}
.search-input {
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--white);
}
.tool-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.song-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-height: 420px;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}
.song-chip {
  display: grid;
  min-height: 60px;
  align-content: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: var(--white);
  cursor: pointer;
  text-align: left;
}
.song-chip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-chip small { margin-top: 5px; color: var(--muted); }
.song-chip.is-selected { border-color: var(--red); box-shadow: inset 4px 0 0 var(--red); }

.game-page { padding-top: clamp(24px, 4vw, 48px); }
.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
}
.game-header h1 { margin-bottom: 0; font-size: clamp(34px, 5vw, 62px); }
.counter { flex: 0 0 auto; color: var(--muted); font-weight: 900; }

.group-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.song-option {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--white);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(24, 24, 22, 0.08);
  text-align: left;
}
.song-option img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.song-option-copy { display: grid; min-height: 88px; align-content: center; padding: 13px; }
.song-option strong { font-size: 16px; line-height: 1.3; }
.song-option small { margin-top: 6px; color: var(--muted); }
.song-option.is-selected { border-color: var(--red); box-shadow: 7px 7px 0 var(--yellow); }
.pick-number {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  width: 32px;
  height: 32px;
  place-items: center;
  background: var(--red);
  color: white;
  font-weight: 900;
}
.song-option.is-selected .pick-number { display: grid; }
.game-actions { display: flex; justify-content: flex-end; margin-top: 24px; }

.revival-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.revival-item {
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--white);
  cursor: pointer;
  text-align: left;
  font-weight: 800;
}
.revival-item.is-selected { border-color: var(--blue); box-shadow: inset 5px 0 0 var(--blue); }

.match-arena {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}
.versus { text-align: center; font-size: 28px; font-weight: 1000; }
.match-choice {
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--white);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.match-choice:hover { border-color: var(--red); transform: translateY(-3px); }
.match-choice img { display: block; width: 100%; max-height: 430px; aspect-ratio: 4 / 3; object-fit: cover; }
.match-copy { display: grid; min-height: 106px; align-content: center; padding: 16px; text-align: center; }
.match-copy strong { font-size: clamp(20px, 3vw, 32px); }
.match-copy small { margin-top: 7px; color: var(--muted); }

.stage-page { min-height: calc(100vh - 66px); }
.stage-intro { display: grid; justify-items: center; text-align: center; }
.stage-intro h1 { margin-bottom: 4px; font-size: clamp(34px, 5vw, 62px); }
.stage-number {
  margin-top: 18px;
  color: var(--red);
  font-size: clamp(90px, 18vw, 210px);
  font-weight: 1000;
  line-height: 0.85;
}
.stage-name { margin: 10px 0 30px; font-size: 18px; font-weight: 1000; }
.qualified-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  gap: 7px;
}
.qualified-song {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--white);
  text-align: left;
}
.qualified-song > span { position: absolute; top: 5px; left: 6px; color: white; font-size: 10px; font-weight: 900; text-shadow: 0 1px 3px black; }
.qualified-song img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.qualified-song strong { display: block; min-height: 42px; padding: 7px; overflow: hidden; font-size: 11px; line-height: 1.3; }
.stage-continue { margin-top: 28px; min-width: 180px; }

.result-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  align-items: center;
  gap: clamp(28px, 7vw, 90px);
}
.result-copy h1 { font-size: clamp(52px, 9vw, 108px); }
.champion-name { color: var(--red); }
.share-card {
  padding: 22px;
  border: 2px solid #dc4c3c;
  background: #241b22;
  color: #ffffff;
  box-shadow: 12px 12px 0 #f2b544;
}
.champion-cover { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.share-meta { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding-top: 18px; }
.share-meta p { margin: 0; font-size: 12px; font-weight: 900; }
.share-meta h2 { margin: 4px 0 0; font-size: 26px; }
.qr { width: 82px; height: 82px; border: 1px solid var(--line); }
.result-actions { margin-top: 30px; }

.bracket-section { margin-top: clamp(70px, 10vw, 130px); padding: 30px; border-top: 0; background: #241b22; color: #ffffff; }
.bracket-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.bracket-heading h2 { margin-bottom: 0; font-size: clamp(34px, 5vw, 58px); }
.bracket-heading > span { color: rgba(255, 255, 255, .55); font-size: 13px; font-weight: 900; }
.bracket-scroll { overflow-x: auto; padding: 0 0 24px; }
.bracket-board { display: grid; grid-template-columns: 1fr 210px 1fr; min-width: 1680px; align-items: flex-start; gap: 18px; padding: 10px 2px 20px; }
.bracket-side { display: flex; gap: 12px; }
.bracket-side.is-right { flex-direction: row-reverse; }
.bracket-round { flex: 0 0 154px; }
.bracket-round h3, .bracket-final h3 { height: 32px; margin: 0; color: rgba(255, 255, 255, .8); font-size: 13px; text-align: center; text-transform: uppercase; }
.bracket-matches { display: grid; gap: var(--round-gap); padding-top: var(--round-offset); }
.bracket-match { border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .045); }
.bracket-song { display: flex; min-height: 29px; align-items: center; justify-content: space-between; gap: 6px; padding: 5px 7px; color: rgba(255, 255, 255, .42); font-size: 11px; }
.bracket-song:first-child { border-bottom: 1px solid rgba(255, 255, 255, .14); }
.bracket-song span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bracket-song b { color: var(--red); font-size: 9px; }
.bracket-song.is-winner { color: #ffffff; font-weight: 900; box-shadow: inset 3px 0 0 #ff765a; }
.bracket-final { display: grid; justify-items: center; padding-top: 214px; }
.bracket-final-match { width: 190px; }
.bracket-champion { display: grid; justify-items: center; width: 190px; margin-top: 20px; text-align: center; }
.bracket-champion img { display: block; width: 116px; height: 116px; border: 2px solid var(--yellow); object-fit: cover; }
.bracket-champion span { margin-top: 9px; color: var(--yellow); font-size: 11px; font-weight: 900; }
.bracket-champion strong { margin-top: 4px; color: #ffffff; font-size: 15px; }

.loading, .error-state { display: grid; min-height: 70vh; place-items: center; text-align: center; }
.error-state p { color: var(--muted); }

@media (max-width: 860px) {
  .setup-grid, .result-band { grid-template-columns: 1fr; }
  .cover-wall { order: -1; grid-template-columns: repeat(6, 1fr); transform: none; }
  .cover-wall img:nth-child(2), .cover-wall img:nth-child(5) { transform: none; }
  .group-options, .revival-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .match-arena { grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr); gap: 8px; }
  .qualified-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .topbar { min-height: 58px; }
  .brand-copy small { display: none; }
  .page { padding-top: 24px; }
  .mode-tabs { grid-template-columns: 1fr; }
  .mode-tab { border-right: 0; border-bottom: 1px solid var(--ink); }
  .mode-tab:last-child { border-bottom: 0; }
  .cover-wall { grid-template-columns: repeat(3, 1fr); }
  .selection-tools { grid-template-columns: 1fr 1fr; }
  .selection-tools .search-input { grid-column: 1 / -1; }
  .song-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-header { align-items: start; }
  .group-options { gap: 8px; }
  .song-option-copy { min-height: 80px; padding: 10px; }
  .song-option strong { font-size: 14px; }
  .match-arena { grid-template-columns: 1fr; }
  .versus { font-size: 16px; }
  .match-choice img { aspect-ratio: 16 / 9; }
  .match-copy { min-height: 82px; }
  .revival-grid { grid-template-columns: 1fr 1fr; }
  .share-card { padding: 14px; }
  .bracket-section { padding: 20px 14px; }
  .album-tracks { grid-template-columns: 1fr; }
  .album-track { border-right: 0; }
  .qualified-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bracket-heading { align-items: start; }
}
