/* Santa's Helper. Copyright C Cliffe 2026. All rights reserved.

   The way in: the code, the name, the crossword and the rank and area choice.
   Built against DESIGN.md, which is binding.

   The lead-in screens are centred and quiet. The crossword is the only one that
   needs the width, and it is sized so the widest grid the generator makes still
   fits a 1366 wide laptop with chrome on it. */

/* ------------------------------------------------------------- the screens */

.entry {
  min-height: 100dvh;
  display: grid;
}

.screen {
  grid-area: 1 / 1;
  display: none;
  place-items: center;
  padding: var(--s-6) var(--s-5);
}

.screen.is-on {
  display: grid;
  animation: screen-in var(--dur-screen) var(--ease) both;
}

/* A crossfade with an 8px rise, and no orchestrated sequence, because the player
   is waiting to play. */
@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.screen-inner {
  width: 100%;
  max-width: 460px;
  text-align: center;
}

.screen-inner-wide { max-width: 760px; }
.screen-wide { align-content: center; }

.eyebrow {
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 var(--s-3);
}

.display {
  font-size: var(--t-display);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 var(--s-6);
}

.h1 { font-size: var(--t-h1); line-height: 1.1; margin: 0 0 var(--s-5); }
.h2 { font-size: var(--t-h2); line-height: 1.15; margin: 0; }

/* A long title still has to fit a projector at 1366 wide. */
@media (max-width: 560px), (max-height: 620px) {
  .display { font-size: var(--t-h1); }
}

/* --------------------------------------------------------------- the fields */

.field-form {
  display: grid;
  gap: var(--s-3);
  justify-items: stretch;
  text-align: left;
}

.field-form-wide { margin-top: var(--s-6); }

.field-label {
  font-size: var(--t-small);
  color: var(--ink-2);
}

.field {
  font: inherit;
  font-size: var(--t-lead);
  color: var(--ink);
  background: var(--night-1);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: var(--s-3) var(--s-4);
  min-height: 48px;
  width: 100%;
  transition: border-color var(--dur-hover) var(--ease);
}

.field:hover { border-color: var(--line-strong); }
.field:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; border-color: var(--lantern); }
.field::placeholder { color: var(--ink-3); }

/* The code upper cases as it is typed, so a code read off the board goes in
   whatever way it is typed. */
#code {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.btn-wide {
  width: 100%;
  min-height: 48px;
  font-size: var(--t-body);
}

/* A refusal says what to do next and never hints at what a right code looks
   like. It holds its line so the screen does not jump when one appears. */
.refusal {
  margin: 0;
  min-height: 1.5em;
  font-size: var(--t-small);
  color: var(--ember);
}

.refusal:empty { min-height: 1.5em; }

/* ------------------------------------------------------------ the crossword */

.xw {
  display: grid;
  grid-template-columns: auto minmax(300px, 420px);
  grid-template-areas:
    "head head"
    "grid clues";
  gap: var(--s-5) var(--s-6);
  align-items: start;
  margin: 0 auto;
}

.xw-head { grid-area: head; max-width: 70ch; }
.xw-lede { margin: var(--s-2) 0 0; color: var(--ink-2); font-size: var(--t-lead); }

.xw-grid-col { grid-area: grid; display: grid; gap: var(--s-5); justify-items: start; }

.xw-grid {
  display: grid;
  /* The columns are set from the puzzle, since the generator decides the shape. */
  grid-auto-rows: 34px;
  gap: 0;
}

.xw-cell { position: relative; }

/* An empty square is nothing at all, so the grid reads as the shape of the
   puzzle rather than as a rectangle with holes in it. */
.xw-cell.is-blank { background: none; border: none; }

.xw-input {
  font: inherit;
  font-size: var(--t-lead);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  background: var(--night-1);
  border: 1px solid var(--line);
  border-radius: var(--r-cell);
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  caret-color: transparent;
  transition: background var(--dur-hover) var(--ease);
}

/* The current word takes a wash and the current cell a ring, so it is always
   obvious which clue you are answering. */
.xw-cell.in-word .xw-input { background: var(--night-2); }

.xw-input:focus-visible {
  outline: 2px solid var(--lantern);
  outline-offset: -2px;
  z-index: 1;
}

/* An answer to a question rather than a permanent telling off. */
.xw-cell.is-wrong .xw-input {
  background: color-mix(in oklch, var(--ember-soft) 12%, var(--night-1));
}

.xw-cell.is-right .xw-input { color: var(--found); }

.xw-grid.is-solved .xw-input {
  animation: grid-flash 400ms var(--ease) both;
}

@keyframes grid-flash {
  50% { background: color-mix(in oklch, var(--found) 22%, var(--night-1)); }
}

/* The number sits in the corner of the first cell of a word, as a crossword's
   numbers always have. */
.xw-n {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: var(--t-micro);
  line-height: 1;
  color: var(--ink-3);
  pointer-events: none;
}

/* ------------------------------------------------------------ the bits table */

.bits { border-collapse: collapse; }

.bits-caption {
  caption-side: top;
  text-align: left;
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-bottom: var(--s-2);
}

/* The same square and the same border as a crossword cell, so it reads as a
   piece of the puzzle rather than a footnote stuck underneath. Quieter than an
   answer, because it is a reference and not something to fill in. */
.bits td {
  width: 34px;
  height: 34px;
  padding: 0;
  text-align: center;
  font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  background: var(--night-1);
  border: 1px solid var(--line);
}

/* --------------------------------------------------------------- the clues */

.xw-clues { grid-area: clues; display: grid; gap: var(--s-4); align-content: start; }

.clue-head {
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 var(--s-2);
}

.clue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-1); }

.clue {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  width: 100%;
  font: inherit;
  font-size: var(--t-small);
  text-align: left;
  color: var(--ink-2);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  padding: var(--s-2);
  cursor: pointer;
  transition: background var(--dur-hover) var(--ease), color var(--dur-hover) var(--ease);
}

.clue:hover { background: var(--night-1); color: var(--ink); }
.clue:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }
.clue.is-current { background: var(--night-2); color: var(--ink); }

.clue-n { flex: none; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.clue-text { flex: 1 1 auto; }

/* A small cross against the clue, and a tick when it is right. Nothing reveals a
   digit. */
.clue-mark { flex: none; width: 1em; text-align: center; }
.clue.is-wrong .clue-mark { color: var(--ember); }
.clue.is-right .clue-mark { color: var(--found); }
.clue.is-right { color: var(--ink-3); }

/* ---------------------------------------------------------------- the ranks */

/* One row of three wide buttons. Not cards. */
.ranks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-3);
}

.rank {
  display: grid;
  gap: var(--s-1);
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--night-1);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: var(--s-4);
  cursor: pointer;
  transition:
    background var(--dur-hover) var(--ease),
    border-color var(--dur-hover) var(--ease);
}

.rank:hover { background: var(--night-2); border-color: var(--line-strong); }
.rank:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }

.rank[aria-checked="true"] {
  background: var(--lantern);
  border-color: var(--lantern);
  color: var(--on-lantern);
}

.rank-name { font-size: var(--t-lead); font-weight: 600; }
.rank-detail { font-size: var(--t-small); color: var(--ink-2); }
.rank-mult { font-size: var(--t-small); color: var(--ink-3); }

/* Inside the chosen one, the quiet greys would disappear. */
.rank[aria-checked="true"] .rank-detail,
.rank[aria-checked="true"] .rank-mult { color: inherit; opacity: 0.8; }

.rank-note {
  margin: var(--s-3) 0 0;
  font-size: var(--t-small);
  color: var(--ink-3);
}

@media (max-width: 720px) {
  .ranks { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------- the matches */

/* Up to five, each with its county, and the list replaces the button until one is
   chosen. */
.matches {
  list-style: none;
  margin: var(--s-3) 0 0;
  padding: 0;
  display: grid;
  gap: var(--s-1);
  text-align: left;
}

.match {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  width: 100%;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--night-1);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: var(--s-3) var(--s-4);
  min-height: 48px;
  cursor: pointer;
  transition: background var(--dur-hover) var(--ease), border-color var(--dur-hover) var(--ease);
}

.match:hover { background: var(--night-2); border-color: var(--line-strong); }
.match:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }

.match-kind { flex: none; font-size: var(--t-micro); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }

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

@media (prefers-reduced-motion: reduce) {
  .screen.is-on { animation: none; }
  .xw-grid.is-solved .xw-input { animation: none; }
  * { transition-duration: 1ms !important; }
}
