:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --cell: min(11vw, 7.5vh, 64px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

header {
  padding: 20px 16px 12px;
  text-align: center;
}

h1 {
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  padding-left: 0.35em;
}

.stats {
  display: flex;
  gap: 22px;
  justify-content: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.modes {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

.mode-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--accent);
  color: #082f49;
  border-color: var(--accent);
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#board-wrap {
  position: relative;
}

#grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-auto-rows: var(--cell);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 4px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.42);
}

.cell.covered .num {
  visibility: hidden;
}

#rects {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.placed {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color);
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.12);
  background: color-mix(in srgb, var(--color) 26%, transparent);
  font-weight: 800;
  font-size: calc(var(--cell) * 0.42);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.sel {
  position: absolute;
  border: 2px dashed rgba(255, 255, 255, 0.65);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.sel.invalid {
  border-color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

#grid.shake {
  animation: shake 0.25s;
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.82);
  border-radius: 4px;
}

#overlay.hidden {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 36px;
  text-align: center;
}

.panel h2 {
  margin-bottom: 8px;
}

.panel p {
  color: var(--muted);
  margin-bottom: 18px;
}

button {
  background: var(--accent);
  color: #082f49;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button:hover {
  filter: brightness(1.1);
}

.controls {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.hint {
  color: var(--muted);
  max-width: 440px;
  text-align: center;
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 14px 16px 24px;
}
