/* Daily Number Cross - "printed puzzle book" look: warm paper, black ink, one vermilion stamp colour. */
:root {
  --paper: #f3ead6;
  --paper-2: #e9dec2;
  --ink: #1d1b16;
  --muted: #62594a;
  --cell: #fffaf0;
  --given: #d8d0bb;
  --sel: #ffdf7e;
  --peer: #f7e9bd;
  --accent: #c8321b;
  --accent-ink: #fff7ec;
  --ok: #23724a;
  --ok-bg: #d3ead9;
  --err: #c8321b;
  --err-bg: #f6d6cd;
  --void-dot: rgba(29, 27, 22, .16);
  --shadow: 3px 3px 0 var(--ink);
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --body: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --num: Rockwell, "Rockwell Nova", "Roboto Slab", "Courier New", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15171c; --paper-2: #1d2027; --ink: #efe6d0; --muted: #a39b88; --cell: #252a33; --given: #3a3f4b;
    --sel: #6b5516; --peer: #2f3037; --accent: #ff6a4d; --accent-ink: #1a0f0b; --ok: #7bd99a; --ok-bg: #1f3a2a;
    --err: #ff7a60; --err-bg: #4a2520; --void-dot: rgba(239, 230, 208, .14); --shadow: 3px 3px 0 #000;
  }
}
:root[data-theme="dark"] {
  --paper: #15171c; --paper-2: #1d2027; --ink: #efe6d0; --muted: #a39b88; --cell: #252a33; --given: #3a3f4b;
  --sel: #6b5516; --peer: #2f3037; --accent: #ff6a4d; --accent-ink: #1a0f0b; --ok: #7bd99a; --ok-bg: #1f3a2a;
  --err: #ff7a60; --err-bg: #4a2520; --void-dot: rgba(239, 230, 208, .14); --shadow: 3px 3px 0 #000;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background-color: var(--paper); font-family: var(--body); font-size: 17px; line-height: 1.55;
  background-image:
    linear-gradient(var(--void-dot) 1px, transparent 1px),
    linear-gradient(90deg, var(--void-dot) 1px, transparent 1px);
  background-size: 28px 28px; background-position: -1px -1px;
  padding-bottom: env(safe-area-inset-bottom);
}
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button { font: inherit; color: inherit; }

.mast, main, .foot { width: 100%; max-width: 680px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.mast { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; letter-spacing: .02em; text-transform: uppercase; font-size: 13px; }
.brand-mark { width: 22px; height: 22px; background: var(--ink); border-radius: 4px; position: relative; flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--paper); }
.brand-mark::before { left: 9px; top: 4px; width: 4px; height: 14px; }
.brand-mark::after { left: 4px; top: 9px; width: 14px; height: 4px; }
.ghost { background: transparent; border: 1.5px solid var(--ink); border-radius: 999px; padding: 4px 14px; font-size: 13px; cursor: pointer; min-height: 32px; }
.ghost:hover { background: var(--ink); color: var(--paper); }

/* ---------- title ---------- */
.titleblock { padding: 8px 0 6px; }
.kicker { margin: 0 0 2px; font-family: var(--num); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
h1 { font-family: var(--display); font-weight: 800; font-size: clamp(30px, 8.4vw, 50px); line-height: 1.02; margin: 0 0 8px; letter-spacing: -.015em; text-wrap: balance; }
.lede { margin: 0 0 12px; color: var(--muted); font-size: 16px; max-width: 46ch; }

/* ---------- tabs ---------- */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 12px; }
.tabs button {
  position: relative; background: var(--cell); border: 2px solid var(--ink); border-radius: 6px; padding: 7px 4px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; line-height: 1.15; min-height: 52px; transition: transform .12s, box-shadow .12s;
}
.tabs .tl { font-family: var(--display); font-weight: 800; font-size: 16px; }
.tabs .ts { font-family: var(--num); font-size: 12px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); box-shadow: var(--shadow); transform: translate(-1px, -1px); }
.tabs button[aria-selected="true"] .ts { color: var(--paper-2); opacity: .8; }
.tabs .tick { position: absolute; top: -7px; right: -5px; width: 20px; height: 20px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 12px; line-height: 20px; text-align: center; display: none; border: 2px solid var(--paper); }
.tabs button.done .tick { display: block; }
.tabs button.done .tick::before { content: "\2713"; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 0 0 10px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.stats > div { padding: 6px 4px 6px 8px; border-left: 1.5px solid var(--ink); min-width: 0; }
.stats > div:first-child { border-left: 0; padding-left: 2px; }
.stats dt { font-family: var(--num); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0; }
.stats dd { margin: 0; font-family: var(--num); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; margin-left: 6px; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); vertical-align: 3px; letter-spacing: .04em; }

.tools { display: flex; gap: 8px; margin-bottom: 10px; }
.tool { background: transparent; border: 1.5px solid var(--ink); border-radius: 6px; padding: 5px 14px; cursor: pointer; font-family: var(--num); font-size: 14px; min-height: 36px; }
.tool:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.tool:disabled { opacity: .4; cursor: default; }

/* ---------- board ---------- */
.boardwrap { container-type: inline-size; width: 100%; }
.board {
  --gap: 4px;
  --u: min(58px, calc((100cqw - 24px - var(--n) * var(--gap)) / (var(--n) + 1)));
  display: grid; grid-template-columns: repeat(calc(var(--n) + 1), var(--u)); grid-auto-rows: var(--u); gap: var(--gap);
  width: max-content; max-width: 100%; margin: 0 auto; padding: 10px; background: var(--paper-2); border: 2px solid var(--ink); border-radius: 8px; box-shadow: var(--shadow);
  box-sizing: content-box; font-size: calc(var(--u) * .5);
}
.board > * { min-width: 0; }
.void { background: transparent; }
.cell {
  position: relative; display: block; width: 100%; height: 100%; padding: 0; background: var(--cell); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 4px; cursor: pointer; font-family: var(--num); font-weight: 700; font-size: 1em; line-height: 1;
  font-variant-numeric: tabular-nums; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color .1s, border-color .15s;
}
.cell.peer { background: var(--peer); }
.cell.sel { background: var(--sel); box-shadow: inset 0 0 0 2px var(--ink); }
.cell.given { background: var(--given); color: var(--muted); cursor: default; }
.cell.given.sel { background: var(--sel); }
.cell.given::after { content: ""; position: absolute; right: 3px; top: 3px; width: 5px; height: 5px; background: var(--muted); border-radius: 50%; opacity: .6; }
/* row/column state shown on the borders: rows on top/bottom, columns on left/right */
.cell.r-ok { border-top-color: var(--ok); border-bottom-color: var(--ok); }
.cell.r-err { border-top-color: var(--err); border-bottom-color: var(--err); }
.cell.c-ok { border-left-color: var(--ok); border-right-color: var(--ok); }
.cell.c-err { border-left-color: var(--err); border-right-color: var(--err); }
.cell.r-ok, .cell.r-err, .cell.c-ok, .cell.c-err { border-width: 3px; }
.cell.pop { animation: pop .18s ease-out; }
@keyframes pop { 0% { transform: scale(.82); } 100% { transform: scale(1); } }

.sum {
  display: grid; place-items: center; font-family: var(--num); font-weight: 700; font-size: calc(var(--u) * .36); line-height: 1; color: var(--ink);
  border: 2px solid var(--muted); border-radius: 50%; width: 88%; height: 88%; align-self: center; justify-self: center; font-variant-numeric: tabular-nums;
  background: transparent; transition: background-color .15s, color .15s, border-color .15s;
}
.sum.ok { background: var(--ok); border-color: var(--ok); color: var(--paper); }
.sum.err { background: var(--err); border-color: var(--err); color: var(--accent-ink); }
.corner { background: transparent; }

.hint { margin: 10px 0 0; text-align: center; font-size: 14px; color: var(--muted); min-height: 1.5em; }

/* ---------- number pad ---------- */
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px auto 0; max-width: 420px; }
.pad button {
  background: var(--cell); border: 2px solid var(--ink); border-radius: 8px; font-family: var(--num); font-weight: 700; font-size: 22px; min-height: 52px; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink); touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.pad button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.pad button:hover { background: var(--sel); }
.pad .erase { color: var(--accent); }
.pad.off { display: none; }
@media (max-width: 600px) {
  body.has-pad { padding-bottom: calc(138px + env(safe-area-inset-bottom)); }
  .pad {
    position: fixed; left: 0; right: 0; bottom: 0; max-width: none; margin: 0; z-index: 20; gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper); border-top: 2px solid var(--ink); box-shadow: 0 -6px 18px rgba(0, 0, 0, .12);
  }
  .pad button { min-height: 46px; font-size: 21px; }
}

/* ---------- result ---------- */
.result { position: relative; margin: 18px 0 8px; padding: 22px 16px 18px; background: var(--cell); border: 2px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow); }
.result h2 { font-family: var(--display); font-size: 28px; margin: 0 0 4px; outline: none; }
.stamp {
  position: absolute; right: 14px; top: 12px; font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .12em; font-size: 15px;
  color: var(--accent); border: 3px double var(--accent); padding: 4px 10px; border-radius: 4px; transform: rotate(-9deg); opacity: .9;
}
.stamp.slam { animation: slam .45s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes slam { 0% { transform: rotate(-9deg) scale(2.2); opacity: 0; } 100% { transform: rotate(-9deg) scale(1); opacity: .9; } }
.resline { margin: 0 0 10px; color: var(--muted); }
.share { margin: 0 0 12px; padding: 12px; background: var(--paper); border: 1.5px dashed var(--ink); border-radius: 6px; font-family: var(--num); font-size: 15px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.resbtns { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.primary { background: var(--accent); color: var(--accent-ink); border: 2px solid var(--ink); border-radius: 8px; padding: 10px 20px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 var(--ink); min-height: 46px; }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.copied { font-family: var(--num); font-size: 14px; color: var(--ok); }
.next { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.cta { margin-top: 16px; padding-top: 14px; border-top: 2px dashed var(--ink); }
.cta-lead { margin: 0 0 10px; }
.cta-btn { display: inline-block; background: var(--ink); color: var(--paper); text-decoration: none; padding: 11px 18px; border-radius: 8px; font-weight: 700; border: 2px solid var(--ink); }
.cta-btn:hover { background: transparent; color: var(--ink); }

/* ---------- prose ---------- */
.howto, .faq { margin-top: 40px; max-width: 62ch; }
.howto h2, .faq h2 { font-family: var(--display); font-size: clamp(24px, 6vw, 32px); line-height: 1.1; margin: 0 0 14px; padding-top: 14px; border-top: 4px solid var(--ink); }
.howto h3 { font-family: var(--display); font-size: 20px; margin: 22px 0 6px; }
.howto p, .faq p { margin: 0 0 14px; }
.faq .qa { padding: 10px 0 2px; border-bottom: 1px solid var(--void-dot); }
.faq h3 { font-family: var(--display); font-size: 18px; margin: 0 0 4px; }
.foot { padding-top: 28px; padding-bottom: 36px; color: var(--muted); font-size: 14px; }
.noscript { padding: 12px; border: 2px solid var(--err); background: var(--err-bg); }

@media (min-width: 900px) { main { max-width: 720px; } .mast, .foot { max-width: 720px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
