/* Wordsnake — mobile-first. Layout uses dvh so mobile browser chrome can't
   crop the board, and the grid disables touch scrolling so swipes draw. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d2021;
  --muted: #6b6f72;
  --line: #ddd8ce;
  --cell: #ffffff;
  --cell-ink: #1d2021;
  --start-ring: #1d2021;
  --draft: #4a4e51;
  --bad: #c1121f;
  --radius: 12px;

  /* Okabe–Ito: colourblind-safe. Colour carries the word structure here, so it
     has to survive deuteranopia and protanopia, not just look nice. */
  --w0: #0072b2;
  --w1: #e69f00;
  --w2: #009e73;
  --w3: #cc79a7;
  --w4: #d55e00;
  --w5: #56b4e9;
  --w6: #8b6f22;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --surface: #1f2224;
    --ink: #ecebe6;
    --muted: #9aa0a4;
    --line: #34383b;
    --cell: #262a2d;
    --cell-ink: #ecebe6;
    --start-ring: #ecebe6;
    --draft: #b8bec2;
    --bad: #ff6b6b;
    --w6: #d9b95c;
  }
}

* {
  box-sizing: border-box;
}

/* A `display` rule on a class beats the [hidden] UA default, so state it
   explicitly — several elements here are toggled by the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

/* ---- header ---- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
}

h1 {
  font-size: 20px;
  letter-spacing: -0.02em;
  margin: 0;
}

h1 span {
  color: var(--w2);
}

.tiers {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.tiers button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.tiers button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* ---- subhead + status ---- */

.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  min-height: 30px;
}

.subhead .left {
  margin-left: auto;
  white-space: nowrap;
}

.subhead strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.daily-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daily-label b {
  color: var(--ink);
  font-weight: 650;
}

.daily-label .done {
  color: var(--w2);
  font-weight: 650;
}

.status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}

.status strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#message {
  font-weight: 600;
}

#message.bad {
  color: var(--bad);
}

#message.good {
  color: var(--w2);
}

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

.board-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap, 6px);
  touch-action: none; /* swipes draw words, they must not scroll the page */
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--cell);
  color: var(--cell-ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--letter-size, 22px);
  font-weight: 650;
  letter-spacing: 0.02em;
  z-index: 1;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.cell.used {
  border-color: transparent;
  color: #fff;
  background: var(--word-color);
}

.cell.draft {
  background: var(--draft);
  color: var(--bg);
  border-color: transparent;
}

.cell.head {
  transform: scale(1.06);
}

/* The live pivot: where the next word must start. */
.cell.pivot::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px dashed currentColor;
  border-radius: calc(var(--radius) - 3px);
  opacity: 0.55;
}

.cell.open {
  border-color: var(--muted);
  border-style: dashed;
}

.cell.start-marker::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--start-ring);
  opacity: 0.8;
}

/* Each cell pops in turn along the finished snake. */
.cell.pop {
  animation: pop 0.34s ease;
}

@keyframes pop {
  40% {
    transform: scale(1.18);
  }
}

#board.shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

/* Connector lines drawn under the cells, so the snake reads as one path. */
#links {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

/* Full-bleed confetti layer. Never intercepts input. */
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
}

/* ---- word chain ---- */

/* Fixed height, not min-height: if this grew as words were found it would eat
   into the board's space and resize the squares mid-game. */
#chain {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  height: 58px;
  overflow-y: auto;
  align-content: flex-start;
}

.chip {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--word-color);
}

.chip.pending {
  background: none;
  color: var(--muted);
  border: 1px dashed var(--line);
}

/* ---- controls ---- */

.controls {
  flex: none;
  display: flex;
  gap: 8px;
}

.controls button {
  flex: 1;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.controls button:disabled {
  opacity: 0.4;
  cursor: default;
}

.controls button.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

/* ---- dialogs ---- */

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  padding: 20px;
  max-width: 340px;
  width: calc(100% - 40px);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

dialog p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

dialog .hint-word {
  color: var(--ink);
  font-weight: 650;
}

dialog menu {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
}

dialog menu button {
  flex: 1;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

dialog menu button.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.slots code {
  display: block;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
}
