/* ═══════════════════════════════════════════════════════
   FlashGrid — v2 production stylesheet
   Premium casual · editorial · mobile-first
   ═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg:      #fafaf9;
  --surface: #ffffff;
  --off:     #f3f3f2;
  --border:  #e5e5e3;
  --border2: #c7c7c4;
  --ink:     #1a1a19;
  --ink2:    #4a4a48;
  --ink3:    #8a8a87;
  --ink4:    #b5b5b2;

  --accent:     #2563eb;
  --accent-soft:#dbeafe;

  --flash-bg: #dbeafe; --flash-bd: #93bbfd;
  --sel-bg:   #dbeafe; --sel-bd:   #2563eb;
  --good-bg:  #dcfce7; --good-bd:  #22c55e;
  --near-bg:  #fef9c3; --near-bd:  #eab308;
  --bad-bg:   #fee2e2; --bad-bd:   #ef4444;
  --miss-bg:  #f0f0ee; --miss-bd:  #c7c7c4;

  --timer:      #1a1a19;
  --timer-warn: #ea580c;
  --timer-hot:  #dc2626;

  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'DM Mono', 'Menlo', monospace;
  --r:  10px;
  --r2: 14px;

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button {
  font-family: var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: none; background: none;
}
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }


/* ═══════════════════════════════════════════════════════
   CONFETTI CANVAS
   ═══════════════════════════════════════════════════════ */
#confettiCanvas {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none; width: 100%; height: 100%;
}


/* ═══════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10,10,10,0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end;
  animation: fadeIn 0.18s ease both;
}
@media (min-width: 500px) {
  .modal-backdrop { align-items: center; justify-content: center; padding: 20px; }
}
.modal {
  width: 100%; max-width: 420px; margin: 0 auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  overflow: hidden;
  box-shadow: 0 -1px 0 var(--border), 0 -8px 48px rgba(0,0,0,0.14);
  animation: sheetUp 0.3s var(--ease-out-expo) both;
}
@media (min-width: 500px) {
  .modal {
    border-radius: var(--r2);
    box-shadow: 0 24px 80px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05);
    animation: popIn 0.22s var(--ease-spring) both;
  }
}

.modal-backdrop.modal-backdrop-center {
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.modal-backdrop-center .modal {
  border-radius: var(--r2);
  box-shadow: 0 24px 80px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05);
  animation: popIn 0.22s var(--ease-spring) both;
}
.modal-backdrop.modal-backdrop-center .modal::before {
  display: none;
}
.modal::before {
  content: ''; display: block; width: 36px; height: 4px;
  background: var(--border2); border-radius: 2px; margin: 12px auto 0;
}
@media (min-width: 500px) { .modal::before { display: none; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.modal-close {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: var(--ink3);
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--off); color: var(--ink); }

.modal-stats { display: grid; grid-template-columns: repeat(4,1fr); border-bottom: 1px solid var(--border); }
.mstat {
  display: flex; flex-direction: column; align-items: center;
  padding: 22px 6px 16px; gap: 6px; border-right: 1px solid var(--border);
}
.mstat:last-child { border-right: none; }
.mstat-v { font-size: 28px; font-weight: 800; letter-spacing: -1.5px; line-height: 1; }
.mstat-k {
  font-size: 9px; font-weight: 600; color: var(--ink3);
  text-transform: uppercase; letter-spacing: 0.6px; text-align: center;
}
.modal-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.modal-row:last-child { border-bottom: none; }
.modal-k { font-size: 13px; color: var(--ink2); }
.modal-v { font-family: var(--mono); font-size: 13px; font-weight: 500; }

/* Distribution chart in stats */
.modal-dist {
  padding: 16px 20px 20px;
}
.modal-dist-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--ink3); margin-bottom: 10px;
}
.dist-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  font-size: 11px; font-family: var(--mono); color: var(--ink2);
}
.dist-label { width: 16px; text-align: right; flex-shrink: 0; }
.dist-bar-wrap { flex: 1; height: 18px; background: var(--off); border-radius: 3px; overflow: hidden; }
.dist-bar {
  height: 100%; background: var(--ink);
  border-radius: 3px; min-width: 2px;
  transition: width 0.5s var(--ease-out-expo);
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 5px;
  font-size: 9px; font-weight: 600; color: #fff;
}
.dist-bar.highlight { background: var(--accent); }

.wizard-modal {
  max-width: 356px;
}
.wizard-header {
  padding-bottom: 10px;
}
.wizard-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  touch-action: pan-x;
}
.wizard-track::-webkit-scrollbar { display: none; }
.wizard-pane {
  min-width: 100%;
  scroll-snap-align: start;
  padding: 14px 18px 8px;
}
.wizard-visual {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
}
.wizard-mini-grid {
  display: grid;
  gap: 10px;
  width: 100%;
  aspect-ratio: 1 / 1;
}
.wizard-mini-grid-3 { grid-template-columns: repeat(3, 1fr); }
.wizard-mini-grid-4 { grid-template-columns: repeat(4, 1fr); }
.wizard-mini-grid-5 { grid-template-columns: repeat(5, 1fr); }
.wizard-cell {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 14px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
}
.wizard-cell.on {
  background: var(--flash-bg);
  border-color: var(--flash-bd);
}
.wizard-cell.sel {
  background: var(--sel-bg);
  border-color: var(--sel-bd);
}
.wizard-cell.good {
  background: var(--good-bg);
  border-color: var(--good-bd);
}
.wizard-cell.near {
  background: var(--near-bg);
  border-color: var(--near-bd);
}
.wizard-cell.miss {
  background: var(--miss-bg);
  border-color: var(--miss-bd);
  border-style: dashed;
}
.wizard-pane h3 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.35px;
  margin-bottom: 8px;
}
.wizard-pane p {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink2);
  min-height: 68px;
}
.wizard-footer {
  padding: 8px 18px 18px;
}
.wizard-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.wizard-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border2);
}
.wizard-dot.active {
  background: var(--ink);
}
.wizard-actions {
  display: flex;
  gap: 12px;
}
.wizard-skip,
.wizard-actions .how-play-btn {
  flex: 1;
  min-height: 56px;
  padding: 0 16px;
  border-radius: var(--r);
  font-size: 16px;
  line-height: 1.15;
  font-weight: 700;
  text-align: center;
}
.wizard-skip {
  background: var(--off);
  color: var(--ink2);
}
.wizard-actions .how-play-btn {
  background: var(--ink);
  color: #fff;
  justify-content: center;
  white-space: normal;
}
.wizard-actions .how-play-btn:hover { opacity: 0.92; }
.wizard-actions .how-play-btn:active { transform: scale(0.99); }

/* ═══════════════════════════════════════════════════════
   HAMBURGER MENU
   ═══════════════════════════════════════════════════════ */
.menu-backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10,10,10,0.38);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end;
  animation: fadeIn 0.15s ease both;
}
.menu-sheet {
  width: 100%; max-width: 420px; margin: 0 auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 0 0 calc(env(safe-area-inset-bottom, 0px) + 18px);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.12);
  animation: sheetUp 0.26s var(--ease-out-expo) both;
}
.menu-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border2); margin: 12px auto 8px;
}
.menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 15px 24px;
  font-size: 15px; font-weight: 500; color: var(--ink);
  transition: background 0.12s; text-align: left;
}
.menu-item:hover { background: var(--off); }
.menu-item:active { background: var(--border); }
.menu-item svg { flex-shrink: 0; color: var(--ink3); }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }
.menu-item-danger { color: #dc2626; }
.menu-item-danger svg { color: #dc2626; }


/* ═══════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-icon { color: var(--ink); }
.brand-name {
  font-size: 20px; font-weight: 800; letter-spacing: -0.7px;
  color: var(--ink); user-select: none;
}
.topnav { display: flex; align-items: center; gap: 6px; }
.nav-icon-btn {
  width: 38px; height: 38px; border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink2); transition: background 0.12s, color 0.12s;
}
.nav-icon-btn:hover { background: var(--off); color: var(--ink); }


/* ═══════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════ */
.main {
  flex: 1; display: flex; justify-content: center;
  padding: 24px 16px 60px;
}
.card { width: min(440px, 100%); }


/* ═══════════════════════════════════════════════════════
   WELCOME — SHARED
   ═══════════════════════════════════════════════════════ */
.welcome { padding: 0; }
.welcome-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.welcome-note { font-size: 13px; line-height: 1.55; color: var(--ink3); margin-bottom: 20px; }
.home-utility-stack { display: flex; flex-direction: column; gap: 12px; margin: 6px 0 14px; }


/* ═══════════════════════════════════════════════════════
   WELCOME — NEW USER
   ═══════════════════════════════════════════════════════ */
.welcome-demo {
  margin-bottom: 32px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
}
.demo-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; width: 110px; }
.demo-cell {
  aspect-ratio: 1; border-radius: 6px; border: 2px solid var(--border);
  background: var(--surface);
  transition: background 0.25s, border-color 0.25s, transform 0.15s;
}
.demo-cell.flash { background: var(--flash-bg); border-color: var(--flash-bd); transform: scale(1.06); }
.demo-cell.sel   { background: var(--sel-bg);   border-color: var(--sel-bd); transform: scale(1.04); }
.demo-cell.good  { background: var(--good-bg);  border-color: var(--good-bd); }
.demo-cell.near  { background: var(--near-bg);  border-color: var(--near-bd); }
.demo-cell.miss  { background: var(--miss-bg);  border-color: var(--miss-bd); border-style: dashed; }
.demo-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink3);
}
.welcome-intro {
  font-size: 28px; font-weight: 800;
  line-height: 1.22; letter-spacing: -0.8px;
  color: var(--ink); margin-bottom: 10px;
}
.welcome-sub {
  font-size: 15px; color: var(--ink3); margin-bottom: 36px;
  line-height: 1.55;
}
.welcome-how {
  font-size: 13px; font-weight: 500; color: var(--ink3);
  text-decoration: underline; text-underline-offset: 3px;
  transition: color 0.12s;
}
.welcome-how:hover { color: var(--ink2); }


/* ═══════════════════════════════════════════════════════
   WELCOME — RETURNING USER
   ═══════════════════════════════════════════════════════ */
.returning-score-block { margin-bottom: 28px; }
.returning-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink3); margin-bottom: 6px;
}
.returning-score {
  font-size: 68px; font-weight: 800; letter-spacing: -4px;
  line-height: 1; color: var(--ink); margin-bottom: 8px;
}
.returning-meta { font-size: 13px; color: var(--ink3); font-family: var(--mono); }
.returning-stats {
  display: grid; grid-template-columns: repeat(3,1fr);
  border: 1px solid var(--border); border-radius: var(--r);
  overflow: hidden; margin-bottom: 28px;
  background: var(--surface);
}
.ret-stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 8px; gap: 5px; border-right: 1px solid var(--border);
}
.ret-stat:last-child { border-right: none; }
.ret-v {
  font-size: 24px; font-weight: 800; letter-spacing: -1px;
  line-height: 1; color: var(--ink); font-family: var(--mono);
}
.ret-k {
  font-size: 9px; font-weight: 700; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--ink3);
}
.returning-nudge {
  font-size: 15px; font-weight: 600; color: var(--ink);
  margin-bottom: 28px; line-height: 1.45;
}


/* ═══════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════ */
.btn {
  display: flex; align-items: center; justify-content: center;
  height: 52px; border-radius: var(--r);
  font-size: 15px; font-weight: 700; letter-spacing: -0.1px;
  transition: opacity 0.12s, background 0.12s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.24; cursor: not-allowed; }
.btn-primary {
  background: var(--ink); color: #fff; border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-secondary {
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--border2); font-size: 14px;
}
.btn-secondary:hover:not(:disabled) { background: var(--off); }
.btn-practice {
  background: #ecfdf5; color: #166534; border: 1.5px solid #86efac;
}
.btn-practice:hover:not(:disabled) { background: #dcfce7; }
.btn-install {
  background: #eef2ff; color: #3730a3; border: 1.5px solid #c7d2fe;
}
.btn-install:hover:not(:disabled) { background: #e0e7ff; }
.btn-install-compact { height: 44px; padding: 0 14px; flex-shrink: 0; }


/* ═══════════════════════════════════════════════════════
   GAME UI
   ═══════════════════════════════════════════════════════ */
.game-ui { display: flex; flex-direction: column; }

.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 30px; margin-bottom: 10px;
}
.status { font-size: 14px; line-height: 1.5; color: var(--ink2); flex: 1; }
.status b { color: var(--ink); font-weight: 700; }
.status-lives {
  font-family: var(--mono); font-size: 16px; color: var(--ink);
  flex-shrink: 0; letter-spacing: 2px;
  transition: transform 0.2s var(--ease-spring);
}
.status-lives.life-lost {
  animation: lifePulse 0.4s ease;
}
@keyframes lifePulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.2); color: #dc2626; }
  100% { transform: scale(1); }
}

.game-nav-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 10px; }
.game-nav-btn {
  height: 42px; border-radius: var(--r);
  font-size: 13px; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--border2);
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}
.game-nav-btn:hover { background: var(--off); border-color: var(--ink4); }
.game-nav-btn:active { transform: scale(0.97); }
.game-nav-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.game-nav-ghost { color: var(--ink3); border-color: var(--border); font-weight: 500; }
.game-nav-ghost:hover { color: var(--ink); background: var(--off); }
.game-nav-btn.played-today {
  color: var(--ink4); border-color: var(--border);
  cursor: default; font-weight: 500;
}
.game-nav-btn.played-today:hover { background: var(--surface); border-color: var(--border); }
.game-nav-practice { background: #ecfdf5; border-color: #86efac; color: #166534; }
.game-nav-practice:hover { background: #dcfce7; border-color: #4ade80; }


/* ═══════════════════════════════════════════════════════
   GRID
   ═══════════════════════════════════════════════════════ */
.grid-wrap {
  position: relative;
  background: var(--off); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 10px;
  touch-action: none; -webkit-user-select: none; user-select: none;
  overflow: hidden;
}
.grid {
  display: grid; gap: 6px;
  touch-action: none; user-select: none;
  /* GPU layer for the whole grid — prevents per-cell layer promotion jank */
  transform: translateZ(0);
}
.cell {
  aspect-ratio: 1; border-radius: 6px;
  background: var(--surface); border: 1.5px solid var(--border);
  cursor: pointer; touch-action: none;
  /* Only GPU-composited props — no layout thrash */
  will-change: transform, opacity;
  transform: translateZ(0);
  /* Instant color swap on tap, only ease out the release */
  transition: transform 0.08s ease-out;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
/* No :active scale — it adds perceived delay on fast swiping */

.cell.flash {
  background: var(--flash-bg); border-color: var(--flash-bd);
  animation: cellFlashIn 0.12s ease-out;
}
.cell.sel {
  background: var(--sel-bg); border-color: var(--sel-bd);
  transform: scale(0.92);
  box-shadow: inset 0 0 0 1px var(--sel-bd);
}
.cell.good {
  background: var(--good-bg); border-color: var(--good-bd);
  animation: cellRevealGood 0.22s var(--ease-spring);
}
.cell.near {
  background: var(--near-bg); border-color: var(--near-bd);
  animation: cellRevealNear 0.2s ease-out;
}
.cell.bad {
  background: var(--bad-bg); border-color: var(--bad-bd);
  animation: cellRevealBad 0.28s ease;
}
.cell.miss {
  background: var(--miss-bg); border-color: var(--miss-bd);
  border-style: dashed;
  animation: cellRevealMiss 0.22s ease-out;
}
.cell.locked { opacity: 0.22; cursor: not-allowed; }

@keyframes cellFlashIn    { 0% { transform: scale(0.85); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes cellRevealGood { 0% { transform: scale(0.88); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes cellRevealNear { 0% { transform: scale(0.92); opacity: 0.6; } 100% { transform: scale(1); opacity: 1; } }
@keyframes cellRevealBad  { 0%,18% { transform: translateX(-3px); } 36% { transform: translateX(3px); } 54% { transform: translateX(-2px); } 72% { transform: translateX(2px); } 100% { transform: translateX(0); } }
@keyframes cellRevealMiss { 0% { opacity: 0; transform: scale(0.88); } 100% { opacity: 1; transform: scale(1); } }


/* ═══════════════════════════════════════════════════════
   OVERLAY (WATCH / countdown / grid milestone)
   ═══════════════════════════════════════════════════════ */
.overlay {
  position: absolute; inset: 0; border-radius: var(--r2);
  display: flex; align-items: center; justify-content: center;
  background: rgba(250,250,249,0.92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.overlay-text {
  font-family: var(--mono); font-size: 18px; font-weight: 500;
  letter-spacing: 6px; color: var(--ink); text-transform: uppercase;
}
.overlay-text.countdown-num {
  font-family: var(--font);
  font-size: 72px; font-weight: 800; letter-spacing: -3px;
  animation: countPop 0.32s var(--ease-spring);
}
.overlay-text.grid-milestone {
  font-family: var(--font);
  font-size: 56px; font-weight: 800; letter-spacing: -2px;
  animation: milestonePop 0.4s var(--ease-spring);
}
.overlay-text.overlay-perfect {
  font-family: var(--font);
  font-size: 20px; font-weight: 800; letter-spacing: 2px;
  color: var(--good-bd);
  animation: perfectPop 0.4s var(--ease-spring);
}

@keyframes countPop     { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes milestonePop { from { transform: scale(0.35); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes perfectPop   { from { transform: scale(0.6) translateY(4px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }


/* ═══════════════════════════════════════════════════════
   TIMER
   ═══════════════════════════════════════════════════════ */
.timer-wrap {
  height: 3px; background: var(--border);
  margin-top: 8px; overflow: hidden; border-radius: 2px;
}
.timer-bar {
  height: 100%; width: 100%; background: var(--timer);
  transform-origin: left; transform: scaleX(0);
  transition: background 0.2s; border-radius: 2px;
}
.timer-bar.warn   { background: var(--timer-warn); }
.timer-bar.danger { background: var(--timer-hot); }

@keyframes wrongPulse { 0%,100% { opacity: 1; } 30% { opacity: 0.15; } 60% { opacity: 0.7; } }
.timer-bar.wrong { background: var(--timer-hot); animation: wrongPulse 0.5s ease; }


/* ═══════════════════════════════════════════════════════
   WOBBLE — idle shake
   ═══════════════════════════════════════════════════════ */
@keyframes wobble {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-7px); }
  30%     { transform: translateX(7px); }
  45%     { transform: translateX(-5px); }
  60%     { transform: translateX(5px); }
  75%     { transform: translateX(-2px); }
}
.grid-wrap.wobble { animation: wobble 0.45s cubic-bezier(0.36,0.07,0.19,0.97) both; }


/* ═══════════════════════════════════════════════════════
   BOTTOM DRAWER
   ═══════════════════════════════════════════════════════ */
.bottom-drawer { margin-top: 10px; }
.drawer-summary {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 500; color: var(--ink2);
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); user-select: none;
  transition: background 0.12s;
}
.drawer-summary::-webkit-details-marker { display: none; }
.drawer-summary:hover { background: var(--off); }
.bottom-drawer[open] .drawer-summary {
  border-radius: 8px 8px 0 0; background: var(--off);
}
.drawer-chevron { transition: transform 0.25s var(--ease-out-expo); flex-shrink: 0; color: var(--ink3); }
.bottom-drawer[open] .drawer-chevron { transform: rotate(180deg); }
.drawer-body {
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 8px 8px; padding: 14px 16px 18px; background: var(--off);
}
.drawer-hint { font-size: 12px; color: var(--ink3); line-height: 1.65; }


/* ═══════════════════════════════════════════════════════
   RESULTS
   ═══════════════════════════════════════════════════════ */
.results {
  margin-top: 16px; border-top: 1px solid var(--border); padding-top: 4px;
  animation: resultsIn 0.4s var(--ease-out-expo) both;
}
@keyframes resultsIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.results-header {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 18px 0 16px;
  scroll-margin-top: calc(env(safe-area-inset-top, 0px) + 72px);
}
.results-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--ink3); margin-bottom: 6px;
}
.results-score {
  font-size: 60px; font-weight: 800; letter-spacing: -3.5px; line-height: 1;
}
.results-meta {
  font-family: var(--mono); font-size: 11px;
  color: var(--ink3); text-align: left; line-height: 1.6;
}

.results-body { display: flex; flex-direction: column; }
.rstat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.rstat-k { font-size: 13px; color: var(--ink2); }
.rstat-v { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.rstat-v.mono { font-size: 15px; letter-spacing: 1.2px; }

.share-block { padding: 16px 0 4px; }
.share-lead { font-size: 13px; color: var(--ink2); line-height: 1.5; margin-bottom: 10px; }
.share-preview {
  display: block; white-space: pre-wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--ink);
}
.share-btn {
  width: 100%; height: 52px;
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%); color: #fff;
  font-family: var(--font); font-size: 15px; font-weight: 700;
  border-radius: var(--r);
  transition: opacity 0.12s, transform 0.1s, background 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.share-btn:hover { opacity: 0.88; }
.share-btn:active { transform: scale(0.98); }
.share-btn.copied { background: #16a34a; }

.home-share-btn {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
}
.install-card {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
}
.install-card-title {
  font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 4px;
}
.install-card-copy {
  font-size: 12px; line-height: 1.5; color: var(--ink3);
}
.install-modal-body {
  padding: 18px 20px 20px;
}
.install-modal-copy {
  font-size: 15px; line-height: 1.6; color: var(--ink2); margin-bottom: 16px;
}
#installBackdrop .install-modal-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
#installDismissBtn {
  min-width: 160px;
  padding: 0 24px;
  align-self: flex-end;
}



/* ═══════════════════════════════════════════════════════
   SHARED KEYFRAMES
   ═══════════════════════════════════════════════════════ */
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes popIn   { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }


/* ═══════════════════════════════════════════════════════
   SCORE POP (floating +pts)
   ═══════════════════════════════════════════════════════ */
.score-pop {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font); font-size: 22px; font-weight: 800;
  color: var(--good-bd); pointer-events: none; z-index: 20;
  animation: scorePop 0.8s var(--ease-out-expo) forwards;
}
@keyframes scorePop {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.6); }
  30%  { opacity: 1; transform: translate(-50%, -70%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.9); }
}


/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .modal-stats                 { grid-template-columns: repeat(2,1fr); }
  .results-score               { font-size: 48px; }
  .welcome-intro               { font-size: 24px; }
  .install-card                { align-items: flex-start; flex-direction: column; }
  .btn-install-compact         { width: 100%; }
  .share-preview               { font-size: 11px; }
  .returning-score             { font-size: 56px; }
  .overlay-text.grid-milestone { font-size: 44px; }
  .overlay-text.countdown-num  { font-size: 56px; }
}

/* Larger screens: gentle max-width glow */
@media (min-width: 500px) {
  .grid-wrap {
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* Daily memory board — sticky return mechanic */
.daily-board-wrap{margin-top:14px}
#dailyBoardWelcome{margin-bottom:10px}
.memory-board-card{border:1px solid var(--line, #e6e6e6);border-radius:18px;padding:12px 14px;background:#fff}
.memory-board-head{display:flex;justify-content:space-between;gap:10px;align-items:center;margin-bottom:10px;flex-wrap:wrap}
.memory-board-title{font-size:13px;font-weight:700;letter-spacing:.02em;text-transform:uppercase;color:#111}
.memory-board-copy{font-size:13px;color:#6e6e73}
.memory-board-strip{display:grid;grid-template-columns:repeat(7,1fr);gap:8px}
.memory-day{display:flex;flex-direction:column;align-items:center;gap:5px}
.memory-dot{width:18px;height:18px;border-radius:999px;background:#f0f0f2;border:1px solid #d9d9dd;display:block}
.memory-label{font-size:11px;color:#8b8b90;font-weight:700}
.memory-day.bronze .memory-dot{background:#f1c48e;border-color:#d89f59}
.memory-day.silver .memory-dot{background:#d8dce4;border-color:#aeb6c2}
.memory-day.gold .memory-dot{background:#f6dd69;border-color:#d8b43b}
.memory-day.today .memory-dot{box-shadow:0 0 0 3px rgba(17,17,17,.08)}
#dailyBoardResults .memory-board-card{margin-top:8px}
@media (max-width: 480px){
  .memory-board-copy{width:100%}
}
