:root {
  --bg: #ffffff;
  --fg: #171717;
  --muted: #737373;
  --faint: #c2c2c2;
  --line: #e5e5e5;
  --soft: #f5f5f4;
  --cell: #ffffff;
  --block: #1c1917;
  --grid-line: #a8a29e;
  --word: #a7d8ff;
  --cross: #dcefff;
  --cur: #ffda00;
  --shade: #e7e5e4;
  --ok: #1d4ed8;
  --bad: #dc2626;
  --key: #e7e5e4;
  --key-fg: #171717;
  --serif: Charter, "Iowan Old Style", "Source Serif 4", Georgia, serif;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171717;
    --fg: #f5f5f4;
    --muted: #a3a3a3;
    --faint: #565656;
    --line: #333;
    --soft: #262626;
    --cell: #2a2a2a;
    --block: #000;
    --grid-line: #57534e;
    --word: #1f4f78;
    --cross: #1c2a38;
    --cur: #b38f00;
    --shade: #44403c;
    --ok: #93c5fd;
    --bad: #f87171;
    --key: #404040;
    --key-fg: #f5f5f4;
  }
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}
body {
  background: var(--bg);
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
a {
  color: inherit;
}

/* Home */
.home {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}
.home h1 {
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.home .sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 15px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
}
.card:hover {
  background: var(--soft);
}
.card svg {
  width: 56px;
  height: 56px;
  flex: none;
}
.card b {
  display: block;
  font-size: 15px;
  line-height: 1.25;
}
.card span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.card .state {
  color: var(--fg);
}
.empty {
  color: var(--muted);
}

/* Play */
.game {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  /* The bar's contents line up with the page below. The player sets the exact sides to the grid and the lists. */
  padding: 10px max(16px, calc((100% - 1232px) / 2));
  min-height: 60px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.back {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 32px;
  /* The chevron sits in the bar's margin, so the title lines up with the grid. */
  margin-left: -34px;
  margin-right: 6px;
  border-radius: 8px;
  color: var(--muted);
}
.back:hover {
  background: var(--soft);
  color: var(--fg);
}
.back svg {
  width: 18px;
  height: 18px;
}
.ttl {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}
.ttl b {
  display: block;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ttl span {
  display: block;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  /* The last word lines up with the edge of the lists. */
  margin-right: -10px;
}
.tools > button,
.dd > summary {
  display: flex;
  align-items: center;
  height: 34px;
  font-size: 15px;
  font-weight: 500;
  padding: 0 10px;
  border-radius: 8px;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.dd > summary::-webkit-details-marker {
  display: none;
}
.tools > button:hover,
.dd > summary:hover,
.dd[open] > summary {
  background: var(--soft);
}
.timer {
  justify-content: flex-end;
  gap: 7px;
  font-variant-numeric: tabular-nums;
  /* Room for "59:59", so the buttons beside it do not move as the time grows. */
  min-width: 76px;
}
.timer svg {
  flex: none;
  /* As tall as the digits, and level with them. */
  width: 11px;
  height: 11px;
  color: var(--muted);
}
/* Check, Reveal and More open menus: a small chevron says so. */
.dd > summary {
  gap: 3px;
}
.caret {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--muted);
}
.dd[open] .caret {
  transform: rotate(180deg);
}
/* A setting in a menu: a check mark when on. */
[data-set].on::after {
  content: " ✓";
}
.rebus-on {
  background: var(--cur) !important;
  color: #171717;
}
.dd {
  position: relative;
}
.dd > div {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  min-width: 150px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.12);
}
.dd > div button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}
.dd > div button:hover {
  background: var(--soft);
}
.dd > div hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}

.play {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  gap: 32px;
  padding: 20px 16px 16px;
  justify-content: center;
  width: 100%;
  max-width: 1264px;
  margin: 0 auto;
  box-sizing: border-box;
}
.board {
  flex: 1 1 0;
  min-width: 0;
  /* The grid never gets huge: about 590px for a 15x15, a little more for a bigger grid. A small grid's squares are 88px at most. */
  max-width: min(calc(440px + var(--cols, 15) * 10px), calc(var(--cols, 15) * 88px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cluebar {
  flex: none;
  display: flex;
  align-items: stretch;
  background: var(--cross);
  border-radius: 8px;
  min-height: 48px;
}
.cluebar > button {
  flex: none;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  opacity: 0.6;
}
.cluebar > button:hover {
  opacity: 1;
}
.cluebar > button svg {
  width: 18px;
  height: 18px;
}
.cb-text {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 16px;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
}
/* A long clue wraps to 3 lines at most. */
.cb-text span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.cb-text b {
  flex: none;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
/* The player sets the grid's height to fit the screen. */
.gridwrap {
  flex: none;
  position: relative;
}
.gridwrap svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.paused {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  z-index: 5;
}
.btn {
  background: var(--fg);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
}
.btn.ghost {
  background: none;
  color: var(--fg);
  border: 1px solid var(--line);
}

/* Grid */
.c {
  fill: var(--cell);
}
.c.sh {
  fill: var(--shade);
}
.c.word {
  fill: var(--word);
}
.c.cur {
  fill: var(--cur);
}
.blk {
  fill: var(--block);
}
.gl {
  stroke: var(--grid-line);
  stroke-width: 1;
}
.edge {
  fill: none;
  stroke: var(--block);
  stroke-width: 3;
}
.wall {
  stroke: var(--block);
  stroke-width: 4;
  stroke-linecap: square;
}
.num {
  font-size: var(--num, 11px);
  fill: var(--fg);
  opacity: 0.75;
}
.let {
  font-size: 23px;
  fill: var(--fg);
  text-anchor: middle;
  font-weight: 500;
}
.let.ok,
.let.rev {
  fill: var(--ok);
}
.ring {
  fill: none;
  stroke: var(--grid-line);
  stroke-width: 1;
}
.slash {
  stroke: var(--bad);
  stroke-width: 2;
  display: none;
}
.slash.on {
  display: inline;
}
.spr {
  font-size: 26px;
  text-anchor: middle;
}
.spr.under {
  opacity: 0.3;
}

/* Clue lists */
/* The lists are as tall as the clue bar and the grid (the player sets the height), and scroll inside. */
.lists {
  flex: 0 1 480px;
  min-width: 320px;
  display: flex;
  gap: 20px;
  min-height: 0;
}
.fitted .lists {
  flex: 1 1 480px;
  max-width: 560px;
}
.lists > div {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* Set like a newspaper's clue column: a bold serif head over a heavy rule. The clues stay sans, for scanning. */
.lists h3 {
  margin: 0;
  /* Lines up with the clue numbers below. */
  padding: 0 8px 6px;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  line-height: 18px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg);
  border-bottom: 2px solid var(--fg);
  flex: none;
}
.lists ol {
  list-style: none;
  margin: 0;
  padding: 6px 0 0;
  overflow-y: auto;
  scroll-padding-block: 6px;
  /* No scrollbar gutter: the player draws a thin bar over the list's edge instead (.thumb). */
  scrollbar-width: none;
  flex: 1;
  min-height: 0;
}
.lists ol::-webkit-scrollbar {
  display: none;
}
.lists > div {
  position: relative;
}
.thumb {
  position: absolute;
  right: 1px;
  width: 5px;
  border-radius: 3px;
  background: var(--muted);
  opacity: 0.55;
  pointer-events: none;
  display: none;
}
.thumb.on {
  display: block;
}
.lists li {
  display: flex;
  gap: 8px;
  padding: 3px 8px;
  font-size: 14.5px;
  line-height: 1.3;
  border-radius: 4px;
  cursor: pointer;
}
.lists li:hover {
  background: var(--soft);
}
.lists li b {
  flex: none;
  min-width: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/* Filled-in clues fade well back, so the ones left to solve stand out. */
.lists li.full {
  color: var(--faint);
}
/* The crossing clue: the other answer through the current square. */
.lists li.x {
  background: var(--cross);
}
.lists li.on {
  background: var(--word);
  color: var(--fg);
}

/* On-screen keyboard */
.kb {
  display: none;
  flex: none;
  padding: 6px 3px calc(6px + env(safe-area-inset-bottom));
  background: var(--soft);
  user-select: none;
  -webkit-user-select: none;
}
.kb .row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 6px;
}
.kb .row:last-child {
  margin-bottom: 0;
}
.kb button {
  flex: 1 1 0;
  max-width: 44px;
  height: 46px;
  border-radius: 6px;
  background: var(--key);
  color: var(--key-fg);
  font-size: 19px;
  font-weight: 500;
}
.kb button.wide {
  flex: 1.6 1 0;
  max-width: 68px;
  font-size: 13px;
}
.kb button:active {
  filter: brightness(0.85);
}

/* Dialog */
.dlg {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(0 0 0 / 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dlg > div {
  background: var(--bg);
  border-radius: 16px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.dlg h2 {
  margin: 0 0 6px;
  font-size: 22px;
}
.dlg p {
  white-space: pre-line;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}
/* The solved popup: the time is the hero, two main buttons, then a quiet row of links. */
.won > div {
  position: relative;
  padding: 28px 24px 20px;
}
.won .x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.won .x svg {
  width: 20px;
  height: 20px;
  display: block;
}
/* "SOLVED" drawn like the Swords wordmark: one letter per square, the first one filled. */
.won h2 {
  display: flex;
  justify-content: center;
  margin: 0 0 6px;
}
.won h2 i {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-left: -2px;
  border: 2px solid var(--fg);
  font-style: normal;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
}
.won h2 i:first-child {
  margin-left: 0;
  background: var(--fg);
  color: var(--bg);
}
.won .time {
  margin: 2px 0 0;
  color: var(--fg);
  font-size: 44px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.won .sub {
  margin: 4px 0 0;
}
.won .note {
  margin: 10px 0 0;
  font-style: italic;
}
.won .wide {
  display: block;
  width: 100%;
  margin-top: 10px;
}
.won [data-won="share"] {
  margin-top: 20px;
}
.won .more {
  margin: 16px 0 0;
  font-size: 13px;
}
.won .more a {
  color: var(--muted);
}
.dlg .acts {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
/* The puzzle's note, under the grid: small, italic and muted. 3 lines at most; "more" opens all of it. */
.notes {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  font-style: italic;
  padding: 0 2px;
  flex: none;
  overflow-wrap: anywhere;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.notes p {
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.notes .more {
  flex: none;
  font: inherit;
  font-style: normal;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.notes .more[hidden] {
  display: none;
}
.notes.off {
  display: none;
}

/* Big screens: more room at the sides, so the page does not run edge to edge. */
@media (min-width: 1100px) {
  /* The grid and lists sit in the middle of the screen, side to side, with room on both sides. */
  .play {
    padding: 28px 48px 24px;
    gap: 40px;
    max-width: 1220px;
  }
}

/* Phones and touch screens: grid, then the clue bar, then the keyboard. No clue lists. */
@media (max-width: 820px), (pointer: coarse) and (max-width: 1100px) {
  .lists {
    display: none;
  }
  /* The on-screen keyboard: phones and tablets only (body class kb-device, set by the player). */
  .kb-device .kb {
    display: block;
  }
  .play {
    padding: 6px 6px 0;
  }
  /* The grid on top, the note under it, and the clue bar at the foot, over the keyboard. */
  .board {
    gap: 6px;
    align-self: stretch;
  }
  .cluebar {
    order: 2;
    margin: auto -6px 0;
    border-radius: 0;
    min-height: 56px;
  }
  .notes {
    order: 1;
    padding: 2px 4px;
  }
  .bar {
    padding: 6px 8px;
    gap: 6px;
    min-height: 0;
  }
  .back {
    margin-left: -4px;
    margin-right: 0;
  }
  .tools {
    margin-right: -7px;
  }
  .tools > button,
  .dd > summary {
    padding: 0 7px;
    font-size: 13px;
  }
  .timer {
    min-width: 62px;
    gap: 5px;
  }
}

/* Newsletter signup */
.signup {
  margin-top: 32px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.signup label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 10px;
}
.signup > div {
  display: flex;
  gap: 8px;
}
.signup input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
}

/* Only the square itself takes clicks: a letter, number or mark on top lets them through. */
.gridwrap svg text,
.gridwrap svg circle,
.gridwrap svg line,
.gridwrap svg path {
  pointer-events: none;
}

/* A puzzle's ending (`ending` in the puzzle file): squares that light up, and effects over the page. */
.c.lit {
  fill: var(--cur);
}
.fx {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}
.fx i {
  position: absolute;
  font-style: normal;
  line-height: 1;
  will-change: transform;
}
.fx .paper {
  width: 9px;
  height: 14px;
  border-radius: 2px;
}
.fx .fall {
  top: -60px;
  animation: fx-fall linear both;
}
.fx .burst {
  animation: fx-burst 1.6s cubic-bezier(0.15, 0.7, 0.3, 1) both;
}
@keyframes fx-fall {
  to {
    transform: translate(var(--drift), 110vh) rotate(var(--spin));
  }
}
@keyframes fx-burst {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--spin)) scale(1);
    opacity: 0;
  }
}
.c.wave {
  animation: fx-wave 0.6s ease-out both;
}
@keyframes fx-wave {
  40% {
    fill: var(--cur);
  }
}

/* A puzzle's scene (`ending.scene`): drawings over the grid after the solve, and the line under the grid. */
.scn * {
  pointer-events: none;
}
.scn-gap {
  fill: transparent;
}
.scn-line {
  fill: none;
  stroke: #d92d20;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.scn-img,
.let {
  transform-box: fill-box;
  transform-origin: center;
}
.scn-cap {
  text-anchor: middle;
  dominant-baseline: central;
  font-weight: 700;
  fill: var(--fg);
  stroke: var(--cell);
  paint-order: stroke;
  stroke-linejoin: round;
}
.let.onblk {
  fill: #fff;
}
.endbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.endbar[hidden] {
  display: none;
}
.endbar button {
  flex: none;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.endbar button[hidden] {
  display: none;
}

/* The paused grid. The card with Resume floats over a cover: the grid as coarse pixels, or a frosted blur. */
.paused > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.pz-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 28px;
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 8px 32px rgb(0 0 0 / 0.18);
  font-weight: 600;
}
.paused {
  background: none;
}
/* The paused clue bar: the clue as a row of small squares. */
.pz-strip {
  display: flex;
  flex-wrap: wrap;
  column-gap: 11px;
  overflow: hidden;
  max-height: 22px;
}
.pz-strip > span {
  display: flex;
  gap: 2px;
}
.pz-strip i {
  width: 9px;
  height: 9px;
}

/* Pausing: each pixel pops in at its own moment, and pops out the same way on resume. */
.paused > svg rect[style],
.pz-strip i {
  animation: pz-in 1ms steps(1) both;
}
.paused.out > svg rect[style],
.pz-strip.out i {
  animation-name: pz-out;
}
/* A pause from leaving the tab: no motion, so none plays on the way back. */
.paused.instant > svg rect[style],
.pz-strip.instant i {
  animation: none;
}
/* The full page: a light cover over the whole window, and a wider card in its middle. */
.paused.global::before {
  content: "";
  position: fixed;
  inset: var(--top, 0) 0 0;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
}
.paused.global .pz-card {
  position: fixed;
  left: 50%;
  /* Near the top: a short way under the header bar, so it reads first. */
  top: calc(var(--top, 0px) + min(12dvh, 96px));
  transform: translateX(-50%);
  width: min(380px, 92vw);
  box-sizing: border-box;
  padding: 28px 32px 22px;
  gap: 16px;
  font-size: 18px;
  text-align: center;
}
.paused.global .pz-auto {
  white-space: nowrap;
}
.pz-card .pz-time {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  margin-left: 2px;
}
.pz-card .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pz-card .btn svg {
  /* The card sits inside the grid box, whose own svg rule would pin this icon to its corner. */
  position: static;
  inset: auto;
  width: 12px;
  height: 12px;
}
@media (max-width: 420px) {
  .paused.global .pz-auto {
    white-space: normal;
  }
}
/* The auto-pause setting under Resume: small and quiet. */
.pz-auto {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.pz-auto input {
  margin: 0;
  accent-color: var(--fg);
}
.paused.out .pz-card {
  display: none;
}
@keyframes pz-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes pz-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Paused clue lists: the clue text hides and its pixels stand in, wrapping like the text. */
.lists.pz li > span:not(.pz-strip) {
  display: none;
}
.pz-strip.pz-li {
  max-height: none;
  flex: 1;
  align-content: flex-start;
  padding-top: 5px;
  row-gap: 10px;
}

/* No focus ring on the popup's buttons: it opens with the first one focused. */
.dlg button:focus, .dlg a:focus { outline: none; }
