/* ==========================================================================
   Oddilo 06 — Visual Memory Test (Ability Series 02)
   Playful Precision Lab Aesthetic with Tactile Mechanical Keycap Grid
   ========================================================================== */

:root {
  --bg-paper: #F7F5F0;
  --bg-surface: #FFFFFF;
  --bg-subtle: #EFECE3;
  --ink: #16161A;
  --ink-muted: #5F5E6C;
  --border-soft: #E2DDD0;
  --tile-flash: #2D5BFF;
  --tile-hit: #00B87C;
  --tile-miss: #FF3B30;
  --tile-missed: #FFE066;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-tactile: 0 4px 0 #16161A;
  --shadow-tactile-sm: 0 2px 0 #16161A;
  --font-display: 'Space Grotesk', 'Inter', system-ui, -apple-system, sans-serif;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-paper);
  background-image: radial-gradient(rgba(22, 22, 26, 0.065) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------- Topbar ---------- */
.topbar {
  width: 100%;
  border-bottom: 1.5px solid var(--border-soft);
  background: rgba(247, 245, 240, 0.92);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
}

.topbar-inner {
  max-width: 780px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

.brand-btn {
  display: inline-flex; align-items: center; gap: 9px;
  background: transparent; border: none; padding: 4px 6px 4px 2px;
  border-radius: 10px; cursor: pointer; color: var(--ink);
}

.brand-wordmark {
  font-family: var(--font-display); font-weight: 700; font-size: 1.18rem;
  letter-spacing: -0.03em; line-height: 1;
}

.brand-cat-tag {
  font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px;
  background: #E6F8F2; color: #007A57; border: 1px solid #00A878;
}

.topbar-pb-pill {
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
  background: var(--bg-surface); border: 1.5px solid var(--border-soft);
  color: var(--ink); white-space: nowrap;
}

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1.5px solid var(--border-soft); background: var(--bg-surface);
  color: var(--ink); display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color 0.14s ease, transform 0.12s ease;
}
.icon-btn:hover { border-color: var(--ink); transform: translateY(-1px); }

/* ---------- Main App Shell ---------- */
.app-shell {
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 16px 16px 40px; flex: 1;
  display: flex; flex-direction: column; gap: 16px;
}

/* ---------- HUD Telemetry Bar ---------- */
.hud-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
  background: var(--bg-surface); border: 1.5px solid var(--ink);
  border-radius: var(--radius-md); padding: 10px 14px;
  box-shadow: var(--shadow-tactile-sm);
}

.hud-group { display: flex; align-items: center; gap: 10px; }

.hud-pill {
  font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700;
  padding: 4px 10px; border-radius: 8px;
  background: var(--bg-subtle); color: var(--ink);
}

.hud-status {
  font-family: var(--font-display); font-weight: 700; font-size: 0.92rem;
  padding: 4px 11px; border-radius: 999px;
  border: 1.5px solid var(--ink); background: var(--bg-paper);
  transition: background 0.12s ease, color 0.12s ease;
}

.hud-status.memorize { background: var(--tile-flash); color: #FFFFFF; }
.hud-status.recall   { background: var(--ink); color: #FFFFFF; }
.hud-status.clear    { background: var(--tile-hit); color: #FFFFFF; }
.hud-status.wrong    { background: var(--tile-miss); color: #FFFFFF; }

.lives-row {
  display: inline-flex; align-items: center; gap: 5px;
}

.heart-icon {
  width: 20px; height: 20px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.heart-icon.lost { opacity: 0.2; transform: scale(0.82); }

/* ---------- Memorize Countdown Bar ---------- */
.timer-bar-wrap {
  height: 6px; width: 100%; background: var(--bg-subtle);
  border-radius: 999px; overflow: hidden; border: 1px solid var(--border-soft);
}

.timer-bar-fill {
  height: 100%; width: 0%; background: var(--tile-flash);
  transform-origin: left center;
}

/* ---------- Main Board Card ---------- */
.board-card {
  position: relative;
  background: var(--bg-surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 7px 0 #16161A;
  padding: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: clamp(340px, 54dvh, 480px);
}

/* Idle Welcome Overlay inside Board */
.start-panel {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 380px; padding: 16px 8px;
}

.start-icon-grid {
  display: grid; grid-template-columns: repeat(3, 20px); gap: 5px;
  margin-bottom: 4px;
}
.start-icon-cell {
  width: 20px; height: 20px; border-radius: 5px;
  border: 1.8px solid var(--ink); background: var(--bg-paper);
}
.start-icon-cell.lit { background: var(--tile-flash); }

.start-kicker {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted);
}

.start-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.9rem, 5.5vw, 2.55rem);
  letter-spacing: -0.035em; line-height: 1.04; margin: 0;
}

.start-sub {
  margin: 0; font-size: 0.96rem; color: var(--ink-muted); line-height: 1.45;
}

/* The Interactive Tactile Tile Grid */
.tile-grid {
  width: min(100%, var(--board-size, 440px));
  flex: none;
  grid-auto-rows: minmax(0, 1fr);
  aspect-ratio: 1 / 1;
  display: grid;
  gap: 10px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.tile-grid.grid-6 { gap: 8px; }
.tile-grid.grid-7 { gap: 6px; }

.tile {
  min-width: 0;
  min-height: 0;
  position: relative;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--bg-paper);
  box-shadow: 0 3px 0 #16161A;
  cursor: pointer;
  padding: 0;
  outline: none;
  display: flex; align-items: center; justify-content: center;
  /* Zero transition on background so memorize flash starts & ends at exact ms! */
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.tile-grid.grid-6 .tile { border-radius: 9px; box-shadow: 0 2.5px 0 #16161A; }
.tile-grid.grid-7 .tile { border-radius: 8px; box-shadow: 0 2px 0 #16161A; border-width: 1.8px; }

.tile:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #16161A;
}

.tile:disabled { cursor: default; }
.tile:focus-visible { outline: 3px solid var(--tile-flash); outline-offset: 3px; }

/* Tile States */
.tile.lit {
  background: var(--tile-flash);
  transform: translateY(-1px);
}
.tile.lit::after {
  content: '';
  width: 26%; height: 26%; border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
}

.tile.hit {
  background: var(--tile-hit);
  transform: translateY(1px);
  box-shadow: 0 1.5px 0 #16161A;
}
.tile.hit::after {
  content: '✓';
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(0.9rem, 2.8vw, 1.35rem); color: #FFFFFF;
}

.tile.wrong {
  background: var(--tile-miss);
  transform: translateY(1px);
  box-shadow: 0 1.5px 0 #16161A;
}
.tile.wrong::after {
  content: '×';
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.1rem, 3.2vw, 1.6rem); color: #FFFFFF;
}

.tile.missed {
  background: var(--tile-missed);
  border-style: dashed;
}

.board-card.shake-it { animation: shake 0.3s ease; }

/* Pause / Interruption Overlay */
.pause-overlay {
  position: absolute; inset: 0;
  background: rgba(247, 245, 240, 0.96);
  border-radius: calc(var(--radius-lg) - 2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center; z-index: 10;
}

.pause-overlay h3 {
  font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; margin: 0;
}
.pause-overlay p { margin: 0 0 6px; color: var(--ink-muted); font-size: 0.92rem; }

/* Board Footer Hint */
.board-footer-hint {
  margin-top: 12px;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-muted);
  min-height: 18px; text-align: center;
}

/* ---------- Summary Result Card ---------- */
.summary-card {
  background: var(--bg-surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 0 7px 0 #16161A;
  padding: 24px 22px;
  display: flex; flex-direction: column; gap: 18px;
  animation: popIn 0.34s cubic-bezier(0.22, 1.25, 0.36, 1) forwards;
}

.summary-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; border-bottom: 1.5px dashed var(--border-soft);
  padding-bottom: 16px; flex-wrap: wrap;
}

.summary-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }

.tier-badge {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.05em; padding: 4px 10px; border-radius: 999px;
  border: 1.5px solid var(--ink);
}

.pb-badge {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: #FFE066; color: var(--ink); border: 1.5px solid var(--ink);
}

.summary-hero-num {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.3rem, 6.5vw, 3.1rem);
  letter-spacing: -0.04em; line-height: 1;
  font-variant-numeric: tabular-nums; margin: 0 0 6px;
}
.summary-hero-num span { font-size: 0.44em; color: var(--ink-muted); font-weight: 600; margin-left: 5px; }

.summary-blurb { margin: 0; font-size: 0.92rem; color: var(--ink-muted); line-height: 1.45; }

.summary-body-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: center;
}

.best-pattern-box {
  background: var(--bg-paper); border: 1.5px solid var(--border-soft);
  border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

.best-pattern-lbl {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; color: var(--ink-muted);
}

.mini-pattern-grid {
  width: 148px; aspect-ratio: 1 / 1;
  display: grid; gap: 4px;
}
.mini-cell {
  border-radius: 4px; border: 1.4px solid var(--ink); background: #FFFFFF;
}
.mini-cell.on { background: var(--tile-flash); }

.summary-stats-col { display: flex; flex-direction: column; gap: 10px; }

.stat-row {
  background: var(--bg-paper); border: 1.5px solid var(--border-soft);
  border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.stat-row-lbl {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; color: var(--ink-muted);
}
.stat-row-val {
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.summary-actions { display: grid; grid-template-columns: 1.25fr 1fr; gap: 10px; }

/* ---------- Buttons ---------- */
.btn-primary {
  font-family: var(--font-display); font-weight: 700; font-size: 1.02rem;
  height: 54px; padding: 0 26px; border-radius: var(--radius-md);
  border: 2px solid var(--ink); background: var(--ink); color: #FFFFFF;
  box-shadow: var(--shadow-tactile); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 5px 0 #16161A; background: var(--tile-flash); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #16161A; }

.btn-secondary {
  height: 54px; padding: 0 18px; border-radius: var(--radius-md);
  border: 2px solid var(--ink); background: var(--bg-surface); color: var(--ink);
  font-family: var(--font-display); font-weight: 700; font-size: 0.96rem;
  box-shadow: var(--shadow-tactile-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-secondary:hover { background: var(--bg-subtle); transform: translateY(-1px); }

/* ---------- Concise Below-Fold Info ---------- */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 4px; }
.info-card {
  background: var(--bg-surface); border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-md); padding: 16px 18px;
}
.info-card h2 { font-family: var(--font-display); font-weight: 700; font-size: 0.98rem; margin: 0 0 6px; }
.info-card p { margin: 0; font-size: 0.86rem; line-height: 1.5; color: var(--ink-muted); }

/* ---------- Confetti, Modal & Toast ---------- */
.confetti-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22, 22, 26, 0.45);
  backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 60;
}
.modal-card {
  width: 100%; max-width: 420px; background: var(--bg-surface);
  border: 2px solid var(--ink); border-radius: var(--radius-lg);
  box-shadow: 0 8px 0 #16161A; padding: 20px;
  max-height: calc(100dvh - 32px); overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; margin: 0; }
.lab-list { display: flex; flex-direction: column; gap: 8px; }
.lab-item {
  width: 100%; text-align: left; padding: 11px 13px; border-radius: 12px;
  border: 1.5px solid var(--border-soft); background: var(--bg-paper);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  cursor: pointer; color: var(--ink);
}
.lab-item.live { background: #FFFFFF; border-color: var(--ink); }
.lab-item-name { font-family: var(--font-display); font-weight: 700; font-size: 0.92rem; display: block; }
.lab-item-desc { font-size: 0.76rem; color: var(--ink-muted); }
.lab-pill { font-family: var(--font-mono); font-size: 0.65rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; }
.lab-pill.live { background: #E6F8F2; color: #007A57; border: 1px solid #00A878; }
.lab-pill.launched { background: #EBF0FF; color: #1D4ED8; border: 1px solid #2D5BFF; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #FFFFFF; font-family: var(--font-display); font-weight: 600; font-size: 0.86rem;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 20px rgba(22, 22, 26, 0.25);
  opacity: 0; pointer-events: none; z-index: 80; transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.95) translateY(6px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  78% { transform: translateX(-3px); }
}

@media (max-width: 580px) {
  .topbar-inner { padding: 8px 12px; }
  .brand-cat-tag { display: none; }
  .app-shell { padding: 12px 12px 30px; gap: 12px; }
  .board-card { padding: 14px; min-height: 330px; }
  .tile-grid { gap: 7px; }
  .tile-grid.grid-6 { gap: 6px; }
  .tile-grid.grid-7 { gap: 4.5px; }
  .summary-body-grid { grid-template-columns: 1fr; }
  .summary-actions { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
}

/* Match the roomier desktop scale of Reaction Time while keeping every grid square. */
@media (min-width: 1000px) {
  .app-shell:has(#playSection:not(.hidden)) { max-width: 940px; }
  .topbar-inner { max-width: 1000px; }
  .tile-grid { --board-size: clamp(440px, 60dvh, 620px); }
  .board-card { min-height: clamp(420px, 62dvh, 680px); }
}
