* {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --card: #111827;
  --card-soft: #1f2937;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --danger: #ef4444;
  --cell: #1e293b;
  --cell-hover: #334155;
  --path: #075985;
  --path-head: #0369a1;
  --fixed: #f8fafc;
  --fixed-text: #0f172a;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(14, 165, 233, 0.16), transparent 36rem),
    var(--bg);
  color: var(--text);
}

button { font: inherit; }

.game-shell {
  width: min(100% - 2rem, 760px);
  margin: 0 auto;
  padding: 2rem 0;
}

.game-card {
  background: rgba(17, 24, 39, 0.96);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(1rem, 3vw, 2rem);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1;
}

.subtitle {
  margin: 0.75rem 0 0;
  color: var(--muted);
  max-width: 34rem;
}

.game-stats,
.hud-grid {
  display: grid;
  gap: 0.75rem;
}

.game-stats {
  grid-template-columns: repeat(2, minmax(88px, 1fr));
}

.hud {
  margin: 1rem 0;
  padding: 1rem;
  background: rgba(8, 15, 29, 0.88);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.hud-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  min-width: 0;
  padding: 0.7rem 0.8rem;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 0.25rem;
}

.stat strong {
  display: block;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.score-note {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.instructions {
  margin: 1.5rem 0 1rem;
  padding: 1rem;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: #cbd5e1;
}

.instructions p { margin: 0; line-height: 1.5; }

.status-bar {
  min-height: 2.7rem;
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: #0b1220;
  border: 1px solid var(--border);
  color: #cbd5e1;
}

.status-bar.ready { border-color: rgba(56, 189, 248, 0.55); }
.status-bar.paused { border-color: rgba(245, 158, 11, 0.75); color: #fde68a; }
.status-bar.success { border-color: rgba(34, 197, 94, 0.7); color: #bbf7d0; }
.status-bar.error { border-color: rgba(239, 68, 68, 0.7); color: #fecaca; }

.board {
  --size: 5;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: 6px;
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 8px;
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 18px;
  user-select: none;
  touch-action: none;
}

.cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid #334155;
  border-radius: 10px;
  background: var(--cell);
  color: var(--text);
  cursor: pointer;
  position: relative;
  font-weight: 700;
  font-size: clamp(0.9rem, 4vw, 1.25rem);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.cell:hover:not(:disabled) { background: var(--cell-hover); border-color: #475569; }
.cell:focus-visible,
.button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cell:disabled { cursor: not-allowed; }
.cell.path { background: var(--path); border-color: #0ea5e9; }
.cell.head { background: var(--path-head); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.fixed { background: var(--fixed); color: var(--fixed-text); border-color: #cbd5e1; }
.cell.fixed.path { background: #bae6fd; border-color: #38bdf8; }
.cell.fixed.head { background: #7dd3fc; }
.cell.hinted { box-shadow: inset 0 0 0 2px #f59e0b; border-color: rgba(245, 158, 11, 0.9); }
.cell.wrong { animation: shake 220ms linear; }
.cell-number { position: relative; z-index: 2; }

.cell-order {
  position: absolute;
  right: 5px;
  bottom: 3px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.6rem;
  font-weight: 500;
}

.fixed .cell-order { color: rgba(15, 23, 42, 0.45); }

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.button {
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  font-weight: 800;
  transition: transform 120ms ease, opacity 120ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button.primary { background: var(--accent-strong); color: white; }
.button.secondary { background: var(--card-soft); color: var(--text); border: 1px solid var(--border); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

@media (max-width: 640px) {
  .game-shell { width: min(100% - 1rem, 760px); padding: 0.5rem 0; }
  .game-card { border-radius: 18px; }
  .game-header { flex-direction: column; }
  .game-stats,
  .hud-grid,
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .game-stats,
  .hud-grid,
  .controls { grid-template-columns: 1fr; }
}
