@font-face {
  font-family: Fredoka;
  src: url("fonts/fredoka.woff") format("woff");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: Nunito;
  src: url("fonts/nunito.woff") format("woff");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #1e293b;
  --muted: #475569;
  --card: rgba(255, 255, 255, 0.96);
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.35);
  --shadow-sm: 0 6px 16px rgba(15, 23, 42, 0.18);
  --accent: #eab308;
  --royal: #1d4ed8;
  --royal-dark: #1e3a8a;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1e4d8a;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#stage, #stage canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#fxCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

#floatLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9;
}

.float-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

.hidden { display: none !important; }

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top-left {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
}

.hud-top-right {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  pointer-events: auto;
}

.stat-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2.5px solid rgba(30, 41, 59, 0.12);
  border-radius: 18px;
  padding: 8px 12px;
  min-width: 164px;
  box-shadow: var(--shadow-sm);
}

.stat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 0.92rem;
}

.crown-dot { font-size: 1rem; line-height: 1; }

.player-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pct-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 2px;
}

.pct-big {
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--ink);
}

.pct-goal {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f5c400, #f59e0b);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.sub-stats {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
}

.hud-actions { display: flex; gap: 8px; }

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 2.5px solid rgba(30, 41, 59, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-sm);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0;
}

.control-hint {
  position: fixed;
  left: 50%;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 14px));
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.control-hint.fade-out { opacity: 0; }

.ready-prompt {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 12;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid rgba(30, 41, 59, 0.12);
  border-radius: 22px;
  padding: 16px 22px;
  text-align: center;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.ready-prompt small {
  display: block;
  margin-top: 4px;
  font-family: Nunito, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(15, 40, 90, 0.28), rgba(15, 40, 90, 0.45));
}

.modal-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  border: 3px solid rgba(255, 255, 255, 0.7);
  padding: 16px 18px 18px;
  text-align: center;
  max-height: 100%;
  overflow: auto;
}

.start-card { padding-top: 14px; }

.title-wrap { margin-bottom: 6px; }

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

.game-title {
  margin: 2px 0 4px;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-weight: 700;
  font-size: clamp(1.7rem, 7.5vw, 2.35rem);
  line-height: 1.05;
  color: #b45309;
  text-shadow: 0 2px 0 #fde68a;
}

.subtitle {
  margin: 0 auto 6px;
  max-width: 28em;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--muted);
}

.preview-stage {
  margin: 6px auto 10px;
  width: min(280px, 100%);
  height: 140px;
  border-radius: 18px;
  background: linear-gradient(180deg, #9fd4ff, #c8e9b8 70%);
  overflow: hidden;
  border: 2px solid rgba(30, 41, 59, 0.1);
}

.preview-stage canvas,
.end-preview-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.play-btn, .secondary-btn, .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border-radius: 16px;
  border: 0;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  cursor: pointer;
}

.play-btn {
  background: linear-gradient(180deg, #f5c400, #e09400);
  color: #1e293b;
  box-shadow: 0 4px 0 #b45309, 0 8px 16px rgba(180, 83, 9, 0.28);
}

.play-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b45309; }

.secondary-btn {
  background: #e0e7ff;
  color: var(--royal-dark);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  min-height: 44px;
  font-size: 1rem;
}

.btn-stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.rules-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 10px;
  margin-top: 12px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
}

.modal-heading {
  margin: 4px 0 6px;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: clamp(1.35rem, 5.5vw, 1.85rem);
  line-height: 1.15;
}

.modal-copy {
  margin: 0 0 8px;
  font-weight: 700;
  color: var(--muted);
}

.compact-card { width: min(360px, 100%); }

.end-badge { font-size: 2.2rem; line-height: 1; }

.end-preview-wrap {
  margin: 6px auto 10px;
  width: min(240px, 100%);
  height: 120px;
  border-radius: 18px;
  background: linear-gradient(180deg, #9fd4ff, #c8e9b8 70%);
  overflow: hidden;
  border: 2px solid rgba(30, 41, 59, 0.1);
}

.end-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 8px;
}

.end-stat {
  background: #f8fafc;
  border-radius: 14px;
  padding: 8px 6px;
}

.end-stat-val {
  display: block;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
}

.end-stat-lbl {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
}

@media (max-height: 680px) {
  .preview-stage { height: 110px; }
  .end-preview-wrap { height: 96px; }
  .game-title { font-size: 1.6rem; }
  .modal-card { padding: 12px 14px 14px; }
}

@media (max-width: 380px) {
  .stat-card { min-width: 140px; padding: 6px 10px; }
  .pct-big { font-size: 1.2rem; }
}
