@font-face {
  font-family: Fraunces;
  src: url("../assets/fonts/fraunces.woff") format("woff");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: Figtree;
  src: url("../assets/fonts/figtree.woff") format("woff");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #f6f0ea;
  --cream-deep: #ebe1d6;
  --tile: #e8ddd3;
  --grout: rgba(120, 92, 78, 0.11);
  --ink: #2c2622;
  --ink-soft: #5c514a;
  --blush: #c1958a;
  --blush-deep: #9a6e66;
  --amber: #c99a3a;
  --amber-bright: #e8b84a;
  --ottoman: #d4b0a6;
  --shadow: 0 18px 40px rgba(60, 40, 32, 0.18);
  --beat: 0.625s;
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: Figtree, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--cream);
  background-image:
    linear-gradient(var(--grout) 1px, transparent 1px),
    linear-gradient(90deg, var(--grout) 1px, transparent 1px);
  background-size: 64px 64px;
  background-position: center top;
  min-height: 100dvh;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px 16px 28px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.top {
  text-align: center;
  margin: 4px 0 14px;
}
.top h1 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  font-size: clamp(2rem, 6vw, 3.1rem);
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.05;
  font-variation-settings: "SOFT" 50, "WONK" 0.4, "opsz" 48;
}
.tag {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

.board-card {
  display: none;
  background: rgba(255, 250, 246, 0.86);
  border: 1px solid rgba(120, 92, 78, 0.12);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 8px 24px rgba(60, 40, 32, 0.06);
}
.board-card h2 {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 10px;
}
.board-card ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}
.board-card li,
.end-board li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(120, 92, 78, 0.1);
  font-variant-numeric: tabular-nums;
}
.board-card li:last-child { border-bottom: 0; }
.board-card li::before,
.end-board li::before {
  counter-increment: rank;
  content: counter(rank);
  color: var(--blush-deep);
  font-weight: 600;
  width: 1.2em;
}
.board-card .empty { color: var(--ink-soft); font-size: 0.92rem; padding: 6px 0; }

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px 12px;
  align-items: end;
  margin-bottom: 10px;
}
.stat .label {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stat .value {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.55rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.lives { display: flex; gap: 6px; padding-bottom: 6px; }
.life {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--amber-bright);
  box-shadow: inset 0 0 0 2px rgba(90, 60, 20, 0.15);
}
.life.gone {
  background: transparent;
  box-shadow: inset 0 0 0 2px rgba(92, 81, 74, 0.35);
}

.stage-wrap {
  position: relative;
  width: min(100%, 420px, calc((100dvh - 280px) * 9 / 16));
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #d9cfc4;
}
.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.stage img#cat {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.cat-motion {
  position: absolute;
  inset: 0;
  transform-origin: 50% 72%;
}
.cat-motion.dance-1 { animation: bounce var(--beat) ease-in-out infinite; }
.cat-motion.dance-2 { animation: wiggle var(--beat) ease-in-out infinite; }
.cat-motion.fever-dance { animation: feverDance calc(var(--beat) * 0.85) ease-in-out infinite; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes wiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-12px) rotate(-1.6deg); }
  75% { transform: translateY(-5px) rotate(1.6deg); }
}
@keyframes feverDance {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1.08); }
  25% { transform: translateY(-16px) rotate(-3deg) scale(1.12); }
  50% { transform: translateY(-6px) rotate(0deg) scale(1.09); }
  75% { transform: translateY(-14px) rotate(3deg) scale(1.12); }
}

.beat-ring {
  position: absolute;
  inset: 10% 8%;
  border-radius: 50%;
  border: 2px solid rgba(201, 154, 58, 0);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
}
.beat-ring.pulse {
  animation: ring var(--beat) linear 1;
}
@keyframes ring {
  0% { opacity: 0; transform: scale(1.18); border-color: rgba(201, 154, 58, 0); }
  75% { opacity: 0.65; border-color: rgba(201, 154, 58, 0.5); }
  100% { opacity: 0; transform: scale(0.78); border-color: rgba(201, 154, 58, 0.75); }
}

.fever-wash {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 30%, rgba(232, 184, 74, 0.62), transparent 42%),
    radial-gradient(circle at 80% 20%, rgba(193, 149, 138, 0.58), transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(255, 236, 180, 0.32), transparent 55%),
    radial-gradient(circle at 70% 80%, rgba(243, 210, 122, 0.5), transparent 40%),
    linear-gradient(180deg, rgba(255, 220, 140, 0.28), rgba(154, 110, 102, 0.22));
  mix-blend-mode: soft-light;
  animation: wash 0.7s ease-in-out infinite alternate;
}
@keyframes wash {
  from { filter: hue-rotate(-14deg) brightness(1.06) saturate(1.18); opacity: 0.82; }
  to { filter: hue-rotate(16deg) brightness(1.24) saturate(1.28); opacity: 1; }
}
body.fever {
  background-color: #f3e4c9;
  animation: bodyPulse 0.65s ease-in-out infinite alternate;
}
@keyframes bodyPulse {
  from { background-color: #f7e7c2; }
  to { background-color: #efc57a; }
}
body.fever .stage-wrap {
  box-shadow: 0 0 0 3px rgba(232, 184, 74, 0.55), 0 0 36px rgba(232, 184, 74, 0.45), var(--shadow);
  animation: feverGlow 0.7s ease-in-out infinite alternate;
}
body.fever .stage-wrap.shake {
  animation: feverShake 0.42s ease-out, feverGlow 0.7s ease-in-out infinite alternate;
}
@keyframes feverGlow {
  from { box-shadow: 0 0 0 3px rgba(232, 184, 74, 0.4), 0 0 22px rgba(232, 184, 74, 0.28), var(--shadow); }
  to { box-shadow: 0 0 0 5px rgba(255, 220, 140, 0.75), 0 0 48px rgba(232, 184, 74, 0.55), var(--shadow); }
}
@keyframes feverShake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-7px, 3px); }
  35% { transform: translate(8px, -4px); }
  55% { transform: translate(-5px, 3px); }
  75% { transform: translate(5px, -2px); }
}
.fever-flash {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 244, 210, 0.88), rgba(232, 184, 74, 0.45) 48%, transparent 72%);
  animation: feverFlash 0.38s ease-out forwards;
}
@keyframes feverFlash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
body.fever #streak {
  font-size: 2.05rem;
  color: #8a5a10;
  animation: comboPulse 0.4s ease-in-out infinite alternate;
}
@keyframes comboPulse {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}
body.fever .beat-ring.pulse {
  animation: ringFever var(--beat) linear 1;
}
@keyframes ringFever {
  0% { opacity: 0; transform: scale(1.22); border-color: rgba(232, 184, 74, 0); }
  70% { opacity: 0.9; border-color: rgba(232, 184, 74, 0.85); }
  100% { opacity: 0; transform: scale(0.72); border-color: rgba(201, 154, 58, 0.95); }
}

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

.cheese {
  position: absolute;
  z-index: 5;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 6px 8px rgba(60, 40, 32, 0.28));
  animation: cheeseSpin 1.6s linear infinite;
}
.cheese img { width: 100%; height: 100%; display: block; pointer-events: none; }
@keyframes cheeseSpin {
  0% { transform: rotate(-8deg); }
  50% { transform: rotate(10deg); }
  100% { transform: rotate(-8deg); }
}

.toast {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  font-size: 1.6rem;
  color: #7a4e14;
  background: rgba(255, 247, 230, 0.92);
  padding: 6px 16px 8px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(60, 40, 32, 0.16);
  pointer-events: none;
  letter-spacing: -0.02em;
}
.toast.fever-toast {
  top: 7%;
  font-size: clamp(2.15rem, 8vw, 3.35rem);
  padding: 10px 28px 14px;
  color: #6b3d0c;
  background: rgba(255, 246, 214, 0.96);
  box-shadow: 0 8px 28px rgba(201, 154, 58, 0.38), 0 0 0 3px rgba(232, 184, 74, 0.45);
  animation: toastPop 0.42s cubic-bezier(0.2, 1.35, 0.3, 1);
  letter-spacing: -0.03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
@keyframes toastPop {
  0% { transform: translateX(-50%) scale(0.62); }
  58% { transform: translateX(-50%) scale(1.1); }
  100% { transform: translateX(-50%) scale(1); }
}

.controls { text-align: center; margin-top: 14px; }
.clap-btn {
  appearance: none;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #faf4ee;
  background: linear-gradient(180deg, #b58379 0%, var(--blush-deep) 100%);
  border: 0;
  border-radius: 999px;
  min-width: min(100%, 280px);
  height: 58px;
  padding: 0 36px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 8px 0 #6f4a44, 0 12px 20px rgba(60, 40, 32, 0.2);
  transform: translateY(0);
  touch-action: manipulation;
}
.clap-btn:hover { filter: brightness(1.05); }
.clap-btn:active, .clap-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 4px 0 #6f4a44, 0 6px 12px rgba(60, 40, 32, 0.18);
}
.clap-btn:focus-visible, .primary:focus-visible, .ghost:focus-visible, .mute:focus-visible {
  outline: 3px solid var(--amber-bright);
  outline-offset: 3px;
}
.hint {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

footer {
  margin-top: 22px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
footer a {
  color: var(--blush-deep);
  text-decoration-color: rgba(154, 110, 102, 0.4);
  text-underline-offset: 2px;
}
footer a:hover { color: var(--ink); }

.mute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 250, 246, 0.9);
  color: var(--ink-soft);
  box-shadow: 0 4px 14px rgba(60, 40, 32, 0.12);
  cursor: pointer;
  z-index: 20;
  display: grid;
  place-items: center;
}
.mute[aria-pressed="true"] { color: var(--blush-deep); }

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.hud, .controls {
  width: min(100%, 440px);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 52, 42, 0.34);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}
.overlay[hidden] { display: none; }
.panel {
  width: min(420px, 100%);
  background: #fbf7f3;
  border-radius: 24px;
  padding: 28px 24px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.panel-face {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 10px;
  box-shadow: 0 8px 18px rgba(60, 40, 32, 0.16);
}
.panel h2 {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.9rem;
  margin: 0 0 10px;
  letter-spacing: -0.03em;
  font-weight: 600;
}
.panel p {
  margin: 0 0 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.panel-note { font-size: 0.92rem; }
.primary, .ghost {
  appearance: none;
  font-family: Figtree, system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  border: 0;
}
.primary {
  color: #faf4ee;
  background: var(--blush-deep);
  min-width: 160px;
}
.primary:hover { filter: brightness(1.06); }
.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(120, 92, 78, 0.28);
}
.end-score {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.15rem;
  color: var(--ink) !important;
  line-height: 1.35;
}
.end-score span {
  font-size: 1.7rem;
  font-weight: 600;
  display: inline-block;
  padding: 0 4px;
}
.end-sub { font-size: 0.92rem; }
.share-preview {
  width: min(260px, 80%);
  border-radius: 12px;
  margin: 8px auto 16px;
  display: block;
  box-shadow: 0 8px 20px rgba(60, 40, 32, 0.16);
  background: var(--cream-deep);
}
.end-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

@media (min-width: 880px) {
  .page { padding-top: 22px; }
  .layout {
    grid-template-columns: 200px 1fr 200px;
    gap: 28px;
  }
  .board-card { display: block; position: sticky; top: 20px; }
  .stage-wrap { width: min(100%, 440px, calc((100dvh - 260px) * 9 / 16)); }
}

@media (max-width: 879px) {
  .hud { grid-template-columns: 1fr 1fr 1fr auto; }
  .stat .value { font-size: 1.3rem; }
}
