:root {
  --bg-top: #17301f;
  --bg-bottom: #0a1810;
  --panel: #1f3f28;
  --panel-light: #2a5234;
  --track: #122417;
  --text: #f2f9f3;
  --text-dim: #9fc4a8;
  --danger: #ff5a5a;
  --accent: #7ddc6f;
  --on-accent: #0d2211;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

button { font-family: inherit; }

.screen {
  height: 100vh;
  height: 100dvh;
  padding: calc(16px + var(--safe-top)) 18px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}
.screen[hidden] { display: none; }

.brand { font-size: 32px; font-weight: 800; margin: 0; letter-spacing: -0.5px; }
.brand.small { font-size: 20px; }
.accent { color: var(--accent); }

/* ---------- Home ---------- */

.home-sub { color: var(--text-dim); margin: 6px 0 30px; font-size: 15px; }

.home-stat {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-stat-label { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.home-stat-value { font-size: 26px; font-weight: 800; color: var(--accent); }

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.btn-secondary { background: transparent; color: var(--text); border: 1.5px solid rgba(255,255,255,0.18); margin-top: 12px; }

.rules-blurb {
  margin-top: auto;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

/* ---------- Game screen ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.icon-btn {
  background: rgba(255,255,255,0.07);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}
.hud-chip {
  flex: 1;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: center;
}
.hud-chip-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.hud-chip-value { font-size: 18px; font-weight: 800; }

.grid-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.tile-grid {
  display: grid;
  gap: 6px;
}

.tile {
  aspect-ratio: 1;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: transform 0.12s ease;
}
.tile:active { transform: scale(0.92); }
.tile.gone { visibility: hidden; pointer-events: none; }
.tile.hint {
  animation: hint-glow 0.9s ease-in-out infinite;
}
@keyframes hint-glow {
  0%, 100% { box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
  50% { box-shadow: 0 0 0 3px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 70%, transparent); }
}

.tray-wrap {
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 10px;
  margin-top: 12px;
}

.tray {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.tray-slot {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--track);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.tray-slot.filled { background: var(--panel-light); }
.tray-slot.pop { animation: tray-pop 0.3s ease; }
@keyframes tray-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.controls-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex: 0 0 auto;
}

.control-btn {
  flex: 1;
  background: var(--panel-light);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.control-btn .emoji-ic { font-size: 22px; }
.control-btn:disabled { opacity: 0.4; }
.control-btn .count-badge {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
  font-size: 10px;
  padding: 1px 6px;
  margin-left: 4px;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 5, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay[hidden] { display: none; }
#confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.overlay-card {
  position: relative;
  background: var(--panel-light);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 30px 26px;
  text-align: center;
  width: min(90vw, 360px);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 60px color-mix(in srgb, var(--accent) 30%, transparent);
}
.overlay-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 6px;
}
.overlay-title { font-size: 26px; margin: 0 0 8px; }
.overlay-sub { color: var(--text-dim); margin: 0 0 22px; }
