:root {
  --bg: #e4ddd0;
  --paper: #f7f3ea;
  --ink: #1c1916;
  --muted: #6d655c;
  --line: #d2c8b8;
  --mark: #8a8174;
  --bad: #9d2f2c;
  --ok: #1f6b45;
  --focus: #1d4e89;
  --cell: 42px;
  --major: color-mix(in srgb, var(--ink) 42%, var(--paper));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --paper: #221f1b;
    --ink: #f3ecdf;
    --muted: #b2a89b;
    --line: #3a342c;
    --mark: #a39888;
    --bad: #ff6b63;
    --ok: #7dcea5;
    --focus: #8eb6ef;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.4 "Avenir Next",
    "Segoe UI",
    sans-serif;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}

h1 {
  margin: 0;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.lede {
  margin: 6px 0 0;
  color: var(--muted);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.status {
  margin: 0;
  min-height: 1.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status.solved {
  color: var(--ok);
  font-weight: 600;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.seg,
.actions {
  display: inline-flex;
  border: 1px solid var(--ink);
}

.seg {
  position: relative;
  margin: 0;
  padding: 0;
  min-inline-size: 0;
}

.seg legend {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.seg button,
.actions button,
.seed-form button,
.cell {
  font: inherit;
  color: inherit;
  background: transparent;
  cursor: pointer;
}

.seg button,
.actions button {
  border: 0;
  border-right: 1px solid var(--ink);
  padding: 8px 12px;
}

.seg button:last-child,
.actions button:last-child {
  border-right: 0;
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.seed-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.seed-form label {
  color: var(--muted);
}

.seed-form input {
  width: 8.5em;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
  padding: 7px 8px;
}

.seed-form button {
  border: 1px solid var(--ink);
  padding: 8px 12px;
}

.help {
  margin: 0 0 18px;
  color: var(--muted);
  max-width: 62ch;
}

.board-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.board {
  --cell: 44px;
  display: grid;
  grid-template-columns: max-content repeat(var(--cols), var(--cell));
  width: max-content;
  background: var(--paper);
  border-top: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  touch-action: none;
  user-select: none;
}

.board[data-cols="10"] {
  --cell: 34px;
}

.board[data-cols="20"] {
  --cell: 26px;
}

.corner,
.clue-col {
  border-bottom: 2px solid var(--ink);
}

.clue {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.clue-num {
  white-space: nowrap;
  letter-spacing: -0.03em;
}

.clue-sep {
  font-weight: 600;
  opacity: 0.75;
  line-height: 1;
}

.clue-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  min-height: 4.2em;
  padding: 6px 0 4px;
  border-right: 1px solid transparent;
}

.clue-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0;
  min-width: 3.4em;
  padding: 0 8px;
  border-right: 2px solid var(--ink);
  border-bottom: 1px solid transparent;
}

.clue-row .clue-sep {
  margin-left: 0.05em;
}

.clue.is-met {
  color: var(--ok);
}

.clue.is-met .clue-sep {
  opacity: 0.85;
}

.clue-col.edge-r,
.cell.edge-r {
  border-right: 2px solid var(--ink);
}
.clue-col.major-r {
  border-right: 3px solid var(--major);
}
.clue-row.edge-b,
.cell.edge-b {
  border-bottom: 2px solid var(--ink);
}
.clue-row.major-b {
  border-bottom: 3px solid var(--major);
}

.cell.major-r {
  border-right: 3px solid var(--major);
  box-shadow: none;
}
.cell.major-b {
  border-bottom: 3px solid var(--major);
  box-shadow: none;
}
.cell.major-r.major-b {
  box-shadow: none;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  position: relative;
  padding: 0;
  border: 0;
  background: transparent;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.cell[data-v="1"] {
  background: var(--ink);
}

.cell[data-v="2"] {
  color: var(--mark);
}

.cell[data-v="2"]::before {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.78);
  line-height: 1;
}

.cell.bad[data-v="1"] {
  background: var(--bad);
}
.cell.bad[data-v="2"] {
  color: var(--bad);
}

.board.is-solved {
  outline: 2px solid var(--ok);
  outline-offset: 4px;
}

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

.cell:focus-visible {
  outline-offset: -3px;
  z-index: 1;
}

@media (max-width: 720px) {
  h1 {
    font-size: 32px;
  }
  .top {
    flex-direction: column;
    align-items: flex-start;
  }
  .status {
    text-align: left;
  }
  .seed-form {
    margin-left: 0;
  }
  .board[data-cols="5"] {
    --cell: 42px;
  }
  .board[data-cols="10"],
  .board[data-cols="20"] {
    --cell: 36px;
  }
  .board[data-cols="10"] .clue,
  .board[data-cols="20"] .clue {
    font-size: 11px;
  }
  .seg button,
  .actions button,
  .seed-form button {
    min-height: 44px;
  }
}

body.is-fullscreen {
  overflow: hidden;
}

body.is-fullscreen main {
  max-width: none;
  padding: 0;
}

body.is-fullscreen .top,
body.is-fullscreen .controls,
body.is-fullscreen .help {
  display: none;
}

body.is-fullscreen .board-wrap {
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 64px 12px 24px;
  background: var(--bg);
}

body.is-fullscreen .board {
  --cell: 48px;
  touch-action: manipulation;
}

#exit-fullscreen {
  display: none;
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 4;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  padding: 10px 14px;
  min-height: 44px;
}

body.is-fullscreen #exit-fullscreen {
  display: block;
}

@media (max-width: 720px) {
  body.is-fullscreen .board {
    --cell: 44px;
  }
}
