:root {
  --bg: #10131c;
  --bg-2: #181c29;
  --surface: #20263a;
  --surface-2: #2a3149;
  --line: #36405e;
  --text: #eef1f8;
  --muted: #9aa3bd;
  --accent: #3fd0c4;
  --accent-ink: #06231f;
  --p1: #3fd0c4;
  --p2: #f0719f;
  --good: #6ee08a;
  --bad: #ff7a70;
  --gold: #ffd166;
  --radius: 14px;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -10%, #1d2540 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom)
    max(16px, env(safe-area-inset-left));
  /* ダブルタップでの拡大と、タップ時の灰色のハイライトを止める */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

main {
  width: 100%;
  max-width: 600px;
  flex: 1;
}

a {
  color: var(--accent);
}

.site-header {
  text-align: center;
  padding: 22px 0 14px;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  letter-spacing: 0.04em;
}

.site-header h1 span {
  color: var(--accent);
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer {
  max-width: 600px;
  padding: 24px 0 20px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

/* ---------- ボタン ---------- */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 700;
  background: var(--surface-2);
  transition: transform 0.08s, filter 0.15s;
  min-height: 44px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* タッチ端末ではタップ後に hover が残るので、マウスがあるときだけ */
@media (hover: hover) {
  button:hover:not(:disabled) {
    filter: brightness(1.12);
  }
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button:focus-visible,
.choice input:focus-visible + .choice-body {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.big {
  width: 100%;
  font-size: 1.15rem;
  padding: 16px;
}

.small {
  font-size: 0.8rem;
  padding: 6px 14px;
  min-height: 36px;
}

/* ---------- 設定画面 ---------- */

.choices {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

#level-choices {
  grid-template-columns: repeat(3, 1fr);
}
#level-choices .choice-body {
  padding: 10px;
}

#level-choices strong {
  font-size: clamp(0.85rem, 4vw, 1.05rem);
  white-space: nowrap;
}


.choices legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.choice {
  display: block;
  cursor: pointer;
}

.choice input {
  position: absolute;
  opacity: 0;
}

.choice-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--bg-2);
}

.choice-body strong {
  font-size: 1.05rem;
}

.choice-body small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.choice input:checked + .choice-body {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-2));
}

.rules {
  margin-top: 22px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.rules summary {
  cursor: pointer;
  font-weight: 700;
}

.rules ol {
  padding-left: 1.3em;
  margin: 10px 0;
}

.rules b {
  color: var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th,
td {
  text-align: left;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  vertical-align: top;
}

thead th {
  border-top: 0;
  color: var(--muted);
  font-weight: 400;
}

tbody th {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}

/* ---------- スコア ---------- */

.topbar {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.scoreboard {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}

.stat {
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 2px solid transparent;
  text-align: center;
  min-width: 0;
}

.stat .label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat .sub {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

.stat.player[data-player="0"] .value {
  color: var(--p1);
}

.stat.player[data-player="1"] .value {
  color: var(--p2);
}

.stat.player.active[data-player="0"] {
  border-color: var(--p1);
}

.stat.player.active[data-player="1"] {
  border-color: var(--p2);
}

.stat.warn .value {
  color: var(--bad);
}

/* ---------- 盤面 ---------- */

/* 盤面は、残った高さと幅の両方に収まる最大の大きさにする (スクロールさせない)。
   カードが 3:4 なので、盤面の 幅:高さ はおよそ 3:行数 になる */
.board-wrap {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

.board {
  --rows: 4;
  --gap: 8px;
  width: min(100cqw, calc((100cqh + var(--gap)) * 3 / var(--rows)));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 6px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 700;
  overflow: hidden;
  min-width: 0;
}

/* 裏面: 音楽プレイヤー風の枠に、ドット絵と番号札 */
.card[data-status="down"] {
  --tone: var(--p1);
  padding: 5px;
  gap: 4px;
  justify-content: stretch;
  align-items: stretch;
  background: #171d33;
  border: 2px solid color-mix(in srgb, var(--tone) 70%, #171d33);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.05);
}

.card[data-status="down"][data-tone="1"] {
  --tone: var(--p2);
}

.card[data-status="down"][data-tone="2"] {
  --tone: var(--gold);
}

.back-art {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background:
    radial-gradient(rgb(255 255 255 / 0.07) 1px, transparent 1.5px) 0 0 / 8px 8px,
    #0d1122;
}

.back-sprite {
  width: 84%;
  max-height: 88%;
}

.back-foot {
  flex: none;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px;
}

.back-eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: clamp(10px, 3.2vmin, 18px);
}

.back-eq i {
  width: clamp(3px, 0.9vmin, 5px);
  height: 100%;
  background: var(--tone);
}

.back-eq i:nth-child(1) {
  height: 50%;
}

.back-eq i:nth-child(3) {
  height: 75%;
}

.back-plate {
  display: grid;
  place-items: center;
  padding: clamp(2px, 0.7vmin, 4px) clamp(3px, 1vmin, 6px);
  border-radius: 3px;
  background: var(--gold);
  color: #1b2140;
}

.back-num {
  display: block;
  height: clamp(9px, 3vmin, 16px);
}

.card[data-status="down"]:disabled {
  opacity: 0.6;
}

.card[data-status="up"] {
  background: linear-gradient(160deg, #fdfdfd, #dfe7f5);
  color: #1a2036;
  border: 2px solid var(--accent);
}

.card.fresh[data-status="up"] {
  animation: flip 0.25s ease-out;
}

.card[data-status="up"]:disabled {
  opacity: 1;
}

.card .num-corner {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 0.7rem;
  opacity: 0.55;
}

.card .hint {
  font-size: clamp(0.62rem, 2.6vw, 0.74rem);
  font-weight: 400;
  opacity: 0.8;
  white-space: pre-line;
  line-height: 1.3;
}

.card[data-status="matched"] {
  background: var(--bg-2);
  border: 2px dashed var(--line);
  color: var(--text);
  justify-content: flex-start;
  padding-top: 18px;
}

.card.fresh[data-status="matched"] {
  animation: pop 0.35s ease-out;
}

.card[data-status="matched"][data-won="0"] {
  border-color: color-mix(in srgb, var(--p1) 60%, transparent);
}

.card[data-status="matched"][data-won="1"] {
  border-color: color-mix(in srgb, var(--p2) 60%, transparent);
}

.card .artist {
  font-size: clamp(0.62rem, 2.8vw, 0.85rem);
  color: var(--gold);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card .title {
  font-size: clamp(0.5rem, 2.2vw, 0.66rem);
  font-weight: 400;
  color: var(--muted);
  line-height: 1.3;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card.wrong {
  border-color: var(--bad);
}

.card.wrong.fresh {
  animation: shake 0.35s;
}

/* イコライザー */
.eq {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 34%;
}

.eq i {
  width: 6px;
  height: 20%;
  border-radius: 3px;
  background: #9aa6c4;
}

.card.playing .eq i {
  background: var(--accent);
  animation: eq 0.7s ease-in-out infinite alternate;
}

.card.playing .eq i:nth-child(2) {
  animation-delay: -0.2s;
}

.card.playing .eq i:nth-child(3) {
  animation-delay: -0.45s;
}

.card.playing .eq i:nth-child(4) {
  animation-delay: -0.1s;
}

/* 読み込み中: 鳴っていないことがひと目で分かるようにする */
.card.loading[data-status="up"] {
  border-color: var(--gold);
  border-style: dashed;
  animation: breathe 1s ease-in-out infinite alternate;
}

.card.paused .eq i {
  animation-play-state: paused;
}

.card.paused .hint {
  font-weight: 700;
  opacity: 1;
}

.card.loading .hint {
  font-weight: 700;
  opacity: 1;
}

.card.playing .hint {
  color: #0b7f76;
  font-weight: 700;
  opacity: 1;
}

@keyframes breathe {
  to {
    filter: brightness(0.82);
  }
}

.card .thumb-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.28;
  pointer-events: none;
}

.card[data-status="matched"] > span {
  position: relative;
  text-shadow: 0 1px 3px #000;
}

.card[data-status="matched"] .title {
  color: var(--text);
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #c3cbe0;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes eq {
  from {
    height: 15%;
  }
  to {
    height: 100%;
  }
}

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

@keyframes flip {
  from {
    transform: rotateY(90deg);
  }
}

@keyframes pop {
  40% {
    transform: scale(1.08);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

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

/* ---------- コール欄 ---------- */

.action {
  /* 手番ごとに高さが変わると盤面が伸び縮みするので、高さは固定する */
  height: 148px;
  flex: none;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--line);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

/* 飾りのドット絵キャラクター (40×40 の絵を整数倍で出す)。カードの大きさには影響させない */
.mascot {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}

/* 設定画面の行進。1 行ぶんの高さしか使わない */
.parade {
  overflow: hidden;
  flex: none;
  margin-bottom: 4px;
}

.parade-track {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0 8px;
}

.parade .mascot {
  width: 40px;
  height: 40px;
}

.parade.flowing .parade-track {
  width: max-content;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 0;
  animation: parade linear infinite;
}

.parade.flowing .mascot {
  margin-right: 8px;
}

@keyframes parade {
  to {
    transform: translateX(-50%);
  }
}

@media (min-width: 768px) and (min-height: 521px) {
  .parade .mascot {
    width: 80px;
    height: 80px;
  }
}

/* 横向きのスマホは案内の幅が狭いので小さく出す */
@media (orientation: landscape) and (max-height: 520px) {
  .mascot {
    width: 40px;
    height: 40px;
  }
}

/* 幅 320px ほどの小さい画面では、ボタンの文字が折り返してしまうので出さない */
@media (max-width: 359px) {
  .action .mascot {
    display: none;
  }
}

@media (min-width: 768px) and (min-height: 521px) {
  .mascot {
    width: 120px;
    height: 120px;
  }
}

.action .buttons button {
  min-height: 52px;
  font-size: 1.05rem;
}

.action p {
  margin: 0;
}

.action .who[data-player="0"] {
  color: var(--p1);
}

.action .who[data-player="1"] {
  color: var(--p2);
}

.action .buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action .verdict {
  font-size: 1.2rem;
  font-weight: 800;
}

.action .verdict.good {
  color: var(--good);
}

.action .verdict.bad {
  color: var(--bad);
}

.action .detail {
  font-size: 0.85rem;
  color: var(--muted);
}

.countdown {
  height: 4px;
  border-radius: 2px;
  background: var(--surface);
  overflow: hidden;
}

.countdown i {
  display: block;
  height: 100%;
  background: var(--muted);
  transform-origin: left;
  animation: drain linear forwards;
}

@keyframes drain {
  to {
    transform: scaleX(0);
  }
}

.start-note {
  margin: 6px 0 0;
  min-height: 1.2em;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* 準備を待つ間に見せる豆知識 */
.tip {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--line);
  text-align: left;
}

.tip[hidden] {
  display: none;
}

.tip.swap .tip-text,
.tip.swap .tip-source {
  animation: tip-in 0.45s ease-out both;
}

@keyframes tip-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.tip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.tip-label {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--gold) 18%, transparent);
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
}

.tip-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.7;
  color: var(--text);
}

.tip-source {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

#setup .tip {
  margin-top: 10px;
}

/* スタート後の準備画面: 進み具合と豆知識だけ */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 14;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: var(--bg);
  overflow: auto;
}

.loading-screen[hidden] {
  display: none;
}

.loading-body {
  width: min(100%, 640px);
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 3vmin, 22px);
}

.loading-title {
  margin: 0;
  text-align: center;
  font-size: clamp(1.1rem, 4vmin, 1.5rem);
  font-weight: 700;
}

.loading-progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.loading-progress .progress {
  flex: 1;
  height: 14px;
  border-radius: 7px;
}

.loading-count {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.loading-screen .tip {
  padding: clamp(16px, 4vmin, 28px);
  min-height: clamp(150px, 34vmin, 240px);
}

.loading-screen .tip-text {
  font-size: clamp(1.15rem, 4.6vmin, 1.7rem);
  line-height: 1.65;
}

.loading-screen .tip-source {
  font-size: 0.8rem;
}

.preload {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.preload .progress {
  flex: 1;
}

.progress {
  height: 8px;
  border-radius: 4px;
  background: var(--surface);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

#quit {
  flex: none;
  border-radius: var(--radius);
  min-height: 0;
  padding: 6px 12px;
}

#quit.armed {
  border-color: var(--bad);
  color: var(--bad);
}

/* ---------- ゲーム中は1画面に収める ---------- */

body[data-screen="game"] {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body[data-screen="game"] .site-header,
body[data-screen="game"] .site-footer {
  display: none;
}

body[data-screen="game"] main {
  min-height: 0;
  display: flex;
}

#game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 12px;
}

/* 横向きのスマホ: 盤面を左、スコアとコール欄を右に並べる */
@media (orientation: landscape) and (max-height: 520px) {
  body[data-screen="game"] main {
    max-width: none;
  }

  #game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "board top" "board preload" "board action";
    column-gap: 14px;
  }

  .topbar {
    grid-area: top;
  }

  .preload {
    grid-area: preload;
  }

  .board-wrap {
    grid-area: board;
  }

  .action {
    grid-area: action;
    height: auto;
    min-height: 148px;
    align-self: end;
  }
}

/* ---------- 結果 ---------- */

.result-head {
  text-align: center;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.result-head h2 {
  margin: 0;
  font-size: 1.5rem;
}

.result-head .final {
  font-size: 3rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.result-head .final .p0 {
  color: var(--p1);
}

.result-head .final .p1 {
  color: var(--p2);
}

.result-head .breakdown {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 4px 0 0;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 22px;
}

/* X に投稿するリンク。ボタンと同じ見た目で、2 つのボタンの下に 1 行で置く */
.share {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

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

@media (hover: hover) {
  .share:hover {
    filter: brightness(1.12);
    background: var(--surface-2);
  }
}

.answers h3 {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin: 0 0 8px;
}

.answers ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.answers li {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border-left: 4px solid var(--line);
}

.answers li.found {
  border-left-color: var(--good);
}

.answers li[data-won="0"] {
  border-left-color: var(--p1);
}

.answers li[data-won="1"] {
  border-left-color: var(--p2);
}

.answers .artist-name {
  font-weight: 800;
  color: var(--gold);
}

.answers .state {
  float: right;
  font-size: 0.72rem;
  color: var(--muted);
}

.answers .song {
  display: block;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

/* 答え合わせの 1 曲: サムネイルの横に曲名と「サビを聴く」 */
.review-song {
  clear: both;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.review-song .thumb {
  flex: none;
  position: relative;
  width: 96px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  outline: 2px solid transparent;
}

.review-song.playing .thumb {
  outline-color: var(--accent);
}

.review-song .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.review-song .thumb .eq {
  display: none;
}

.review-body {
  min-width: 0;
  display: grid;
  gap: 6px;
  justify-items: start;
}

.review-play[data-state="playing"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.review-play[data-state="loading"] {
  opacity: 0.7;
}

/* ---------- 正解の演出 ---------- */

.celebrate {
  --who: var(--gold);
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  background: rgb(9 11 20 / 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  animation: flash 0.5s ease-out;
}

.celebrate[data-player="0"] {
  --who: var(--p1);
}

.celebrate[data-player="1"] {
  --who: var(--p2);
}

.celebrate .confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* 後ろで回る光の筋 */
.celebrate .rays {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 200vmax;
  height: 200vmax;
  margin: -100vmax 0 0 -100vmax;
  background: repeating-conic-gradient(from 0deg, rgb(255 209 102 / 0.13) 0 9deg, transparent 9deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0, transparent 38%);
  mask-image: radial-gradient(circle, #000 0, transparent 38%);
  animation: rays 24s linear infinite, fade-in 0.6s ease-out;
  pointer-events: none;
}

.celebrate-body {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1.4vmin, 10px);
}

.celebrate p,
.celebrate h2,
.celebrate figure {
  margin: 0;
}

.celebrate .cheer {
  font-size: clamp(2rem, 11vmin, 4rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff6c9 10%, var(--gold) 45%, #ff9d5c 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgb(0 0 0 / 0.35)) drop-shadow(0 0 22px rgb(255 209 102 / 0.55));
  animation: slam 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.celebrate .combo {
  font-size: clamp(0.95rem, 4.4vmin, 1.5rem);
  font-weight: 900;
  font-style: italic;
  color: var(--p2);
  text-shadow: 0 0 14px rgb(240 113 159 / 0.7);
  animation: slam 0.5s 0.25s cubic-bezier(0.2, 1.6, 0.4, 1) both, wiggle 0.5s 0.8s ease-in-out infinite alternate;
}

.celebrate .pair {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 3vmin, 18px);
  margin-top: clamp(2px, 1.5vmin, 10px);
}

.song-card {
  min-width: 0;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--line);
  overflow: hidden;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  animation: fly-left 0.6s 0.25s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

.song-card:nth-child(2) {
  animation-name: fly-right;
  animation-delay: 0.4s;
}

.song-card.playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(63 208 196 / 0.3), 0 10px 30px rgb(0 0 0 / 0.5);
}

.song-card .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0b0d16;
}

.song-card .thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.song-card .thumb .eq {
  display: none;
  position: absolute;
  right: 6px;
  bottom: 6px;
  height: 22px;
  padding: 4px 6px;
  box-sizing: content-box;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.65);
}

.song-card.playing .thumb .eq {
  display: flex;
}

.song-card.playing .eq i {
  width: 4px;
  background: var(--accent);
  animation: eq 0.7s ease-in-out infinite alternate;
}

.song-card.playing .eq i:nth-child(2) {
  animation-delay: -0.2s;
}

.song-card.playing .eq i:nth-child(3) {
  animation-delay: -0.45s;
}

.song-card.playing .eq i:nth-child(4) {
  animation-delay: -0.1s;
}

.song-card figcaption {
  padding: 6px 8px 8px;
  text-align: left;
}

.song-title {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: clamp(0.72rem, 3.1vmin, 0.95rem);
  font-weight: 700;
  line-height: 1.35;
}

.song-meta {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.6rem, 2.4vmin, 0.72rem);
  color: var(--muted);
}

.celebrate .same {
  margin-top: clamp(2px, 1.5vmin, 10px);
  font-size: clamp(0.7rem, 2.8vmin, 0.85rem);
  color: var(--muted);
  letter-spacing: 0.2em;
  animation: fade-in 0.4s 0.65s both;
}

.celebrate .pname {
  max-width: 100%;
  font-size: clamp(1.5rem, 9vmin, 3.2rem);
  font-weight: 900;
  line-height: 1.15;
  overflow-wrap: anywhere;
  color: #fff;
  text-shadow: 0 0 18px var(--who), 0 0 42px var(--who), 0 3px 0 rgb(0 0 0 / 0.4);
}

.celebrate .pname span {
  display: inline-block;
  animation: letter 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}

.celebrate .gain {
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--who);
  color: #111522;
  font-weight: 800;
  font-size: clamp(0.9rem, 3.6vmin, 1.1rem);
  animation: slam 0.45s 1.1s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.celebrate .tap-next {
  font-size: 0.72rem;
  color: var(--muted);
  animation: fade-in 0.4s 1.4s both;
}

.celebrate .countdown {
  width: min(60%, 240px);
}

/* 横向きのスマホなど、高さがないとき */
@media (max-height: 520px) {
  .celebrate-body {
    width: min(100%, 760px);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    column-gap: 18px;
    justify-items: center;
    align-items: center;
  }

  .celebrate .pair {
    grid-column: 1;
    grid-row: 1 / span 7;
    margin: 0;
  }

  .celebrate-body > :not(.pair) {
    grid-column: 2;
  }

  .song-title {
    -webkit-line-clamp: 2;
  }
}

@keyframes flash {
  from {
    background: rgb(255 255 255 / 0.85);
  }
}

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes slam {
  from {
    opacity: 0;
    transform: scale(2.6) rotate(-8deg);
  }
}

@keyframes wiggle {
  from {
    transform: rotate(-3deg) scale(1);
  }
  to {
    transform: rotate(3deg) scale(1.08);
  }
}

@keyframes fly-left {
  from {
    opacity: 0;
    transform: translateX(-70vw) rotate(-14deg);
  }
}

@keyframes fly-right {
  from {
    opacity: 0;
    transform: translateX(70vw) rotate(14deg);
  }
}

@keyframes letter {
  from {
    opacity: 0;
    transform: translateY(0.6em) scale(0.3) rotate(-20deg);
  }
}

/* ---------- その他 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: max-content;
  text-align: center;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 18px;
  background: #3a1f25;
  border: 1px solid var(--bad);
  color: #ffd9d6;
  font-size: 0.85rem;
  z-index: 10;
}

#media {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 256px;
  height: 144px;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.media-slot {
  position: absolute;
  inset: 0;
}

[hidden] {
  display: none !important;
}

.debug {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  background: rgb(0 0 0 / 0.8);
  color: #9f9;
  font: 10px/1.3 ui-monospace, monospace;
  white-space: pre-wrap;
  pointer-events: none;
  z-index: 20;
}

.media-slot iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* BGM の切り替え */
.bgm-toggle {
  white-space: nowrap;
}

.bgm-toggle[aria-pressed="false"] {
  opacity: 0.6;
}

.site-header .bgm-toggle {
  margin-top: 10px;
}
