/* Nonet */

@font-face { font-family: "Barlow Semi Condensed"; font-weight: 400; font-display: swap; src: url(../fonts/barlow-semi-condensed-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-display: swap; src: url(../fonts/barlow-semi-condensed-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 600; font-display: swap; src: url(../fonts/barlow-semi-condensed-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-display: swap; src: url(../fonts/barlow-semi-condensed-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url(../fonts/barlow-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url(../fonts/barlow-latin-600-normal.woff2) format("woff2"); }

:root {
  --paper: #E8EDF2;          /* graph-paper blue-grey */
  --paper-line: #D7DFE7;
  --sheet: #FFFFFF;
  --ink: #1B2A4A;            /* navy ink: digits, text */
  --ink-soft: #4A5872;
  --graphite: #6B7480;       /* secondary text */
  --note: #1F4E9E;           /* pencil notes */
  --rule: #B9C3CE;
  --hl: #BCD6FF;             /* selection */
  --hl-soft: #E4EEFF;
  --sel-edge: #3D7BE0;
  --err: #C42F3A;
  --thermo: #C9CED6;
  --whisper: #57B36A;
  --renban: #B784D6;
  --arrow: #9AA3AF;
  --parity: #E1E5EA;
  --given: #6B7480;
  --on-ink: #FFFFFF;

  --font: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
  --digits: "Barlow", system-ui, sans-serif;

  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.3125rem;
  --step-2: 1.75rem;
  --step-3: 2.5rem;

  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141922;
    --paper-line: #1A212D;
    --sheet: #1F2733;
    --ink: #E7EDF6;
    --ink-soft: #B3BED0;
    --graphite: #8E99AB;
    --note: #A9C8FF;
    --rule: #3A4556;
    --hl: #29467A;
    --hl-soft: #1F2E4A;
    --sel-edge: #6FA3FF;
    --err: #FF6B74;
    --thermo: #3D4757;
    --whisper: #4E9E5E;
    --renban: #8F62AC;
    --arrow: #6F7B8C;
    --parity: #2C3543;
    --given: #8E99AB;
    --on-ink: #141922;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--paper-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
a { color: var(--ink); }

.skip { position: absolute; left: -999px; top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

/* ------------------------------------------------------------ layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-content: center;
  column-gap: 48px;
  padding: 0 14px;
  max-width: 1400px;
  margin: 0 auto;
}
.main-col { width: 100%; max-width: 780px; margin: 0 auto; min-width: 0; }
.rail { display: none; padding-top: 24px; }
.rail > .ad-slot { position: sticky; top: 24px; }

@media (min-width: 1140px) {
  .layout { grid-template-columns: minmax(0, 780px) 300px; }
  .rail-right { display: flex; flex-direction: column; gap: 24px; }
  .rail-right .ad-second { position: static; }
  .ad-inline { display: none; }
}
@media (min-width: 1400px) {
  .layout { grid-template-columns: 160px minmax(0, 780px) 300px; }
  .rail-left { display: block; }
}

/* ------------------------------------------------------------ header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 2px; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand-mark { width: 26px; height: 26px; }
.brand-mark rect { fill: var(--sheet); stroke: var(--ink); stroke-width: 2; }
.brand-mark path { stroke: var(--ink); stroke-width: 1; fill: none; }
.brand-mark .hi { fill: var(--hl); stroke: none; }
.brand-name { font-weight: 700; font-size: var(--step-1); letter-spacing: -0.01em; line-height: 1; }

.top-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 42px; height: 42px; border: 0; background: transparent; border-radius: var(--radius);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--sheet); }
.icon-btn svg { width: 23px; height: 23px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: var(--ink); stroke: none; }

.puzzle-meta {
  display: grid; grid-template-columns: 1fr auto; align-items: end;
  column-gap: 16px; padding: 6px 0 10px;
}
.puzzle-title { margin: 0; font-size: var(--step-2); font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.puzzle-sub { margin: 3px 0 0; color: var(--ink-soft); grid-column: 1; }
.diff { font-weight: 600; color: var(--ink); margin-left: 8px; }
.timer {
  grid-column: 2; grid-row: 1 / span 2; margin: 0;
  font-family: var(--digits); font-weight: 500; font-size: var(--step-1);
  font-variant-numeric: tabular-nums; color: var(--ink-soft);
}
@media (min-width: 760px) {
  .top { padding: 14px 0 4px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand-name { font-size: var(--step-2); }
  .puzzle-meta { padding: 10px 0 16px; }
  .puzzle-title { font-size: var(--step-3); }
  .timer { font-size: var(--step-2); }
}

/* ------------------------------------------------------------ play area */
.play { display: grid; gap: 12px; }
@media (min-width: 760px) {
  .play { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 28px; }
}
.board-wrap {
  background: var(--sheet);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 var(--rule), 0 12px 32px -18px rgba(27, 42, 74, .35);
  padding: 8px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}
/* keep the board and the keypad on one phone screen */
@media (max-width: 759px) {
  .board-wrap { max-width: min(100%, calc(100svh - 330px)); min-width: 260px; }
}
.board {
  width: 100%; aspect-ratio: 1; display: block;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.board:focus { outline: none; }
.kb .board:focus { outline: 3px solid var(--ink); outline-offset: 5px; border-radius: 2px; }
.board.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .board.shake { animation: none; } }

/* SVG layers */
.cell-bg { fill: var(--sheet); cursor: pointer; }
.cell-bg.same { fill: var(--hl-soft); }
.cell-bg.hinted { fill: var(--hl-soft); }
.cell-bg.sel { fill: var(--hl); }
.sel-edge { fill: none; stroke: var(--sel-edge); stroke-width: 4; stroke-linejoin: round; pointer-events: none; }
.grid-thin { stroke: var(--rule); stroke-width: 1.5; }
.grid-outer { fill: none; stroke: var(--ink); stroke-width: 4; }
.cage { fill: none; stroke: var(--ink-soft); stroke-width: 1.6; stroke-dasharray: 5 4; }
.cage-sum-bg { fill: var(--sheet); }
.cage-sum { font-family: var(--digits); font-weight: 600; font-size: 15px; fill: var(--ink); }
.thermo { stroke: var(--thermo); fill: none; stroke-linecap: round; stroke-linejoin: round; }
.thermo-bulb { fill: var(--thermo); }
.whisper { stroke: var(--whisper); fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.renban { stroke: var(--renban); fill: none; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.arrow-shaft { stroke: var(--arrow); fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.arrow-circle { fill: none; stroke: var(--arrow); stroke-width: 3; }
.parity { fill: var(--parity); }
.dot-white { fill: var(--sheet); stroke: var(--ink); stroke-width: 2; }
.dot-black { fill: var(--ink); }
.xv-bg { fill: var(--sheet); }
.xv { font-family: var(--digits); font-weight: 600; font-size: 22px; fill: var(--ink); }
.digit { font-family: var(--digits); font-weight: 500; font-size: 56px; fill: var(--ink); pointer-events: none; }
.digit.given { fill: var(--given); font-style: italic; }
.digit.err { fill: var(--err); }
.note { font-family: var(--digits); font-weight: 600; fill: var(--note); pointer-events: none; }
.note-corner { font-size: 18px; }
.overlay { pointer-events: none; }

/* ------------------------------------------------------------ controls
   Laid out like a phone keypad: tools | 1-9 | note modes. */
.controls { display: grid; gap: 8px; align-content: start; width: 100%; max-width: 520px; margin: 0 auto; }
.pad-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1.1fr 1.1fr 1fr;
  grid-auto-rows: 54px;
  gap: 6px;
}
@media (min-width: 760px) { .pad-grid { grid-auto-rows: 66px; } }

.key, .tool, .mode {
  border: 0; border-radius: var(--radius); cursor: pointer; position: relative;
  background: var(--sheet); box-shadow: 0 1px 0 var(--rule);
  touch-action: manipulation;
}
.key {
  font-family: var(--digits); font-weight: 500; font-size: 1.6rem; color: var(--ink);
  display: grid; place-items: center; padding: 0;
}
@media (min-width: 760px) { .key { font-size: 1.85rem; } }
.key:active, .tool:active, .mode:active { transform: translateY(1px); }
@media (hover: hover) { .key:hover, .tool:hover, .mode:not(.on):hover { background: var(--hl-soft); } }
.key.used { color: var(--rule); }

/* the keys preview where a note will land */
.controls[data-mode="corner"] .key { place-items: start; padding: 5px 9px; font-size: 1.05rem; font-weight: 600; color: var(--note); }
.controls[data-mode="centre"] .key { font-size: 1.05rem; font-weight: 600; color: var(--note); }

.tool, .mode {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); padding: 0 2px;
}
.tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tool:disabled { opacity: .4; cursor: default; }
.mode.on { background: var(--ink); color: var(--on-ink); box-shadow: none; }
.mode-glyph { font-family: var(--digits); height: 21px; line-height: 21px; font-size: 1.15rem; font-weight: 600; }
.glyph-corner { position: relative; width: 26px; font-size: 0.62rem; line-height: 1; }
.glyph-corner i { position: absolute; font-style: normal; }
.glyph-corner i:nth-child(1) { left: 0; top: 1px; }
.glyph-corner i:nth-child(2) { right: 0; top: 1px; }
.glyph-corner i:nth-child(3) { left: 0; bottom: 1px; }
.glyph-centre { font-size: 0.75rem; letter-spacing: 0.02em; }

.sub-actions { display: flex; justify-content: space-between; gap: 8px; padding: 0 2px; }
.link-btn {
  border: 0; background: transparent; padding: 8px 2px; cursor: pointer;
  color: var(--ink-soft); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--rule);
}
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }

/* ------------------------------------------------------------ rules */
.rules, .about { margin-top: 30px; }
.rules h2, .about h2 { font-size: var(--step-1); margin: 0 0 6px; font-weight: 700; }
.rules-base { margin: 0 0 10px; }
.rules-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rules-list li { display: grid; grid-template-columns: 68px 1fr; gap: 14px; align-items: center; max-width: 62ch; }
.rules-list svg { width: 68px; height: 48px; background: var(--sheet); border-radius: 4px; display: block; }
.rules-list .grid-thin { stroke-width: 3; }
.rules-list .cage { stroke-width: 3; stroke-dasharray: 9 6; }
.rules-list .cage-sum { font-size: 22px; }
.rules-list .arrow-shaft, .rules-list .arrow-circle { stroke-width: 5; }
.rules-list .dot-white { stroke-width: 4; }
.rules-list .xv { font-size: 44px; }
.about p { max-width: 64ch; color: var(--ink-soft); margin: 0 0 10px; }

/* ------------------------------------------------------------ ads */
.ad-slot { display: block; margin: 0 auto; overflow: hidden; }
.ad-skyscraper { width: 160px; min-height: 600px; }
.ad-rect { width: 300px; min-height: 250px; }
.ad-banner { width: 100%; max-width: 728px; min-height: 100px; }
.ad-inline { margin-top: 32px; }
.ad-slot.placeholder {
  border: 1.5px dashed var(--rule); border-radius: var(--radius);
  display: grid; place-items: center; color: var(--graphite); font-size: var(--step--1);
  background: color-mix(in srgb, var(--sheet) 50%, transparent);
}
.ad-slot.placeholder::before { content: "Ad space " attr(data-size); }
.ad-slot.collapsed { min-height: 0; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-label { font-size: 11px; color: var(--graphite); text-align: center; margin: 0 0 4px; }

/* ------------------------------------------------------------ footer */
.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 28px 0 40px; color: var(--graphite); font-size: var(--step--1); }
.foot a { color: var(--graphite); }
.foot-btn { font-size: inherit; color: var(--graphite); font-weight: 400; padding: 0; }

/* ------------------------------------------------------------ toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--on-ink); padding: 10px 16px; border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ------------------------------------------------------------ dialogs */
.dlg {
  border: 0; border-radius: 10px; padding: 26px 24px 22px; width: min(440px, calc(100vw - 32px));
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.4);
}
.dlg::backdrop { background: rgba(20, 28, 44, .45); }
.dlg h2 { margin: 0 0 12px; font-size: var(--step-2); line-height: 1.1; padding-right: 30px; }
.dlg p { margin: 0 0 12px; }
.dlg-close { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: var(--graphite); width: 40px; height: 40px; }
.btn-primary, .btn-secondary {
  border: 0; font-weight: 600; font-size: var(--step-0);
  padding: 12px 18px; border-radius: var(--radius); cursor: pointer; width: 100%; margin-top: 6px;
}
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--rule); }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { font-size: var(--step--1); color: var(--graphite); }
.stats dd { margin: 0; font-family: var(--digits); font-weight: 600; font-size: var(--step-2); font-variant-numeric: tabular-nums; }

.archive { list-style: none; padding: 0; margin: 0; max-height: 60vh; overflow: auto; }
.archive li a {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 6px; text-decoration: none; border-bottom: 1px solid var(--paper-line);
}
.archive li a:hover { background: var(--hl-soft); }
.archive .a-num { font-weight: 700; }
.archive .a-meta { color: var(--graphite); }
.archive .a-state { font-size: var(--step--1); color: var(--graphite); }
.archive .a-state.solved { color: var(--ink); font-weight: 600; }
.archive li.current a { background: var(--hl-soft); }

.dlg-win h2 { font-size: var(--step-3); }
.win-time { font-family: var(--digits); font-size: var(--step-2); font-weight: 600; margin: 0; font-variant-numeric: tabular-nums; }
.win-note { color: var(--ink-soft); }
.win-order p { font-size: var(--step--1); color: var(--graphite); margin: 0 0 6px; }
.order-grid { display: grid; grid-template-columns: repeat(3, 40px); gap: 3px; margin-bottom: 14px; }
.order-grid span {
  height: 40px; display: grid; place-items: center; font-family: var(--digits); font-weight: 600;
  background: var(--paper); border-radius: 3px; color: var(--ink);
}
.order-grid span.first { background: var(--hl); }
.win-next { font-size: var(--step--1); color: var(--graphite); text-align: center; margin: 12px 0 0; }

/* Privacy and 404 pages */
.page { max-width: 680px; margin: 0 auto; padding: 24px 16px 60px; }
.page h1 { font-size: var(--step-3); margin: 20px 0 10px; line-height: 1.05; }
.page h2 { font-size: var(--step-1); margin: 26px 0 6px; }
.page p, .page li { max-width: 66ch; }

/* link back to the hub, same as the other games */
.site-back { display: inline-block; margin: 10px 0 0; color: var(--ink-soft); text-decoration: none; font-size: 0.95rem; }
.site-back:hover { text-decoration: underline; }
