:root {
  --paper: #f0efe8;
  --card: #fbfaf6;
  --ink: #1b1c20;
  --ink-soft: #5d5b53;
  --line: #d9d5c9;
  --blue: #2547c9;
  --blue-deep: #1a36a8;
  --red: #cf3a2b;
  --red-tint: #fbe7e3;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Spline Sans Mono", "Cascadia Code", ui-monospace, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
}

::selection { background: rgba(37, 71, 201, 0.22); }

button, input, textarea { font: inherit; color: inherit; }

.mono { font-family: var(--font-mono); }

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.masthead {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 20px 6px;
}

.brand { display: flex; align-items: center; gap: 13px; }

.mark { width: 46px; height: 46px; flex: none; }

.mark-t {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 21px;
  fill: var(--ink);
}

.brand-name {
  display: block;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  line-height: 1.1;
}

.brand-tag {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 56px;
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  position: sticky;
  top: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
}

.panel-title + .panel-title,
.row.spread + h2,
.size-cards ~ h2,
#titleInput + h2,
.gen-notes + h2 { margin-top: 20px; }

.clue-no {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  border: 1.4px solid var(--ink);
  border-radius: 4px;
  padding: 2px 5px;
  letter-spacing: 0.03em;
}

.hint { margin: 0 0 8px; font-size: 12.5px; color: var(--ink-soft); }

.hint code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: #eceade;
  border-radius: 4px;
  padding: 1px 5px;
}

.entry-table { width: 100%; border-collapse: separate; border-spacing: 4px 7px; }

.et-ans-col { width: 36%; }

.entry-table thead th {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: left;
}

.et-w, .et-c {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 9px;
  font-size: 12.5px;
  line-height: 1.45;
}

.et-w { font-family: var(--font-mono); }

.et-w:focus, .et-c:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 71, 201, 0.14); }

#titleInput {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 9px;
  font-size: 13.5px;
}

#titleInput:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 71, 201, 0.14); }

#loadSelect {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 8px;
  font-size: 12.5px;
}

#loadSelect:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 71, 201, 0.14); }

.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row.spread { justify-content: space-between; }

.microcount { font-size: 11px; color: var(--ink-soft); text-align: right; }
.microcount b { color: var(--red); font-weight: 500; }

.size-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.size-card {
  position: relative;
  border: 1.4px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.size-card:hover { border-color: var(--ink-soft); }

.size-card input { position: absolute; opacity: 0; pointer-events: none; }

.size-card.checked {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.sc-name { display: block; font-weight: 700; font-size: 13.5px; }
.size-card.checked .sc-name { font-weight: 800; }
.sc-dims { display: block; font-family: var(--font-mono); font-size: 10px; color: var(--ink-soft); margin-top: 2px; line-height: 1.35; }

.paper-row { gap: 6px; }

.pill-radio {
  position: relative;
  border: 1.4px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 5px 14px;
  font-size: 12.5px;
  cursor: pointer;
}

.pill-radio input { position: absolute; opacity: 0; pointer-events: none; }
.pill-radio.checked { background: var(--ink); border-color: var(--ink); color: #fff; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 12px;
  cursor: pointer;
}

.check-row input { accent-color: var(--blue); width: 15px; height: 15px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.4px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 8px 13px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #32343c; }

.btn.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 18px; }

.btn.ghost {
  border: none;
  background: transparent;
  color: var(--blue);
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 12px;
  padding: 2px;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.btn.ghost:hover { color: var(--blue-deep); }

.btn.danger { color: var(--red); }
.btn.danger:hover:not(:disabled) { color: #a92c1f; }

.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 6px; }

.btn.light { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.4); color: #fff; }
.btn.light:hover:not(:disabled) { background: rgba(255, 255, 255, 0.26); border-color: #fff; }

.gen-notes { margin-top: 10px; font-size: 12px; color: var(--ink-soft); display: none; }
.gen-notes.show { display: block; }
.gen-notes .note { padding-left: 14px; position: relative; margin-top: 3px; }
.gen-notes .note::before { content: ""; position: absolute; left: 2px; top: 7px; width: 5px; height: 5px; background: var(--ink-soft); border-radius: 1px; }
.gen-notes .note.bad::before { background: var(--red); }

.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  min-height: 460px;
}

.print-title { display: none; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.chip {
  font-size: 11px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 11px;
  color: var(--ink-soft);
}

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

.timer { font-size: 13px; color: var(--ink-soft); min-width: 46px; text-align: right; letter-spacing: 0.02em; }

.win-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 14px;
  animation: rise 0.3s ease-out;
}

.win-banner strong { font-weight: 800; }
.win-text { font-size: 14px; }
.win-actions { display: flex; gap: 8px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.empty {
  min-height: 320px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 40px 16px;
}

.empty-mark { width: 96px; opacity: 0.9; }
.empty-title { margin: 18px 0 0; font-weight: 700; font-size: 17px; }
.empty-sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 13px; max-width: 340px; }
.empty-sub em { font-style: normal; color: var(--blue); font-weight: 600; }

.grid-wrap { display: grid; place-items: center; padding: 6px 0 2px; }

.grid {
  --cellpx: 24px;
  --letfs: calc(var(--cellpx) * 0.5);
  --numfs: max(7px, calc(var(--cellpx) * 0.3));
  display: grid;
  grid-template-columns: repeat(var(--n, 15), var(--cellpx));
  background: #fff;
}

.cell { position: relative; width: var(--cellpx); height: var(--cellpx); }

/* classic look: one thin line per interior edge (drawn by the lower/right
   neighbour), dark outlines reserved for block edges via .b-* below */
.cell:not(.black) { border-top: 1px solid var(--line); border-left: 1px solid var(--line); }

.cell.black { background: var(--ink); }

.cell.b-t { border-top: 1.6px solid var(--ink); }
.cell.b-r { border-right: 1.6px solid var(--ink); }
.cell.b-b { border-bottom: 1.6px solid var(--ink); }
.cell.b-l { border-left: 1.6px solid var(--ink); }

.cell .num {
  position: absolute;
  top: max(1px, calc(var(--cellpx) * 0.05));
  left: max(1px, calc(var(--cellpx) * 0.07));
  font-family: var(--font-mono);
  font-size: var(--numfs);
  line-height: 1;
  z-index: 1;
}

.cell .letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: var(--letfs);
  line-height: 1;
}

.cell.sel { outline: 2.5px solid var(--blue); outline-offset: -3px; z-index: 2; }
.cell.wrong { background: var(--red-tint); }
.cell.wrong .letter { color: var(--red); }
.cell.revealed .letter { color: var(--blue); font-weight: 800; }

.clues {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.clue-block h3 {
  margin: 0 0 9px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--ink);
}

.clue-list { columns: 2; column-gap: 22px; }
.clue-list.dense { columns: 3; }

.clue { break-inside: avoid; display: flex; gap: 7px; margin-bottom: 6px; font-size: 13px; line-height: 1.45; }
.clue .cnum { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-soft); min-width: 20px; text-align: right; flex: none; padding-top: 1px; }
.clue .ctext { flex: 1; }
.clue .cw { font-family: var(--font-mono); font-size: 10.5px; color: #a39f92; white-space: nowrap; margin-left: 6px; }

body.playing .cw { display: none; }

#playInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  max-width: min(90vw, 480px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; padding-top: 12px; }
  body.has-puzzle .stage { order: -1; }
  .panel { position: static; }
}

@media (max-width: 560px) {
  .clues { grid-template-columns: 1fr; gap: 18px; }
  .clue-list, .clue-list.dense { columns: 1; }
  .toolbar { margin-bottom: 10px; }
  .tool-actions { width: 100%; justify-content: flex-start; }
  .masthead { padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  @page { margin: 11mm; }

  body { background: #fff; font-size: 12pt; }

  .masthead, #setupPanel, #stageEmpty, #winBanner, #toast, #playInput { display: none; }

  .shell { display: block; max-width: none; padding: 0; }

  .stage { border: none; background: #fff; padding: 0; min-height: 0; }

  .toolbar { display: none; }

  .print-title {
    display: block;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 19pt;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 4mm;
  }

  .grid-wrap { padding: 0; }

  .grid { background: transparent; }

  .cell.black {
    background: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .grid.size-10 { --cellpx: 34pt !important; }
  .grid.size-15 { --cellpx: 26.5pt !important; }
  .grid.size-20 { --cellpx: 21pt !important; }

  .clues { margin-top: 7mm; gap: 8mm 14mm; font-size: 7.3pt; }
  body[data-grid="20"] .clues { font-size: 6.6pt; }

  .clue-block h3 { font-size: 9pt; border-bottom-width: 1.4pt; margin-bottom: 2.5mm; }
  .clue-list { columns: 2; column-gap: 8mm; font-size: inherit; }
  body[data-grid="20"] .clue-list, body[data-grid="20"] .clue-list.dense { columns: 3; }

  .clue { margin-bottom: 1.6mm; font-size: inherit; line-height: 1.4; }
  .cw { display: none !important; }

  .cell.sel, .cell.wrong { background: #fff; outline: none; }
}
