/* SPELT — one stylesheet, no build step. */

:root {
  color-scheme: light dark;

  --bg: #f6f2ea;
  --surface: #fffdf8;
  --ink: #1c1a16;
  --muted: #6d6558;
  --line: #d9d1c1;
  --line-strong: #b9ae99;
  --slot: #e4dccb;
  --tile: #fffdf8;
  --tile-line: #c3b8a2;
  --tile-shadow: rgba(48, 38, 20, .22);
  --accent: #1f6f4f;
  --accent-soft: #dcece2;
  --focus: #2b6cb0;
  --danger: #a63d2f;

  --cell: clamp(2.75rem, 16.5vw, 4rem);
  --gap: clamp(.3rem, 1.4vw, .5rem);
  --radius: 10px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1d2026;
    --ink: #ece9e2;
    --muted: #9a9488;
    --line: #333842;
    --line-strong: #4a515e;
    --slot: #0e1013;
    --tile: #2b313a;
    --tile-line: #454d59;
    --tile-shadow: rgba(0, 0, 0, .5);
    --accent: #6cc39b;
    --accent-soft: #1e3830;
    --focus: #7fb3ff;
    --danger: #e2836f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 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) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 50%; translate: -50% -150%;
  background: var(--surface); color: var(--ink); z-index: 20;
  padding: .5rem 1rem; border-radius: 0 0 var(--radius) var(--radius);
  border: 1px solid var(--line); text-decoration: none;
}
.skip-link:focus { translate: -50% 0; }

/* ---------- chrome ---------- */

.topbar {
  width: 100%;
  max-width: 34rem;
  display: grid;
  grid-template-columns: var(--tap) 1fr auto;
  align-items: center;
  gap: .25rem;
  padding: .35rem .5rem;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  margin: 0;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 650;
  /* Set in the markup as "Spelt" and capitalised here: an all-caps wordmark in
     the HTML gets spelled out letter by letter by some screen readers. */
  text-transform: uppercase;
  letter-spacing: .22em;
  text-indent: .22em;
}

.topbar-end { display: flex; justify-content: flex-end; }

.icon-button {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.icon-button:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.icon-button svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sheet-head .icon-button { font-size: 1.15rem; }

main {
  width: 100%;
  max-width: 34rem;
  padding: .5rem .75rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}

.puzzle-head {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: .5rem;
  color: var(--muted);
  font-size: .85rem;
  padding: .25rem 0;
}
.puzzle-no { font-weight: 650; color: var(--ink); }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; }
.archive-tag {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 .5rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ---------- grid ---------- */

.grid { display: flex; flex-direction: column; gap: var(--gap); }

.grid-row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell)) 1.5rem;
  gap: var(--gap);
  align-items: center;
}

/* Letters are always uppercase, which is the cheapest way to keep I/l/1 and
   O/0 from ever being confusable on a tile (GDD §10). */
.cell {
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  font-size: calc(var(--cell) * .52);
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Given letters sit flat on the board; only tiles the player controls are
   raised. The difference is what tells you at a glance what you can move. */
.cell.fixed {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

/* Empty slots read as wells cut into the board, so the eye goes to the holes
   rather than to the letters already printed. */
.cell.slot {
  background: var(--slot);
  border: 1px solid color-mix(in srgb, var(--line-strong) 60%, transparent);
  box-shadow: inset 0 2px 5px color-mix(in srgb, var(--tile-shadow) 65%, transparent);
  color: var(--ink);
  padding: 0;
  font: inherit;
  font-size: calc(var(--cell) * .52);
  font-weight: 600;
  cursor: pointer;
  touch-action: none;
}

.cell.slot.filled {
  background: var(--tile);
  border-color: var(--tile-line);
  box-shadow: 0 2px 0 var(--tile-line), 0 3px 6px color-mix(in srgb, var(--tile-shadow) 40%, transparent);
}

.cell.slot.selected {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}
/* Where the next typed letter will go, as opposed to a slot the player picked.
   Quieter on purpose: it is a caret, not a target. */
.cell.slot.caret {
  outline: 2px dashed color-mix(in srgb, var(--focus) 60%, transparent);
  outline-offset: 1px;
}

.cell.slot.target {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.cell.slot:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.cell.hinted { animation: pop .45s ease; }
.cell.reject { animation: shake .3s ease; }

.row-mark {
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  color: var(--accent);
  opacity: 0;
  scale: .6;
  transition: opacity .18s ease, scale .18s ease;
}
.row-mark.on { opacity: 1; scale: 1; }
.row-mark svg { width: 100%; height: 100%; }

/* ---------- pool ---------- */

.pool-head {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-top: .25rem;
}
.pool-title {
  margin: 0;
  font-size: .75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}
.pool-count { color: var(--muted); font-size: .8rem; margin-left: auto; }

.pool {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: .6rem;
  border: 1px dashed var(--line-strong);
  border-radius: calc(var(--radius) + 4px);
  min-height: calc(var(--tap) + 1.2rem);
}
/* One line per row, each centred on its own: a nine-tile Saturday reads 5 + 4
   with both lines centred, instead of a short line hugging the left edge. */
.pool-row {
  display: flex;
  width: 100%;
  justify-content: center;
  gap: var(--gap);
}
.pool.stalled {
  border-style: solid;
  border-color: var(--danger);
}

.tile {
  /* Capped at --cell, and never so wide that a full row overflows the pool:
     the lines can no longer re-wrap, so they must always fit. */
  width: min(var(--cell), calc((100% - (var(--pool-cols, 5) - 1) * var(--gap)) / var(--pool-cols, 5)));
  aspect-ratio: 1;
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--tile-line);
  background: var(--tile);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--tile-line), 0 3px 6px color-mix(in srgb, var(--tile-shadow) 40%, transparent);
  font: inherit;
  font-size: calc(var(--cell) * .52);
  font-weight: 600;
  line-height: 1;
  cursor: grab;
  transition: translate .12s ease, box-shadow .12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.tile.selected {
  translate: 0 -6px;
  box-shadow: 0 6px 0 var(--tile-line), 0 8px 14px color-mix(in srgb, var(--tile-shadow) 50%, transparent);
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* A ghost, not a hole: the letter stays readable so the pool says at a glance
   what has been spent, which is the whole point of the fixed layout (GDD §6). */
.tile.spent {
  background: transparent;
  border-style: dashed;
  border-color: var(--line-strong);
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  box-shadow: none;
  cursor: default;
}

.tile.dragging { opacity: .25; }

.drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.drag-ghost {
  position: absolute;
  translate: -50% -50%;
  scale: 1.1;
  box-shadow: 0 10px 20px color-mix(in srgb, var(--tile-shadow) 70%, transparent);
}

/* ---------- buttons & sheets ---------- */

.actions { display: flex; gap: .5rem; margin-top: .25rem; }

.button {
  min-height: var(--tap);
  padding: 0 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { border-color: var(--ink); }
.button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .button.primary { color: #0e1a15; } }
.button.ghost { background: none; }

.sheet {
  width: min(30rem, calc(100vw - 1.5rem));
  max-height: 85svh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
}
.sheet::backdrop { background: rgba(10, 8, 4, .45); backdrop-filter: blur(2px); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .5rem .5rem 1rem;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 1.05rem; }

.sheet-body { padding: 1rem; overflow-y: auto; max-height: calc(85svh - 3.5rem); }
.sheet-body > p:first-child { margin-top: 0; }

/* How to play: a picture of a board mid-solve does the explaining, so one line
   of copy is all the text the sheet needs. */
.help { text-align: center; }
.help .lede { font-size: 1.05rem; line-height: 1.45; margin: .7rem 0; }
.help .setting { text-align: left; }

.demo { display: grid; justify-items: center; gap: .25rem; margin: 0 0 .3rem; }
.demo-grid { display: grid; gap: .25rem; }
/* Six columns, the last one the ✓ gutter, exactly as .grid-row is laid out. */
.demo-row { display: grid; grid-template-columns: repeat(5, 2.1rem) 1.2rem; gap: .25rem; align-items: center; }
.demo-mark { display: grid; place-items: center; width: 1.2rem; height: 1.2rem; color: var(--accent); }
.demo-mark svg { width: 100%; height: 100%; }
/* The pool sits in its own dashed tray, exactly as it does in the puzzle, so the
   example reads as a picture of the real board. */
.demo-pool {
  display: flex;
  gap: .25rem;
  margin-top: .5rem;
  margin-right: 1.45rem; /* the ✓ gutter, so the tray centres under the letters */
  padding: .4rem .5rem;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
}
.demo figcaption { margin-top: .85rem; }
.demo-cell {
  width: 2.1rem;
  height: 2.1rem;
  aspect-ratio: auto; /* .tile's square sizing must not leak into the demo figure */
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
}
.demo-cell.empty {
  background: var(--slot);
  border-color: color-mix(in srgb, var(--line-strong) 60%, transparent);
  box-shadow: inset 0 2px 4px color-mix(in srgb, var(--tile-shadow) 60%, transparent);
}
/* Same raise as a real tile, in the pool or dropped into a slot, so the D in
   CANDY reads as something the player put there rather than a printed letter. */
.demo-cell.tile {
  background: var(--tile);
  border-color: var(--tile-line);
  box-shadow: 0 2px 0 var(--tile-line), 0 3px 6px color-mix(in srgb, var(--tile-shadow) 40%, transparent);
}

/* The D keeps its place in the pool as a ghost, as .tile.spent does, so the
   letter on the board is visibly the one that left the tray. */
.demo-cell.tile.spent {
  background: transparent;
  border-style: dashed;
  border-color: var(--line-strong);
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  box-shadow: none;
}

.setting { border-top: 1px solid var(--line); margin-top: .85rem; padding-top: .7rem; }
.switch { display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; }
.switch input { width: 1.15rem; height: 1.15rem; margin-top: .2rem; accent-color: var(--accent); }
.switch + .switch { margin-top: .6rem; }

/* A button that reads as a link, because it opens a sheet rather than a page. */
.linkish {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.linkish:hover { color: var(--ink); }

/* ---------- the drop box ---------- */

.field { display: block; margin-bottom: .8rem; }
.field > span { display: block; margin-bottom: .25rem; }
.field textarea, .field input, .field select {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: .5rem .6rem; min-height: var(--tap);
}
.field textarea { resize: vertical; min-height: 6rem; line-height: 1.45; }
.field :is(textarea, input, select):focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus);
}
.fb-note { min-height: 1.2rem; margin: .2rem 0 .6rem; font-size: .85rem; color: var(--muted); }
.fb-note.bad { color: var(--danger); }

/* ---------- the day's readout ---------- */

.field-line { margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.field-tail { display: block; margin-top: .15rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- footer ---------- */

.sitefoot {
  width: 100%;
  max-width: 34rem;
  margin-top: auto;
  padding: 1rem .75rem 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
}
.sitefoot p { margin: 0; }
.sitefoot a { color: inherit; text-underline-offset: .2em; }
.sitefoot a:hover { color: var(--ink); }

/* ---------- stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4.5rem, 1fr));
  gap: .5rem;
  margin-bottom: 1rem;
}
.stat { text-align: center; }
.stat b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.hist { display: flex; flex-direction: column; gap: .25rem; }
.hist-row { display: grid; grid-template-columns: 2rem 1fr; align-items: center; gap: .5rem; font-size: .8rem; }
.hist-bar {
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 0 .35rem;
  min-width: 1.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .hist-bar { color: #0e1a15; } }
.hist-bar.empty { background: var(--line); color: var(--muted); }

.share-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre;
  line-height: 1.3;
  letter-spacing: .1em;
  font-size: clamp(.75rem, 3.6vw, .95rem);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem;
  margin: .75rem 0;
  overflow-x: auto;
}

.archive-list { display: flex; flex-direction: column; gap: .35rem; }
.archive-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  min-height: var(--tap);
  padding: .35rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.archive-item:hover { border-color: var(--line-strong); }
.archive-item[aria-current="true"] { border-color: var(--accent); }
.archive-item .no { font-weight: 650; min-width: 3.5rem; }
.archive-item .when { color: var(--muted); font-size: .85rem; }
.archive-item .state { margin-left: auto; color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  translate: -50% 0;
  background: var(--ink);
  color: var(--bg);
  padding: .55rem 1rem;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 40;
  animation: fade-in .15s ease;
}

@keyframes pop { 0% { scale: .7; } 60% { scale: 1.12; } 100% { scale: 1; } }
@keyframes shake {
  0%, 100% { translate: 0; } 20% { translate: -5px; } 40% { translate: 5px; }
  60% { translate: -3px; } 80% { translate: 3px; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

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

@media (min-width: 30rem) {
  :root { --cell: 3.6rem; }
}
