@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: #ff4f8b;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #172f52;
  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;
}

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

.hidden {
  display: none !important;
}

/* HUD */
.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));
  pointer-events: none;
}

.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;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #1e293b;
  flex-shrink: 0;
}

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

.lives-row {
  margin-left: auto;
  font-size: 0.85rem;
  letter-spacing: 1px;
}

.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: 5px 0 4px;
}

.progress-fill {
  height: 100%;
  width: 2%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s ease;
}

.sub-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--muted);
}

.hud-top-right {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 2.5px solid rgba(30, 41, 59, 0.14);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-sm);
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

.leaderboard {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2.5px solid rgba(30, 41, 59, 0.12);
  border-radius: 16px;
  padding: 7px 10px;
  width: 162px;
  box-shadow: var(--shadow-sm);
}

.lb-title {
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}

.lb-rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 4px;
  border-radius: 7px;
}

.lb-row.is-me {
  background: rgba(59, 130, 246, 0.14);
  font-weight: 800;
}

.lb-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid #1e293b;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.minimap-wrap {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 106px;
  height: 106px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

#minimapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.control-hint {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 999px;
  transition: opacity 0.5s ease;
  max-width: calc(100vw - 140px);
}

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

.banner-toast {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffffff;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2.5px solid #fbbf24;
  box-shadow: var(--shadow-sm);
  z-index: 25;
  pointer-events: none;
  white-space: nowrap;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 30;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  background: var(--card);
  border: 3.5px solid #1e293b;
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
  text-align: center;
}

.compact-card {
  max-width: 340px;
  padding: 24px 20px;
}

.game-title {
  margin: 0;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #ff6b2b;
  text-shadow: 0 3px 0 #1e293b;
  -webkit-text-stroke: 1.5px #1e293b;
}

.subtitle {
  margin: 5px 0 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--muted);
}

.preview-stage {
  margin: 10px auto 6px;
  width: 240px;
  height: 118px;
  border-radius: 20px;
  background: radial-gradient(circle at 50% 60%, #ffffff 0%, #f1f5f9 100%);
  border: 2.5px solid #cbd5e1;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#previewCanvas {
  width: 240px;
  height: 118px;
  display: block;
}

.picker-section {
  margin: 10px 0 12px;
}

.section-label {
  display: block;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  max-width: 264px;
  margin: 0 auto;
}

.color-swatch {
  width: 52px;
  height: 44px;
  margin: 0 auto;
  border-radius: 14px;
  border: 3px solid #1e293b;
  cursor: pointer;
  position: relative;
  box-shadow: 0 4px 0 rgba(30, 41, 59, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.color-swatch:active {
  transform: translateY(2px);
}

.color-swatch.selected {
  transform: scale(1.08);
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px #1e293b;
}

.color-swatch.selected::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 900;
  font-size: 1.2rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

.name-row {
  display: flex;
  gap: 10px;
  margin: 8px 0 12px;
}

.name-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border-radius: 16px;
  border: 3px solid #1e293b;
  padding: 0 14px;
  font-family: "Nunito", sans-serif;
  font-size: 1rem;
  font-weight: 800;
  color: var(--ink);
  background: #f8fafc;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.name-input:focus {
  border-color: #2563eb;
  background: #ffffff;
}

.play-btn {
  height: 48px;
  padding: 0 22px;
  border-radius: 16px;
  border: 3px solid #1e293b;
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 100%);
  color: #052e16;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #1e293b;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  white-space: nowrap;
}

.play-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1e293b;
}

.secondary-btn {
  height: 44px;
  padding: 0 18px;
  border-radius: 14px;
  border: 3px solid #1e293b;
  background: #fde047;
  color: #1e293b;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #1e293b;
}

.ghost-btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
  font-family: "Nunito", sans-serif;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
}

.rules-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 14px;
  padding: 8px 10px;
}

.modal-heading {
  margin: 4px 0 4px;
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-copy {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
}

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

.end-preview-wrap {
  margin: 6px auto 10px;
  width: 200px;
  height: 110px;
  border-radius: 18px;
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  display: grid;
  place-items: center;
}

.end-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.end-stat {
  background: #f1f5f9;
  border-radius: 14px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
}

.end-stat-val {
  font-family: "Fredoka", ui-rounded, sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}

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

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 700px) {
  .stat-card {
    min-width: 200px;
    padding: 10px 14px;
  }
  .leaderboard {
    width: 192px;
    padding: 9px 12px;
  }
  .minimap-wrap {
    width: 132px;
    height: 132px;
  }
}

@media (max-width: 420px) {
  .modal-card {
    padding: 14px 14px 12px;
    border-radius: 22px;
  }
  .color-swatch {
    width: 48px;
    height: 40px;
  }
  .stat-card {
    min-width: 144px;
    padding: 7px 10px;
  }
  .pct-big {
    font-size: 1.25rem;
  }
  .leaderboard {
    width: 136px;
    padding: 6px 8px;
  }
  .minimap-wrap {
    width: 90px;
    height: 90px;
  }
}
