/* Sudoku - ruled paper on the same bench, under the same brass lamp. */

:root {
  --ink:        #12100C;
  --parchment:  #F0E4CC;
  --parchment-2:#C3B294;
  --parchment-3:#8B7C64;
  --brass:      #C79A45;
  --brass-2:    #8A6C31;
  --crimson:    #A9342B;
  --verdigris:  #3FA97A;

  --shell: 1px solid color-mix(in srgb, var(--brass) 34%, transparent);

  /* The board is sized once, here, and everything on it is a fraction of that.
     There is no camera and nothing to pan: the whole grid is always on screen
     at whatever size fits, so a cell can never be scrolled out from under a
     finger that is about to tap it. */
  --board: min(94vw, 62vh, 560px);
  --cell: calc(var(--board) / 9);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  color: var(--parchment);
  background:
    radial-gradient(130% 90% at 50% -20%, #33281D 0%, #1D1710 46%, #0D0A07 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: .3;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

/* -------------------------------------------------------------- layout -- */

.page {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.6vh, 16px);
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 880px;
  margin-inline: auto;
}

/* ----------------------------------------------------------- masthead -- */

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.masthead {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 16px;
  min-width: 0;
}

.backlink {
  font-size: 10px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--parchment-3);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color .2s, border-color .2s;
}
.backlink::before { content: '\27F5\2003'; }
.backlink:hover {
  color: var(--brass);
  border-bottom-color: color-mix(in srgb, var(--brass) 50%, transparent);
}

.title {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'SOFT' 50, 'opsz' 120, 'wght' 620;
  font-weight: 620;
  font-size: clamp(1.35rem, 3.2vw, 1.85rem);
  line-height: 1;
  margin: 0;
  letter-spacing: -.015em;
  text-shadow: 0 1px 0 #000, 0 0 34px rgba(199, 154, 69, .18);
}

.stamp {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--brass);
}
.stamp__rule {
  width: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass-2), transparent);
}

/* ------------------------------------------------------------- sticker -- */

/* Stuck on at a slight angle, the way a grade is stamped on a paper. The
   three colours are the only place difficulty is ever said in colour, so they
   have to read at a glance and mean nothing else on the page. */
.sticker {
  margin: 0;
  flex: 0 0 auto;
  padding: 6px 15px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--parchment-2);
  border-radius: 2px;
  transform: rotate(-1.6deg);
  box-shadow:
    0 6px 14px -8px rgba(0, 0, 0, .9),
    inset 0 0 0 1px rgba(255, 255, 255, .28);
}
.sticker[data-grade='easy']   { background: var(--verdigris); }
.sticker[data-grade='medium'] { background: var(--brass); }
.sticker[data-grade='hard']   { background: #C4574A; color: #1B0F0D; }

.shelfnote {
  margin: -2px 0 0;
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'ital' 1, 'wght' 500;
  font-style: italic;
  font-size: 13px;
  color: var(--parchment-3);
  text-align: center;
  max-width: 60ch;
}

/* --------------------------------------------------------------- board -- */

.board {
  display: grid;
  place-items: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: var(--board);
  aspect-ratio: 1;
  border: 2px solid var(--brass-2);
  border-radius: 2px;
  background: rgba(9, 7, 5, .45);
  box-shadow:
    0 24px 48px -28px rgba(0, 0, 0, .9),
    inset 0 0 60px -30px rgba(199, 154, 69, .35);
  overflow: hidden;
}

.cell {
  position: relative;
  font: inherit;
  padding: 0;
  margin: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: var(--parchment);
  background: transparent;
  border: 0;
  border-right: 1px solid rgba(199, 154, 69, .17);
  border-bottom: 1px solid rgba(199, 154, 69, .17);
  cursor: pointer;
  transition: background .12s;
  /* iOS puts a grey flash on every tap, which on a 81-cell grid reads as the
     board flickering rather than as a cell being chosen. */
  -webkit-tap-highlight-color: transparent;
}
/* The heavy rules between the boxes, drawn by the cells that sit against them. */
.cell.is-edge-r { border-right: 2px solid var(--brass-2); }
.cell.is-edge-b { border-bottom: 2px solid var(--brass-2); }

.cell__digit {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'SOFT' 50, 'wght' 500;
  font-size: calc(var(--cell) * .56);
  line-height: 1;
  color: var(--brass);
}

/* A given is the printed half of the puzzle: heavier, and not in brass, so
   what you have written is always distinguishable from what you were told. */
.cell.is-given .cell__digit {
  font-variation-settings: 'SOFT' 50, 'wght' 700;
  color: var(--parchment);
}
.cell.is-given { cursor: default; background: rgba(255, 255, 255, .022); }

.cell.is-peer { background: rgba(199, 154, 69, .13); }
.cell.is-same { background: rgba(199, 154, 69, .26); }
.cell.is-sel  { background: rgba(199, 154, 69, .34); }

.cell.is-sel::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--brass);
  pointer-events: none;
}

.cell.is-clash .cell__digit { color: var(--crimson); }
.cell.is-clash { background: rgba(169, 52, 43, .17); }

/* A hinted digit was not deduced and was not written, so it is neither brass
   nor parchment: it is the one colour on the board that means 'this is
   certain', and it is fixed, which the faint rule underneath says quietly. */
.cell.is-shown .cell__digit {
  font-variation-settings: 'SOFT' 50, 'wght' 600;
  color: var(--verdigris);
}
.cell.is-shown { cursor: default; background: rgba(63, 169, 122, .09); }
.cell.is-shown::before {
  content: '';
  position: absolute;
  left: 26%;
  right: 26%;
  bottom: 11%;
  border-bottom: 1px solid rgba(63, 169, 122, .5);
  pointer-events: none;
}

/* Marked by Check: wrong, though it breaks no rule you could see. Same crimson
   as a clash, because it means the same thing to whoever has to fix it, with a
   hatch behind it so the two are still tellable apart at a glance. */
.cell.is-wrong .cell__digit { color: var(--crimson); }
.cell.is-wrong {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(169, 52, 43, .26) 0 2px,
      rgba(169, 52, 43, .10) 2px 6px
    );
}

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

/* --------------------------------------------------------------- notes -- */

.cell__notes {
  position: absolute;
  inset: 8%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  pointer-events: none;
}
.cell__notes i {
  font-style: normal;
  font-size: calc(var(--cell) * .21);
  line-height: 1;
  color: var(--parchment-3);
  opacity: 0;
}
.cell__notes i.is-on { opacity: 1; }

/* A pencil mark for the digit under the cursor should stand out — that is
   what the highlight is for. */
.cell.is-peer .cell__notes i.is-on { color: var(--parchment-2); }

/* ----------------------------------------------------------------- pad -- */

.pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
  width: var(--board);
}

.padkey {
  position: relative;
  font: inherit;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: var(--parchment-2);
  background: rgba(255, 255, 255, .02);
  border: var(--shell);
  border-radius: 2px;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s, transform .08s;
}
.padkey b {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'wght' 600;
  font-size: calc(var(--cell) * .5);
  font-weight: 600;
  line-height: 1;
}
/* How many of that digit are still to be placed. Small, in the corner, and
   gone entirely once the digit is finished with. */
.padkey__left {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  line-height: 1;
  color: var(--brass-2);
}
.padkey:hover:not(.is-done) {
  color: var(--ink);
  background: var(--brass);
  border-color: var(--brass);
}
.padkey:active { transform: translateY(1px); }
.padkey:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.padkey.is-done { opacity: .3; }

/* In notes mode the pad is visibly a pencil, not a pen. */
body.is-noting .padkey {
  border-style: dashed;
  color: var(--parchment-3);
}
body.is-noting .padkey:hover:not(.is-done) { color: var(--ink); }

/* ------------------------------------------------------------- console -- */

.console {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(199, 154, 69, .16);
}

.counter { margin: 0; display: flex; align-items: baseline; gap: 10px; }
.counter__label {
  font-size: 10px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--parchment-3);
}
.counter b {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'wght' 600;
  font-size: 1.3rem;
  color: var(--parchment);
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Whatever Check just said. It sits on its own line under the buttons and
   takes the full width, so the row above it never reflows when it fills. */
.verdict {
  flex-basis: 100%;
  margin: 0;
  min-height: 1.2em;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--parchment-3);
  transition: color .18s;
}
.verdict[data-tone='bad']  { color: var(--crimson); }
.verdict[data-tone='good'] { color: var(--verdigris); }

.btn {
  font: inherit;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--parchment-2);
  background: rgba(255, 255, 255, .015);
  border: var(--shell);
  border-radius: 2px;
  padding: 9px 12px;
  cursor: pointer;
  transition: color .18s, background .18s, border-color .18s, transform .1s;
}
.btn:hover:not(:disabled) {
  color: var(--ink);
  background: var(--brass);
  border-color: var(--brass);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .3; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn[aria-pressed='false'] { color: var(--parchment-3); border-style: dashed; }

/* --------------------------------------------------------------- howto -- */

.howto {
  width: 100%;
  font-size: 12px;
  line-height: 1.65;
  color: var(--parchment-2);
}
.howto summary {
  cursor: pointer;
  list-style: none;
  font-size: 10px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--parchment-3);
  padding: 4px 0;
  transition: color .2s;
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: '\FF0B\2002'; color: var(--brass-2); }
.howto[open] summary::before { content: '\FF0D\2002'; }
.howto summary:hover { color: var(--brass); }
.howto ul { margin: 10px 0; padding-left: 1.1em; }
.howto li { margin-bottom: 5px; }
.howto b { color: var(--parchment); font-weight: 500; }
.howto kbd {
  font: inherit;
  font-size: 11px;
  padding: 1px 5px;
  color: var(--parchment);
  border: 1px solid rgba(199, 154, 69, .3);
  border-radius: 2px;
  background: rgba(0, 0, 0, .3);
}
.howto__note {
  color: var(--parchment-3);
  border-left: 1px solid var(--brass-2);
  padding-left: 12px;
  max-width: 62ch;
}

/* ----------------------------------------------------------------- win -- */

.win {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 8, 5, .72);
  backdrop-filter: blur(7px) saturate(.8);
  -webkit-backdrop-filter: blur(7px) saturate(.8);
  animation: fade .4s ease both;
}
.win.is-instant { animation: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.win__card {
  position: relative;
  width: min(400px, 100%);
  text-align: center;
  padding: 46px 30px 30px;
  color: #2A2117;
  border-radius: 3px;
  background:
    radial-gradient(120% 90% at 50% 0%, #FBF2DF 0%, #EFE1C4 60%, #E2D2B2 100%);
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, .8),
    inset 0 0 0 1px rgba(255, 255, 255, .5),
    inset 0 0 0 6px rgba(169, 52, 43, .07);
  animation: rise .5s cubic-bezier(.25, 1.2, .4, 1) both;
}
.win.is-instant .win__card { animation: none; }
@keyframes rise {
  from { opacity: 0; transform: translateY(22px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.seal {
  position: absolute;
  top: -26px;
  left: 50%;
  width: 62px;
  height: 62px;
  transform: translateX(-50%) rotate(-8deg);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: rgba(255, 226, 216, .78);
  font-size: 22px;
  background: radial-gradient(circle at 34% 28%, #C4463A, #8E2A22 62%, #6E1E18 100%);
  box-shadow:
    inset 0 -3px 8px rgba(0, 0, 0, .5),
    inset 0 3px 6px rgba(255, 255, 255, .25),
    0 8px 16px -6px rgba(0, 0, 0, .7);
  clip-path: polygon(
    50% 0%, 66% 6%, 82% 4%, 92% 18%, 100% 32%, 96% 50%, 100% 68%, 90% 82%,
    80% 96%, 62% 96%, 46% 100%, 30% 94%, 16% 90%, 8% 74%, 0% 56%, 4% 38%,
    2% 20%, 18% 10%, 34% 6%);
}

.win__card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'SOFT' 50, 'opsz' 140, 'wght' 700;
  font-size: 2.1rem;
  margin: 6px 0 4px;
  letter-spacing: -.01em;
}

.win__grade {
  margin: 0 0 16px;
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'ital' 1, 'wght' 500;
  font-style: italic;
  font-size: 1.15rem;
  letter-spacing: .04em;
  color: #7A6244;
}

.win__line { margin: 0 0 22px; font-size: 12px; line-height: 1.8; color: #574734; }
.win__line b { color: #2A2117; font-weight: 600; }

.win__next {
  margin: 0 0 22px;
  padding: 12px 0;
  border-top: 1px solid rgba(42, 33, 23, .16);
  border-bottom: 1px solid rgba(42, 33, 23, .16);
}
.win__next-label {
  display: block;
  font-size: 9px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: #8A7458;
  margin-bottom: 6px;
}
.win__clock {
  font-size: 1.5rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
  color: #2A2117;
}

.win__actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn--ink {
  color: #574734;
  border-color: rgba(42, 33, 23, .3);
  background: transparent;
}
.btn--ink:hover:not(:disabled) {
  background: #2A2117;
  border-color: #2A2117;
  color: #EFE1C4;
}

/* -------------------------------------------------------------- motion -- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (max-width: 620px) {
  :root { --board: min(96vw, 58vh, 460px); }
  .page { padding-inline: 8px; gap: 8px; }
  .topbar { justify-content: center; gap: 8px 14px; }
  .masthead { justify-content: center; gap: 4px 12px; }
  .stamp { justify-content: center; letter-spacing: .18em; }
  .stamp__rule { display: none; }
  .shelfnote { font-size: 12px; }
  .pad { gap: 3px; }
  .console { flex-direction: column; align-items: stretch; }
  .counter { justify-content: center; }
  .actions { justify-content: center; }
}

/* ---------------------------------------------------------------- ledger -- */

/* The written half of the page: what the game is, and the way out to the
   others. Below the fold by design — the game gets the first screen. */
.ledger {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px calc(56px + env(safe-area-inset-bottom));
  display: grid;
  gap: 34px;
  border-top: 1px solid rgba(199, 154, 69, .16);
  font-size: 13px;
  line-height: 1.85;
  color: var(--parchment-2);
}

.ledger h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'SOFT' 50, 'opsz' 90, 'wght' 600;
  font-weight: 600;
  font-size: 1.25rem;
  line-height: 1.2;
  margin: 0 0 14px;
  color: var(--parchment);
  letter-spacing: -.01em;
}

.ledger p { margin: 0 0 14px; }
.ledger p:last-child { margin-bottom: 0; }
.ledger strong { color: var(--parchment); font-weight: 500; }
.ledger em { color: var(--brass); font-style: italic; }

.ledger__more ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.ledger__more li {
  padding-left: 14px;
  border-left: 1px solid rgba(199, 154, 69, .22);
}
.ledger a {
  color: var(--brass);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.ledger a:hover { border-bottom-color: var(--brass); }
.ledger__home { margin-top: 18px; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }

/* Spans both columns: the legal line belongs to the page, not to either half
   of it. Quieter than the links above — it is there to be found, not read. */
.ledger__legal {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(199, 154, 69, .12);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.ledger__legal a { color: var(--parchment-3); }
.ledger__legal a:hover { color: var(--brass); }

@media (min-width: 760px) {
  .ledger { max-width: 940px; grid-template-columns: 1.7fr 1fr; gap: 48px; }
}
