:root {
  --ink: #1d1f24;
  --muted: #6b7080;
  --line: #d7dae0;
  --bg: #f5f4ef;
  --panel: #fff;
  --accent: #2f5bd3;
  --word: #dce6ff;
  --sel: #ffd84d;
  --bad: #e5484d;
  --warn: #c98a00;
  --cell: min(36px, calc((100vw - 32px) / var(--cols)));
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: #fff; }
input[type=number] { width: 4.2em; }
label { display: block; margin: 6px 0; color: var(--muted); }
label > input:not([type=radio]):not([type=number]):not([type=file]), label > textarea { display: block; width: 100%; color: var(--ink); margin-top: 2px; }
label.inline { display: inline-flex; gap: 4px; align-items: center; margin-right: 12px; }
.bar label { display: inline-flex; gap: 4px; align-items: center; margin: 0; }

.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 16px; background: var(--ink); color: #eee; }
.bar h1 { font-size: 18px; margin: 0 8px 0 0; letter-spacing: .5px; }
.bar label { color: #ccc; }
.sep { flex: 1; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on, .tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

main { display: grid; grid-template-columns: auto minmax(340px, 1fr); gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 1000px) { main { grid-template-columns: 1fr; } }

.board { min-width: 0; }
.clue-bar { min-height: 2.2em; padding: 6px 10px; margin-bottom: 8px; background: var(--word); border-radius: 6px; font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(var(--cols), var(--cell)); border: 2px solid var(--ink); width: max-content; background: var(--ink); gap: 1px; outline: none; user-select: none; }
.cell { position: relative; width: var(--cell); height: var(--cell); background: #fff; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .58); font-weight: 600; cursor: pointer; }
.cell.block { background: var(--ink); }
.cell .num { position: absolute; top: 1px; left: 2px; font-size: calc(var(--cell) * .27); font-weight: 400; color: var(--ink); }
.cell.auto .ltr { color: var(--accent); font-weight: 500; }
.cell.shade { background: #e3e3e3; }
.cell.circle::after { content: ""; position: absolute; inset: 2px; border: 1px solid var(--ink); border-radius: 50%; pointer-events: none; }
.cell.word { background: var(--word); }
.cell.sel { background: var(--sel); }
.cell.unchecked { box-shadow: inset 0 0 0 2px var(--warn); }
.cell.bad { box-shadow: inset 0 0 0 2px var(--bad); }
.cell.problem { background: #ffd2d2; }
.cell.problem.sel { background: #ffb0a0; }

.stats { margin-top: 10px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 14px; }
.stats b { color: var(--ink); }
.issues { margin: 8px 0; padding-left: 18px; }
.issues li.err { color: var(--bad); }
.issues li.warn { color: var(--warn); }
.issues li.ok { color: #2a8a4a; list-style: none; margin-left: -18px; }
.hint { color: var(--muted); font-size: 12px; max-width: 560px; }
kbd { border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; background: #fff; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.row label { margin: 0; }
#pattern { flex: 1; min-width: 180px; font-family: ui-monospace, monospace; letter-spacing: 1px; }
.status { padding: 8px 10px; background: #f3f5f9; border-radius: 6px; margin: 8px 0; white-space: pre-line; }
.status.err { background: #fde8e8; color: #8b1a1a; }
.status.ok { background: #e6f5ea; color: #1d5f30; }
.log { max-height: 200px; overflow: auto; color: var(--muted); font-size: 12px; padding-left: 22px; }
.results { width: 100%; border-collapse: collapse; font-size: 13px; }
.results th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px; }
.results td { padding: 3px 4px; border-bottom: 1px solid #f0f0f0; }
.results tr { cursor: pointer; }
.results tr:hover td { background: var(--word); }
.results tr.dead td { color: #b0b0b0; }
.results td:first-child { font-family: ui-monospace, monospace; letter-spacing: 1px; }

.clue-editor { max-height: 70vh; overflow: auto; }
.clue-editor h3 { margin: 10px 0 4px; font-size: 14px; }
.clue-row { display: grid; grid-template-columns: 2.6em 1fr; gap: 2px 6px; padding: 4px 0; border-bottom: 1px solid #f0f0f0; }
.clue-row.cur { background: var(--word); }
.clue-row .n { font-weight: 600; text-align: right; }
.clue-row .ans { font-family: ui-monospace, monospace; color: var(--muted); font-size: 12px; letter-spacing: 1px; }
.clue-row input.text { width: 100%; }
.clue-row input.enum { width: 6em; }
.clue-row .fields { display: flex; gap: 4px; }

.print-view { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .bar, main { display: none !important; }
  .print-view { display: block; }
  .print-view h2 { margin: 0 0 2px; font-size: 18pt; }
  .print-view .by { margin: 0 0 10px; color: #444; }
  .print-view img { width: 100%; max-width: 120mm; display: block; margin-bottom: 8mm; }
  .print-view .clues { columns: 3; column-gap: 8mm; font-size: 9.5pt; }
  .print-view .clues h3 { font-size: 11pt; margin: 0 0 3px; break-after: avoid; }
  .print-view .clues p { margin: 0 0 3px; break-inside: avoid; }
}
