/* Wells — mobile first. No web fonts, no frameworks, no network beyond the
   puzzle file, so the page is usable on a phone on a bad connection. */

:root {
  --bg: #071624;
  --panel: #0e2739;
  --line: #1d4159;
  --ink: #e8f4fb;
  --dim: #8fb3c9;
  --accent: #38bdf8;
  --warn: #f87171;
  --given: #143349;
  --cell: 1;
  /* A well is a hole, so it is drawn as a hole: near-black in both themes, with
     a bright ringed dot in it. The point of the change is that a well must not
     be mistakeable for a number, so it gets its own colour as well as its own
     shape rather than being one more square in the value ramp. */
  --wellbg: #03101a;
  --wellink: #7dd3fc;
  --d0: #0369a1;
  --d1: #0e7490;
  --d2: #0f766e;
  --d3: #3f6212;
  --d4: #854d0e;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 8px);
  overscroll-behavior: none;
}

.bar {
  width: 100%;
  max-width: 440px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px 4px;
  border-bottom: 1px solid var(--line);
}

.bar h1 {
  font-size: 1.35rem;
  letter-spacing: 0.34em;
  margin: 0 0 0 0.34em;
  font-weight: 800;
}

.icon {
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 1.25rem;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  cursor: pointer;
}
.icon:active {
  background: var(--panel);
}

.rule {
  margin: 10px 0 6px;
  color: var(--dim);
  font-size: 0.95rem;
  text-align: center;
  max-width: 440px;
}
.rule b {
  color: var(--accent);
}

main {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.statusline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.lives {
  letter-spacing: 2px;
}
.lives .gone {
  opacity: 0.22;
}

.board {
  display: grid;
  gap: 4px;
  width: 100%;
  aspect-ratio: 1;
  touch-action: manipulation;
}

.cell {
  border: 0;
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: clamp(1.1rem, 7.5vw, 2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}
/* Givens keep a ring so that, once the board is full, a player can still see
   which squares were handed to them and which they worked out - the same
   distinction the share grid draws. */
.cell.given {
  background: var(--given);
  color: var(--dim);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
}
.cell.sel {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.cell.well {
  background: var(--wellbg);
  color: var(--wellink);
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.35);
}
/* A printed well keeps the givens ring, otherwise the one distinction the
   board draws - handed to you vs worked out - vanishes on exactly the squares
   the puzzle is about. */
.cell.given.well {
  color: #4a9fd0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
}
.cell.v1 { background: var(--d1); color: #fff; }
.cell.v2 { background: var(--d2); color: #fff; }
.cell.v3 { background: var(--d3); color: #fff; }
.cell.v4 { background: var(--d4); color: #fff; }
.cell.bad {
  animation: shake 0.28s ease;
  background: var(--warn) !important;
  color: #350a0a !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .cell.bad { animation: none; }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.key {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 0;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
}
.key.well {
  background: var(--wellbg);
  color: var(--wellink);
  border-color: rgba(125, 211, 252, 0.4);
}
/* The mark is sized in em so one definition serves the 6x6 board, the 3x3
   worked example and the keypad without three sets of magic numbers. */
.wellmark {
  width: 1.22em;
  height: 1.22em;
  display: block;
}
.key .wellmark {
  width: 1.3em;
  height: 1.3em;
  margin: 0 auto;
}
.wellword {
  display: inline-block;
  vertical-align: -0.18em;
  width: 1.15em;
  height: 1.15em;
  color: var(--accent);
}
.wellword .wellmark {
  width: 100%;
  height: 100%;
}
.key:active {
  background: var(--line);
}
.key[disabled] {
  opacity: 0.35;
}

.message {
  min-height: 1.3em;
  margin: 0;
  text-align: center;
  color: var(--dim);
  font-size: 0.9rem;
}

.panel {
  width: 100%;
  max-width: 440px;
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}
.panel h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}
.endgrid {
  font-size: 1.05rem;
  line-height: 1.15;
  margin: 6px 0 10px;
  font-family: system-ui, sans-serif;
}
.endline {
  margin: 0 0 12px;
  color: var(--dim);
}
.countdown {
  color: var(--dim);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.copynote {
  color: var(--accent);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 8px 0 0;
}

.primary {
  background: var(--accent);
  color: #04222f;
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

dialog {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 420px;
  width: calc(100% - 28px);
  padding: 18px;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}
dialog h2 {
  margin-top: 0;
}
dialog p,
dialog li {
  color: var(--dim);
  line-height: 1.45;
}
dialog .big {
  color: var(--ink);
  font-size: 1.05rem;
}
dialog ul {
  padding-left: 1.1rem;
}

.example {
  margin: 14px 0;
}
.board.mini {
  gap: 3px;
  width: 190px;
  margin: 0 auto;
}
.board.mini .cell {
  font-size: 1rem;
  border-radius: 6px;
}
figcaption {
  color: var(--dim);
  font-size: 0.85rem;
  margin-top: 8px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.stat b {
  display: block;
  font-size: 1.5rem;
}
.stat span {
  color: var(--dim);
  font-size: 0.7rem;
}
.fineprint {
  font-size: 0.78rem;
}

footer {
  margin-top: auto;
  padding-top: 18px;
  color: var(--dim);
  font-size: 0.78rem;
  text-align: center;
  max-width: 440px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f8fc;
    --panel: #ffffff;
    --line: #cfe0ec;
    --ink: #0b2233;
    --dim: #52738a;
    --given: #dfeaf3;
    /* Kept dark in the light theme too: a well is a hole in the board, and a
       pale hole is a contradiction the eye has to work out. */
    --wellbg: #0b2233;
    --wellink: #9adcfb;
  }
  .primary {
    color: #04222f;
  }
}
