/* ---------- tokens ----------
   Two palettes in one: the page chrome follows the OS theme, while the card
   itself stays light in both — it is a printable artifact and the PNG/JPG
   export always renders it on white, so the screen should match. */
:root {
  color-scheme: light;

  /* page chrome */
  --bg: #eceae4;
  --panel: #ffffff;
  --ink: #14110d;
  --ink-soft: #5d574c;
  --rule: #d6d2c8;
  --btn: #ffffff;
  --btn-hover: #f2efe8;
  --btn-primary-bg: #14110d;
  --btn-primary-ink: #ffffff;
  --btn-primary-hover: #37312a;
  --shadow: 0 2px 0 #14110d;

  /* the card — fixed in both themes */
  --card-bg: #ffffff;
  --card-bg-hover: #f3f0e9;
  --card-ink: #14110d;
  --card-marked: #fbe9ea;
  --card-free: #fff6d8;
  --line: #14110d;
  --win: #f2b705;

  --accent: #c81d25;
  --accent-soft: rgba(200, 29, 37, 0.12);
  --radius: 6px;
  --display: Impact, Haettenschweiler, "Arial Black", "Helvetica Neue", system-ui, sans-serif;
  --sans: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1b1917;
    --panel: #232120;
    --ink: #f0ece4;
    --ink-soft: #a9a296;
    --rule: #3a3631;
    --btn: #2a2724;
    --btn-hover: #37332e;
    --btn-primary-bg: #f0ece4;
    --btn-primary-ink: #14110d;
    --btn-primary-hover: #ffffff;
    --shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1917;
  --panel: #232120;
  --ink: #f0ece4;
  --ink-soft: #a9a296;
  --rule: #3a3631;
  --btn: #2a2724;
  --btn-hover: #37332e;
  --btn-primary-bg: #f0ece4;
  --btn-primary-ink: #14110d;
  --btn-primary-hover: #ffffff;
  --shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

/* Wins over the `display` values set on elements we toggle with .hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding-block: 24px 8px;
  padding-inline: 16px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

main { max-width: 1080px; margin: 0 auto; }

/* ---------- header ---------- */
.page-head {
  max-width: 1080px;
  margin: 0 auto 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.card-title {
  width: 100%;
  max-width: 900px;
  border: 0;
  background: transparent;
  text-align: center;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(30px, 8vw, 64px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #fff;
  padding: 4px 8px;
  border-radius: var(--radius);
  /* 8-way outline: works in every engine, unlike -webkit-text-stroke +
     paint-order, and keeps the title readable on a light background. */
  text-shadow:
    -2px -2px 0 #14110d, 0 -2px 0 #14110d, 2px -2px 0 #14110d,
    -2px 0 0 #14110d, 2px 0 0 #14110d,
    -2px 2px 0 #14110d, 0 2px 0 #14110d, 2px 2px 0 #14110d,
    5px 5px 0 rgba(20, 17, 13, 0.45);
}

.card-title:hover { background: rgba(127, 127, 127, 0.16); }
.card-title:focus-visible { outline: 2px solid var(--accent); background: rgba(127, 127, 127, 0.22); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 2px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.tool-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.tool-sep { flex: 1 1 0; min-width: 0; }

/* Keeps related buttons on the same line as each other when the bar wraps,
   instead of the pair splitting across two rows. */
.tool-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.step {
  width: 28px;
  height: 28px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--btn);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.step:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--ink-soft); }
.step:disabled { opacity: 0.35; cursor: not-allowed; }
.step-value { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }

.btn {
  padding: 7px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { background: var(--btn-hover); border-color: var(--ink-soft); }

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-ink);
  border-color: var(--btn-primary-bg);
  font-weight: 600;
}

.btn-primary:hover { background: var(--btn-primary-hover); border-color: var(--btn-primary-hover); }
.btn-export { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn-danger { color: var(--accent); }
.btn-danger:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-export:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: progress; }

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.btn-theme { min-width: 148px; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- messages ---------- */
.notice {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14px;
}

.banner {
  margin: 0 0 14px;
  padding: 12px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(22px, 5vw, 34px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- board ---------- */
.board-scroll { overflow-x: auto; padding-bottom: 4px; }

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 6px;
  padding: 6px;
  background: var(--line);
  border: 3px solid var(--line);
  border-radius: 4px;
  min-width: min-content;
}

/* column counts — set as a class so the page never writes inline styles */
.board.cols-2 { grid-template-columns: repeat(2, minmax(112px, 1fr)); }
.board.cols-3 { grid-template-columns: repeat(3, minmax(112px, 1fr)); }
.board.cols-4 { grid-template-columns: repeat(4, minmax(112px, 1fr)); }
.board.cols-5 { grid-template-columns: repeat(5, minmax(112px, 1fr)); }
.board.cols-6 { grid-template-columns: repeat(6, minmax(112px, 1fr)); }
.board.cols-7 { grid-template-columns: repeat(7, minmax(112px, 1fr)); }
.board.cols-8 { grid-template-columns: repeat(8, minmax(112px, 1fr)); }
.board.cols-9 { grid-template-columns: repeat(9, minmax(112px, 1fr)); }
.board.cols-10 { grid-template-columns: repeat(10, minmax(112px, 1fr)); }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 2;
  padding: 8px 6px;
  border: 0;
  background: var(--card-bg);
  color: var(--card-ink);
  font: inherit;
  font-size: clamp(11px, 1.15vw, 14px);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  hyphens: auto;
  cursor: pointer;
  transition: background 0.12s;
}

.cell:hover { background: var(--card-bg-hover); }
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell.is-marked { background: var(--card-marked); }

/* Each stroke is a bar centred on the cell, then rotated about its own
   middle. 33.69deg is atan(2/3) — the diagonal angle of the 3:2 cell — and
   114% is just under the 120.2% that would reach the corners exactly, so the
   ends stay inside even with the stroke width. Cells that stretch taller than
   3:2 only gain clearance. */
.cell.is-marked::before,
.cell.is-marked::after {
  content: "";
  position: absolute;
  left: -7%;
  width: 114%;
  top: calc(50% - 2px);
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  transform-origin: center;
  opacity: 0.85;
  pointer-events: none;
}

.cell.is-marked::before { transform: rotate(33.69deg); }
.cell.is-marked::after { transform: rotate(-33.69deg); }

/* Blank squares are an invitation, not a gap — click to type into them. The
   greys are literal because the card keeps its light palette in every theme. */
.cell.is-empty {
  color: #b3ab9c;
  font-size: 26px;
  font-weight: 400;
  box-shadow: inset 0 0 0 2px #e3dfd6;
}

.cell.is-empty:hover {
  color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell-input {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  padding: 8px 6px;
  border: 0;
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  background: var(--card-bg);
  color: var(--card-ink);
  font-family: var(--sans);
  font-size: clamp(11px, 1.15vw, 14px);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.cell.is-free {
  background: var(--card-free);
  font-family: var(--display);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.05em;
}

.cell.in-line { box-shadow: inset 0 0 0 4px var(--win); }

/* ---------- editor dialog ---------- */
.editor {
  width: min(560px, 92vw);
  padding: 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

.editor::backdrop { background: rgba(20, 17, 13, 0.55); }
.editor-form { display: flex; flex-direction: column; gap: 10px; padding: 18px; }

.editor h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.editor-help, .editor-count { margin: 0; font-size: 13px; color: var(--ink-soft); }

.editor textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.editor-actions .spacer { flex: 1 1 0; }

/* ---------- misc ---------- */
.hint { margin: 12px 0 0; font-size: 13px; color: var(--ink-soft); text-align: center; }

.page-foot {
  max-width: 1080px;
  margin: 24px auto 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

.page-foot code { font-size: 11px; }

@media (max-width: 520px) {
  .toolbar { gap: 6px; }
  .tool-sep { flex-basis: 100%; height: 0; }
  .btn { flex: 1 1 auto; }
}
