/* Path Finder — Game CMB. Neon Minimal Puzzle theme.
   No external art assets: every visual is CSS (gradients, box-shadow
   glow, radial glows) or inline SVG icons. */

:root {
  --bg-0: #05070f;
  --bg-1: #0a0f1f;
  --panel: #0e1526;
  --panel-2: #121a30;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eaf0ff;
  --text-dim: #8fa0c9;
  --cyan: #4df3ff;
  --cyan-2: #22d6e6;
  --gold: #ffd166;
  --purple: #b083ff;
  --coral: #ff6b81;
  --green: #59ffb0;
  --orb: #f4ffff;
  --wall: #1a2138;
  --wall-edge: rgba(120, 160, 255, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

/* [hidden] must always win over any author display: rule on
   overlays/screens/icon-buttons — see standing-conventions.md #3. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Inter', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(80vw 60vh at 15% -10%, rgba(77, 243, 255, 0.10), transparent 60%),
    radial-gradient(70vw 55vh at 100% 110%, rgba(176, 131, 255, 0.12), transparent 60%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1));
  display: flex;
  flex-direction: column;
  align-items: center;
}

a { color: var(--cyan); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: var(--text);
}
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- App shell ---------- */
.app {
  width: 100%;
  max-width: 720px;
  padding: 12px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
}
.brand-mark {
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
}
.brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.header-icons {
  display: flex;
  gap: 6px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: transform 0.12s ease, background 0.12s ease;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn[aria-pressed="false"] { opacity: 0.5; }

/* ---------- Screens ---------- */
.screen {
  background: linear-gradient(180deg, var(--panel), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 18px;
  box-shadow: var(--shadow-lg);
}

.home-title {
  text-align: center;
  margin: 6px 0 2px;
}
.home-title .h1-game {
  font-size: 2rem;
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  color: var(--text-dim);
  text-align: center;
  margin: 4px 0 18px;
  font-size: 0.95rem;
}

.profile-line {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: -6px 0 18px;
}
.profile-line button.link-btn {
  background: none;
  color: var(--cyan);
  text-decoration: underline;
  font-size: inherit;
  padding: 0 2px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color .12s ease;
}
.mode-card:hover { border-color: rgba(77,243,255,0.4); }
.mode-card:active { transform: scale(0.985); }
.mode-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex: 0 0 auto;
}
.mode-icon.run { background: rgba(77,243,255,0.15); box-shadow: 0 0 18px rgba(77,243,255,0.25) inset; }
.mode-icon.daily { background: rgba(255,209,102,0.15); box-shadow: 0 0 18px rgba(255,209,102,0.25) inset; }
.mode-title { font-weight: 700; font-size: 1rem; }
.mode-sub { color: var(--text-dim); font-size: 0.82rem; margin-top: 2px; }

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 16px;
}
.stat-pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.stat-pill .stat-value { font-weight: 800; font-size: 1.15rem; color: var(--cyan); }
.stat-pill .stat-label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

.home-links {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.text-link-btn {
  background: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}
.text-link-btn:hover { color: var(--cyan); }

/* ---------- HUD ---------- */
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.hud-item {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  text-align: center;
}
.hud-item .hud-value { font-weight: 800; font-size: 1.05rem; }
.hud-item .hud-label { font-size: 0.62rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.hud-item.timer.warn .hud-value { color: var(--coral); animation: pulse 1s infinite; }
.hud-item.streak .hud-value { color: var(--gold); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.run-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.run-topbar .level-badge {
  font-weight: 800;
  color: var(--text-dim);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}
.run-topbar .topbar-actions { display: flex; gap: 6px; }

/* ---------- Board ---------- */
.board-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0 14px;
}
.board {
  position: relative;
  width: min(92vw, 480px);
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), transparent 30%),
    var(--bg-1);
  border-radius: 14px;
  border: 1px solid rgba(120, 160, 255, 0.18);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3) inset, 0 20px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  touch-action: none;
  display: grid;
}

.cell {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.035);
}
.cell.wall {
  background: linear-gradient(160deg, var(--wall), #0c1120);
  box-shadow: inset 0 0 0 1px var(--wall-edge);
}
.cell.start {
  background: radial-gradient(circle at 50% 50%, rgba(89,255,176,0.35), rgba(89,255,176,0.05) 70%);
  box-shadow: inset 0 0 12px rgba(89,255,176,0.4);
}
.cell.exit {
  background: radial-gradient(circle at 50% 50%, rgba(255,209,102,0.35), rgba(176,131,255,0.08) 70%);
  box-shadow: inset 0 0 14px rgba(255,209,102,0.45);
  animation: exit-glow 2.2s ease-in-out infinite;
}
@keyframes exit-glow {
  0%, 100% { box-shadow: inset 0 0 10px rgba(255,209,102,0.35); }
  50% { box-shadow: inset 0 0 22px rgba(255,209,102,0.65), inset 0 0 8px rgba(176,131,255,0.5); }
}
.cell.visited::after {
  content: "";
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: rgba(77, 243, 255, 0.35);
}

.trail-dot {
  position: absolute;
  /* width/height set inline by Board.dropTrail() — see the .player-orb
     comment above for why a CSS percentage here would be wrong. */
  border-radius: 50%;
  background: radial-gradient(circle, rgba(77,243,255,0.85), rgba(77,243,255,0));
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: trail-fade 900ms ease-out forwards;
}
@keyframes trail-fade {
  0% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
}

.player-orb {
  position: absolute;
  /* width/height are set inline per-level by Board.build() (JS) — a
     percentage here would resolve against the whole board (this
     element's containing block), not against one grid cell, since the
     orb sits outside the CSS grid flow as a free-positioned overlay. */
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--orb) 30%, var(--cyan) 75%);
  box-shadow: 0 0 14px rgba(77,243,255,0.9), 0 0 30px rgba(77,243,255,0.55);
  transform: translate(-50%, -50%) scale(1);
  transition: left 120ms cubic-bezier(.34,1.56,.64,1), top 120ms cubic-bezier(.34,1.56,.64,1), transform 130ms ease;
  pointer-events: none;
  z-index: 3;
}
.player-orb.squash { transform: translate(-50%, -50%) scale(0.9); }
.player-orb.pop { transform: translate(-50%, -50%) scale(1.05); }

/* particles for PERFECT PATH celebration */
.particle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
.particle {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.9;
  animation: particle-fly 700ms ease-out forwards;
}
@keyframes particle-fly {
  to { transform: translate(var(--px), var(--py)) scale(0.2); opacity: 0; }
}

.board-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,209,102,0.35), transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}
.board-flash.active { animation: flash-pop 550ms ease-out; }
@keyframes flash-pop {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---------- Controls under board ---------- */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}
.btn {
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(90deg, var(--cyan-2), var(--cyan));
  color: #041018;
  box-shadow: 0 8px 24px rgba(77,243,255,0.28);
}
.btn-gold {
  background: linear-gradient(90deg, #ffb347, var(--gold));
  color: #2a1a00;
  box-shadow: 0 8px 24px rgba(255,209,102,0.3);
}
.btn-block { width: 100%; text-align: center; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay-card {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}
.overlay-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 6px;
  text-align: center;
}
.overlay-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 16px;
}
.overlay-close-x {
  position: absolute;
  top: 14px; right: 14px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}
.result-stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}
.result-stat .rs-value { font-weight: 800; font-size: 1.2rem; }
.result-stat .rs-label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; }
.perfect-badge {
  display: block;
  text-align: center;
  font-weight: 800;
  color: var(--gold);
  margin: 6px 0 12px;
  font-size: 1.05rem;
  text-shadow: 0 0 14px rgba(255,209,102,0.6);
}
.best-line {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 4px 0 14px;
}
.best-line.new-best { color: var(--gold); font-weight: 700; }

.overlay-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.overlay-actions .btn { flex: 1; }

.howto-list {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}
.howto-list li { margin-bottom: 6px; }
.key-hint {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.78rem;
  font-family: monospace;
}

.nickname-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 8px;
}
.field-error {
  color: var(--coral);
  font-size: 0.82rem;
  min-height: 1.2em;
  margin-bottom: 8px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.tab-btn {
  flex: 1;
  padding: 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
}
.tab-btn.active {
  background: linear-gradient(90deg, var(--cyan-2), var(--cyan));
  color: #041018;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow-y: auto;
}
.lb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.lb-row.top1 { border-color: rgba(255,209,102,0.5); }
.lb-row.top1 .lb-rank { color: var(--gold); }
.lb-row.top2 .lb-rank { color: #cfe0ff; }
.lb-row.top3 .lb-rank { color: #e0b088; }
.lb-rank { font-weight: 800; text-align: center; color: var(--text-dim); }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--cyan); }
.lb-empty, .lb-loading { text-align: center; color: var(--text-dim); padding: 20px 0; font-size: 0.9rem; }

/* ---------- Footer / SEO content ---------- */
.ad-slot {
  width: 100%;
  min-height: 90px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.seo-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.65;
}
.seo-section h2 {
  color: var(--text);
  font-size: 1.15rem;
  margin: 0 0 10px;
}
.seo-section h3 {
  color: var(--text);
  font-size: 1rem;
  margin: 16px 0 6px;
}
.seo-section ul { padding-left: 20px; }
.seo-section .faq-item { margin-bottom: 14px; }

.related-games {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.related-games a {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--text-dim);
}
.related-games a:hover { color: var(--cyan); border-color: rgba(77,243,255,0.4); }

.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 10px 0 4px;
}
.site-footer a { color: var(--text-dim); text-decoration: underline; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .player-orb, .cell.exit, .trail-dot, .particle, .hud-item.timer.warn .hud-value {
    animation: none !important;
    transition: none !important;
  }
}

@media (min-width: 640px) {
  .mode-grid { grid-template-columns: 1fr 1fr; }
}
