/* ========= Reset ========= */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
select { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ========= Root tokens (default: neon theme) ========= */
:root {
  --fg: #e8f4ff;
  --fg-dim: #9aa4bf;
  --bg-0: #0a0a14;
  --bg-1: #12121f;
  --bg-2: #1a1a2e;
  --panel: rgba(22, 24, 42, 0.7);
  --panel-2: rgba(34, 38, 64, 0.6);
  --border: rgba(120, 140, 200, 0.18);
  --border-strong: rgba(120, 140, 200, 0.35);
  --accent: #00e5ff;
  --accent-2: #ff2ec4;
  --accent-3: #39ff14;
  --danger: #ff3366;
  --warning: #ffb020;

  --n1: #00e5ff;
  --n2: #39ff14;
  --n3: #ff2ec4;
  --n4: #b362ff;
  --n5: #ffb020;
  --n6: #00f5d4;
  --n7: #ff6bcb;
  --n8: #ffffff;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --glow: 0 0 12px var(--accent), 0 0 24px rgba(0, 229, 255, 0.4);

  --font-display: "Orbitron", "JetBrains Mono", ui-monospace, monospace;
  --font-body: "JetBrains Mono", ui-monospace, monospace;

  --cell-size: clamp(22px, 4vmin, 36px);
  --gap: 3px;
}

/* ========= Page ========= */
body {
  font-family: var(--font-body);
  color: var(--fg);
  background:
    radial-gradient(ellipse at 20% -10%, rgba(0, 229, 255, 0.12), transparent 60%),
    radial-gradient(ellipse at 110% 110%, rgba(255, 46, 196, 0.1), transparent 55%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1));
  min-height: 100svh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100svh;
}

/* ========= Header ========= */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
}
.brand h1 {
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.4vw, 1.3rem);
  letter-spacing: 0.28em;
  font-weight: 800;
  color: var(--fg);
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}
.brand .logo { filter: drop-shadow(0 0 6px currentColor); }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.difficulty select {
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.difficulty select:hover,
.difficulty select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.15); outline: none; }
.difficulty select option { background: var(--bg-2); color: var(--fg); }

/* ========= Buttons ========= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.15); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #08091a;
  border-color: transparent;
  font-weight: 800;
  text-shadow: none;
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.4);
}
.btn-primary:hover { box-shadow: 0 0 24px rgba(255, 46, 196, 0.5); }

.btn-ghost svg { opacity: 0.9; }
.btn-ghost.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 14px rgba(0, 229, 255, 0.35); }

/* theme icon swap */
[data-theme="neon"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* ========= Status Bar ========= */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.status-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  padding: 4px 10px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid var(--border);
  min-width: 72px;
  justify-content: center;
}
.stat svg { color: var(--accent); filter: drop-shadow(0 0 4px currentColor); }

/* Tool Buttons (power-ups + hint + undo) */
.tool {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--fg);
  font-weight: 700;
  transition: all 0.15s;
}
.tool svg { color: var(--accent); filter: drop-shadow(0 0 4px currentColor); }
.tool:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.tool:disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.6); }
.tool.active { border-color: var(--accent-2); color: var(--accent-2); box-shadow: 0 0 16px rgba(255, 46, 196, 0.45); }
.tool.active svg { color: var(--accent-2); }
.tool-count {
  font-size: 0.8rem;
  padding: 1px 6px;
  background: var(--bg-0);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* ========= Footer ========= */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
  flex-wrap: wrap;
}
.meta {
  color: var(--fg-dim);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

/* ========= Modal ========= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 20, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow), 0 0 40px rgba(0, 229, 255, 0.12);
  animation: modalIn 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-card h2 {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  font-size: 1.4rem;
  margin-bottom: 12px;
  color: var(--accent);
  text-shadow: 0 0 12px currentColor;
}
.modal-body { color: var(--fg-dim); line-height: 1.5; margin-bottom: 18px; }
.modal-body strong { color: var(--fg); }
.modal-body .highlight { color: var(--accent-3); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ========= Accessibility ========= */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
