:root {
  --bg: #0b1020;
  --panel: rgba(17, 24, 39, 0.94);
  --panel-soft: #182235;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --line: rgba(255,255,255,0.10);
  --shadow: 0 24px 60px rgba(0,0,0,0.38);
  --cell-size: clamp(42px, 11vw, 72px);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(56,189,248,0.13), transparent 28%),
    radial-gradient(circle at 80% 90%, rgba(168,85,247,0.12), transparent 30%),
    var(--bg);
  min-height: 100vh;
}

button { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-card {
  width: min(920px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 34px);
  position: relative;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 6px;
  color: #7dd3fc;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 7vw, 3.7rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.subtitle {
  color: var(--muted);
  max-width: 600px;
  margin-bottom: 0;
  line-height: 1.55;
}

.stats {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.stat {
  min-width: 84px;
  padding: 10px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
}

.stat span { display: block; color: var(--muted); font-size: 0.75rem; }
.stat strong { display: block; margin-top: 2px; font-size: 1.1rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 24px 0 12px;
}

button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #263248;
  color: var(--text);
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 750;
  transition: transform .14s ease, background .14s ease, opacity .14s ease;
}

button:hover:not(:disabled) { transform: translateY(-1px); background: #31405b; }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, #0ea5e9, #7c3aed); border-color: transparent; }
button.primary:hover:not(:disabled) { background: linear-gradient(135deg, #0284c7, #6d28d9); }

.message {
  color: var(--muted);
  min-height: 24px;
  font-size: .95rem;
}

.board-wrap {
  display: grid;
  place-items: center;
  padding: 18px 0 8px;
}

.board {
  width: calc(var(--cell-size) * 6);
  height: calc(var(--cell-size) * 6);
  display: grid;
  grid-template-columns: repeat(6, var(--cell-size));
  grid-template-rows: repeat(6, var(--cell-size));
  border: 2px solid rgba(255,255,255,.18);
  border-radius: 18px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #0d1526;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.03), 0 12px 28px rgba(0,0,0,.25);
}

.board.is-locked { filter: saturate(.55); opacity: .72; }

.cell {
  position: relative;
  border-right: 1px solid rgba(255,255,255,.08);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: grid;
  place-items: center;
}

.cell::before {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0;
}

/* Flow-style paths: a narrow line runs through the center of each cell.
   The colored square itself stays dark instead of filling with the path color. */
.cell.path::before {
  opacity: 1;
  width: 24%;
  height: 24%;
  border-radius: 50%;
  background: var(--path-color);
  z-index: 1;
  box-shadow: 0 0 12px color-mix(in srgb, var(--path-color) 42%, transparent);
}

/* Directional half-segments are drawn as background layers in JavaScript.
   Each segment is only 24% of a cell thick, producing a clean pipe/line look. */
.cell.path {
  background-repeat: no-repeat;
}

.dot {
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--dot-color);
  box-shadow: 0 0 0 5px rgba(255,255,255,.055), 0 0 22px color-mix(in srgb, var(--dot-color) 62%, transparent);
  position: relative;
  z-index: 2;
}

.help-panel,
.win-panel {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 18, .82);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 10;
  backdrop-filter: blur(5px);
}

.help-panel[hidden], .win-panel[hidden] { display: none; }

.help-content,
.win-card {
  width: min(470px, 100%);
  border-radius: 20px;
  padding: 24px;
  background: #172033;
  border: 1px solid var(--line);
  box-shadow: 0 22px 55px rgba(0,0,0,.45);
}

.help-content p,
.win-card p { color: var(--muted); line-height: 1.6; }
.win-card h2 { font-size: 1.7rem; margin-bottom: 8px; }
.score-note { font-size: .9rem; }

.leaderboard-section {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.leaderboard-section h2 { font-size: 1rem; margin-bottom: 10px; }

@media (max-width: 700px) {
  .app-shell { padding: 10px; }
  .game-card { border-radius: 18px; padding: 16px; }
  .topbar { flex-direction: column; gap: 16px; }
  .stats { width: 100%; }
  .stat { flex: 1; }
  :root { --cell-size: min(14.8vw, 62px); }
}

@media (max-width: 380px) {
  .controls button { flex: 1 1 100%; }
}
