/* Queens - presentation. Light and dark themes, region colours, board + chrome. */

:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #23222b;
  --ink-soft: #5c5a66;
  --ink-muted: #8a8794;
  --line: rgba(35, 34, 43, .16);
  --edge: #1b1a22;
  --accent: #4c4a68;
  --accent-ink: #ffffff;
  --good: #1f7a4d;
  --bad: #c0392b;
  --focus: #3b6fd4;
  --shadow: 0 10px 30px rgba(24, 22, 40, .10);
  --radius: 14px;

  /* region palette - light */
  --r0:  #b3a4ea; --r1:  #f7bd88; --r2:  #9dd894; --r3:  #e9ef8b;
  --r4:  #9bc2f6; --r5:  #f2917d; --r6:  #d8d7d3; --r7:  #96ded4;
  --r8:  #f2b2cd; --r9:  #cfe189; --r10: #c9b3a2; --r11: #f4d689;
  --queen: #1e1d26;
  --cross: #6f6c7a;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16151b;
  --card: #1f1e26;
  --ink: #eeeef2;
  --ink-soft: #b6b4c0;
  --ink-muted: #83818e;
  --line: rgba(238, 238, 242, .14);
  --edge: #f2f1f6;
  --accent: #8f8ad6;
  --accent-ink: #16151b;
  --good: #5ed39a;
  --bad: #f2705c;
  --focus: #7fb2ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);

  --r0:  #4a4279; --r1:  #6c5031; --r2:  #3c5e3a; --r3:  #5f6430;
  --r4:  #34527d; --r5:  #6f3c32; --r6:  #454449; --r7:  #2d5b56;
  --r8:  #673a4e; --r9:  #556330; --r10: #57493c; --r11: #66592f;
  --queen: #f6f5fa;
  --cross: #9a97a6;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Cantarell, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

/* ------------------------------------------------------------------ chrome */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px clamp(14px, 4vw, 28px);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: .04em;
  font-size: 18px;
}

.brand-glyph { width: 20px; height: 20px; fill: var(--accent); }

.timer {
  margin-inline: auto;
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--ink-soft);
}

.timer.running { color: var(--ink); }

.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.icon-btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: clamp(14px, 3vw, 28px);
}

.stage {
  width: min(680px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 28px);
  align-self: flex-start;
}

.puzzle-head { text-align: center; margin-bottom: 6px; }

.puzzle-head h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: .01em; }

.puzzle-sub {
  margin: 0 0 14px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  color: var(--ink-muted);
  font-size: 13.5px;
}

.badge {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--ink-soft);
}

.badge[data-level="easy"]   { background: #1f7a4d22; color: var(--good); }
.badge[data-level="hard"]   { background: #c0392b22; color: var(--bad); }
.badge.ghost { background: transparent; border: 1px solid var(--line); }

/* ------------------------------------------------------------------- board */

.board-shell { position: relative; display: flex; justify-content: center; }

.board-frame {
  padding: 5px;
  background: var(--card);
  border-radius: 8px;
}

.board {
  --edge-w: max(2px, calc(var(--cell) * .07));
  --grid-w: max(1px, calc(var(--cell) * .028));
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-template-rows: repeat(var(--n), var(--cell));
  border: var(--edge-w) solid var(--edge);
  border-radius: 6px;
  touch-action: none;
  user-select: none;
  outline: none;
}

.cell {
  position: relative;
  margin: 0;
  padding: 0;
  appearance: none;
  background: var(--cell-color, transparent);
  border-style: solid;
  border-color: var(--edge);
  border-width: var(--cw-t) var(--cw-r) var(--cw-b) var(--cw-l);
  display: grid;
  place-items: center;
  cursor: pointer;
  font: inherit;
  color: var(--queen);
  transition: filter .12s ease, transform .08s ease;
}

/* interior grid lines are drawn with an inset shadow so region edges stay crisp */
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 var(--grid-w) var(--line);
  pointer-events: none;
}

.cell:hover { filter: brightness(.94); }
html[data-theme="dark"] .cell:hover { filter: brightness(1.22); }

.cell:focus-visible {
  z-index: 3;
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.cell.r0  { --cell-color: var(--r0);  } .cell.r1  { --cell-color: var(--r1);  }
.cell.r2  { --cell-color: var(--r2);  } .cell.r3  { --cell-color: var(--r3);  }
.cell.r4  { --cell-color: var(--r4);  } .cell.r5  { --cell-color: var(--r5);  }
.cell.r6  { --cell-color: var(--r6);  } .cell.r7  { --cell-color: var(--r7);  }
.cell.r8  { --cell-color: var(--r8);  } .cell.r9  { --cell-color: var(--r9);  }
.cell.r10 { --cell-color: var(--r10); } .cell.r11 { --cell-color: var(--r11); }

.cell .queen { width: 74%; height: 74%; fill: var(--queen); display: none; pointer-events: none; }
.cell .cross { display: none; font-size: calc(var(--cell) * .46); color: var(--cross); line-height: 1; pointer-events: none; }

.cell.state-queen .queen { display: block; animation: pop .16s ease-out; }
.cell.state-block .cross { display: block; }

/* cells a placed queen rules out */
.cell.auto::after {
  content: "";
  width: calc(var(--cell) * .13);
  height: calc(var(--cell) * .13);
  border-radius: 50%;
  background: color-mix(in srgb, var(--queen) 34%, transparent);
}

.cell.clash { background: color-mix(in srgb, var(--bad) 55%, var(--cell-color)); }
.cell.clash .queen { fill: #fff; }
html[data-theme="dark"] .cell.clash .queen { fill: #fff; }
.cell.clash { animation: shake .22s ease-in-out; }

.cell.flagged::before { box-shadow: inset 0 0 0 3px var(--bad); }
.cell.flagged-soft::before { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--bad) 60%, transparent); border-radius: 4px; }

.board.solved .cell { animation: cheer .5s ease-out; }
.board.solved .cell.state-queen .queen { fill: var(--good); }

@keyframes pop { from { transform: scale(.55); } to { transform: scale(1); } }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
@keyframes cheer { 40% { transform: scale(1.06); } }

@media (prefers-reduced-motion: reduce) {
  .cell, .board.solved .cell { animation: none !important; transition: none; }
}

/* ------------------------------------------------------------- win overlay */

.win-card {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(300px, 92%);
  height: max-content;
  padding: 22px 20px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 10;
  animation: pop .22s ease-out;
}

.win-card h2 { margin: 0 0 4px; font-size: 20px; }
.win-time { font-size: 34px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.win-note { margin: 0 0 16px; color: var(--ink-muted); font-size: 13.5px; }
.win-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ----------------------------------------------------------------- controls */

.status {
  text-align: center;
  min-height: 22px;
  margin: 14px 0 10px;
  font-size: 14px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.status b.bad { color: var(--bad); }
.status b.good { color: var(--good); }

.puzzle-nav, .toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.btn, .select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .12s ease, transform .06s ease;
}

.btn:hover, .select:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.accent { border-color: var(--good); color: var(--good); }
.btn.subtle { border-color: var(--line); color: var(--ink-muted); font-size: 13px; padding: 5px 11px; }

.select { padding-right: 26px; }

/* Native popups follow the theme instead of coming up white in dark mode. */
.select, .select option, .select optgroup { background-color: var(--card); color: var(--ink); }
.select optgroup { color: var(--ink-muted); }
.select option:checked { background-color: color-mix(in srgb, var(--accent) 35%, var(--card)); }

input[type="checkbox"] { accent-color: var(--accent); }

.field { display: inline-flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--ink-muted); }
.field > span { padding-left: 4px; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 4px;
}

/* ------------------------------------------------------------------ panels */

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 14px;
  font-size: 14.5px;
  color: var(--ink-soft);
}

.panel > summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
  letter-spacing: .02em;
}

.panel h2 { font-size: 14px; margin: 0 0 6px; color: var(--ink); letter-spacing: .02em; }
.panel ol { margin: 8px 0; padding-left: 22px; }
.panel li { margin: 4px 0; }
.panel p { margin: 8px 0; }

.inline-x { color: var(--cross); font-weight: 700; }

.keys { font-size: 13px; color: var(--ink-muted); }

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  font: 500 12px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}

.muted { color: var(--ink-muted); font-size: 13.5px; }

.progress-panel h2 { margin-bottom: 4px; }

footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: 12.5px;
  padding: 8px 16px 22px;
}

button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- responsive */

.board {
  --cell: max(26px, min(58px,
      calc((100vw - 64px) / var(--n)),
      calc((100vh - 330px) / var(--n))));
}

@media (max-width: 560px) {
  .puzzle-head h1 { font-size: 19px; }
  .toolbar { gap: 6px; }
  .btn, .select { font-size: 13px; padding: 6px 11px; }
  .board {
    --cell: max(24px, min(52px,
        calc((100vw - 52px) / var(--n)),
        calc((100vh - 340px) / var(--n))));
  }
}
