:root {
  --navy: #0b1224;
  --navy-2: #121a33;
  --tile-0: #0f1730;
  --cream: #f3e6c8;
  --coral: #ff6b6b;
  --coral-deep: #e8455a;
  --lime: #c8ff3d;
  --ink: #0b1224;
  --muted: #8a93a8;
  --white: #f7f4ee;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--navy);
  color: var(--white);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

#app {
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  gap: 8px;
}

.top { text-align: center; padding-top: 4px; }
.brand {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 1.05rem;
  color: var(--cream);
}
.stats {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.lime { color: var(--lime); }

#stage {
  display: grid;
  place-items: center;
  min-height: 0;
}

.grid {
  width: min(92vw, 360px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.tile {
  position: relative;
  border-radius: 14px;
  background: var(--tile-0);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 4px 0 rgba(0,0,0,0.35);
  display: grid;
  place-items: center;
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  font-weight: 800;
  color: transparent;
  transition: transform 80ms ease-out, background 120ms ease, color 120ms ease;
  -webkit-touch-callout: none;
}
.tile.v1 { background: var(--cream); color: var(--ink); }
.tile.v2 { background: var(--coral); color: var(--white); }
.tile.v3 { background: var(--coral-deep); color: var(--white); }
.tile:active { transform: scale(0.94); }

.tile.flash {
  background: var(--lime) !important;
  color: var(--ink) !important;
  animation: burst 320ms ease-out;
}
.tile.flash.show0::after {
  content: "0";
  color: var(--ink);
}

@keyframes burst {
  0% { transform: scale(0.86); box-shadow: 0 0 0 0 rgba(200,255,61,0.55); }
  55% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(200,255,61,0); }
  100% { transform: scale(1); }
}

.plus-burst {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--ink);
  opacity: 0;
}
.tile.flash .plus-burst {
  animation: pluspop 320ms ease-out;
}
@keyframes pluspop {
  0% { opacity: 0; transform: translateY(6px) scale(0.7); }
  35% { opacity: 1; transform: translateY(-2px) scale(1.15); }
  100% { opacity: 0; transform: translateY(-14px) scale(0.9); }
}

.bottom { text-align: center; }
.hint {
  min-height: 1.2em;
  color: var(--muted);
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ghost {
  background: var(--navy-2);
  border-radius: 12px;
  padding: 12px 8px;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--cream);
}
.ghost[disabled] { opacity: 0.35; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 22, 0.78);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.overlay[hidden] { display: none !important; }
.card {
  width: min(340px, 100%);
  background: var(--navy);
  border: 2px solid var(--lime);
  border-radius: 22px;
  padding: 22px 20px 18px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.45);
}
.card-kicker {
  letter-spacing: 0.16em;
  font-weight: 800;
  font-size: 0.85rem;
  margin-bottom: 14px;
  color: var(--cream);
}
.rules {
  text-align: left;
  margin: 0 0 18px;
  padding-left: 1.2em;
  color: var(--cream);
  line-height: 1.45;
  font-size: 0.92rem;
}
.rules li { margin-bottom: 0.55em; }
.coral {
  width: 100%;
  background: var(--coral);
  color: var(--white);
  border-radius: 14px;
  padding: 14px 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 1rem;
}
.coral:active { transform: scale(0.98); }
.clear-card .big-zero {
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
}
.clear-card .big-zero::after {
  content: "";
  display: inline-block;
  width: 0.18em;
  height: 0.18em;
  margin-left: -0.55em;
  margin-bottom: 0.55em;
  border-radius: 50%;
  background: var(--lime);
  vertical-align: middle;
}
.clear-title {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  color: var(--cream);
  margin-top: 4px;
}
.clear-sub {
  color: var(--muted);
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  margin: 6px 0 18px;
  font-weight: 700;
}
.fail-copy {
  color: var(--cream);
  margin: 0 0 18px;
}

@media (min-width: 720px) {
  #app { max-width: 420px; }
  .grid { width: 360px; }
}

.tile.coach {
  box-shadow: 0 0 0 3px var(--lime), 0 6px 0 rgba(0,0,0,0.35);
  animation: coachpulse 900ms ease-in-out infinite;
  z-index: 2;
}
.tile.coach-dim { opacity: 0.38; }
@keyframes coachpulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.stats .coach-pulse,
#moves.coach-pulse {
  color: var(--lime) !important;
  animation: coachpulse 700ms ease-in-out infinite;
}
.top { position: relative; }
.how-link {
  position: absolute;
  right: 0;
  top: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--navy-2);
  color: var(--lime);
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1;
}
.rules-actions { display: grid; gap: 10px; }
.rules-actions .ghost.full {
  width: 100%;
  background: var(--navy-2);
  border-radius: 14px;
  padding: 12px;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: var(--cream);
}
.ghost.full { width: 100%; }
