/* ---------- theme ---------- */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #1e293b;
  --cell: #f1f5f9;
  --cell-line: #cbd5e1;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --path: #6366f1;
  --path-solved: #22c55e;
  --wall: #0f172a;
  --cp-bg: #0f172a;
  --cp-ink: #ffffff;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: radial-gradient(120% 100% at 50% 0%, #1e293b 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- header ---------- */
.topbar {
  text-align: center;
}
.topbar h1 {
  margin: 4px 0 2px;
  font-size: 28px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- tier selector ---------- */
.tiers {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tiers::-webkit-scrollbar {
  display: none;
}
.tier {
  flex: 1 0 auto;
  min-width: 60px;
  border: 1px solid #334155;
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.tier:active {
  transform: scale(0.96);
}
.tier-day {
  font-weight: 700;
  font-size: 13px;
}
.tier-blurb {
  font-size: 10px;
  color: var(--muted);
}
.tier.active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.tier.active .tier-blurb {
  color: rgba(255, 255, 255, 0.85);
}

/* ---------- status bar ---------- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  padding: 0 2px;
}
.spacer {
  flex: 1;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink);
  font-size: 15px;
}
.best {
  font-variant-numeric: tabular-nums;
}

/* ---------- board ---------- */
.board-wrap {
  position: relative;
  width: 100%;
}
.board {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: min(480px, 92vw);
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 6px;
  touch-action: none;
  user-select: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.cell {
  fill: var(--cell);
  stroke: var(--cell-line);
  stroke-width: 0.012;
}
.path {
  stroke: var(--path);
  stroke-width: 0.34;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.92;
  transition: stroke 0.2s ease;
}
.path.solved {
  stroke: var(--path-solved);
}
.head {
  fill: var(--path);
  opacity: 0.95;
}
.wall {
  stroke: var(--wall);
  stroke-width: 0.14;
  stroke-linecap: round;
}
.cp-bg {
  fill: var(--cp-bg);
}
.cp-num {
  fill: var(--cp-ink);
  font-size: 0.42px;
  font-weight: 700;
  font-family: inherit;
}

/* ---------- win banner ---------- */
.banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.banner.show {
  opacity: 1;
  pointer-events: auto;
}
.banner-card {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #334155;
  backdrop-filter: blur(6px);
  border-radius: 16px;
  padding: 22px 26px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  transform: scale(0.9);
  transition: transform 0.2s ease;
}
.banner.show .banner-card {
  transform: scale(1);
}
.banner-title {
  font-size: 26px;
  font-weight: 800;
}
.banner.win .banner-title {
  color: var(--path-solved);
}
.banner-sub {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}
.banner-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.btn {
  flex: 1;
  border: 1px solid #334155;
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 13px 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active {
  transform: scale(0.95);
}
.btn-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

@media (min-width: 600px) {
  .topbar h1 {
    font-size: 34px;
  }
  .btn {
    padding: 12px;
  }
}
