/* Beamline.
 *
 * The page follows the visitor's light or dark preference. The board itself is
 * always dark, the way a photograph stays a photograph in either theme: it is
 * an optics table in the fiction, and coloured light only reads against a dark
 * ground.
 *
 * Type is Libre Caslon, self-hosted under the OFL. No font or script is fetched
 * from anyone else's server.
 */

@font-face {
  font-family: "Libre Caslon Text";
  src: url("../fonts/caslon-text-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Libre Caslon Text";
  src: url("../fonts/caslon-text-400-italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Libre Caslon Text";
  src: url("../fonts/caslon-text-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Libre Caslon Display";
  src: url("../fonts/caslon-display-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light dark;

  --bg:        #e6ebf2;
  --bg-2:      #d6dfea;
  --panel:     #f5f8fc;
  --line:      #c9d3e0;
  --control:   #68768b;
  --ink:       #0f1522;
  --ink-2:     #334055;
  --ink-3:     #4f5c70;
  --accent:    #2443b0;
  --accent-ink:#ffffff;
  --done:      #2443b0;

  /* Board tokens do not change with the theme. */
  --table:      #070a0f;
  --table-line: #1a212c;
  --cell:       #0f141c;
  --cell-hover: #172030;
  --wall:       #2a3240;
  --wall-edge:  #3a4456;
  --board-ink:  #c9d3e0;
  --focus:      #ffd166;

  --radius: 14px;
  --pill: 999px;
  --serif: "Libre Caslon Text", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Libre Caslon Display", "Libre Caslon Text", Georgia, serif;
  --grid-line: rgba(36, 67, 176, .07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #070b15;
    --bg-2:    #0d1527;
    --panel:   #101a2e;
    --line:    #22304a;
    --control: #62728c;
    --ink:     #edf1f8;
    --ink-2:   #b6c1d3;
    --ink-3:   #8f9cb3;
    --accent:  #93abff;
    --accent-ink: #070b15;
    --done:    #93abff;
    --grid-line: rgba(147, 171, 255, .05);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  /* A faint engineering grid, the kind printed on an optics lab notebook. */
  background:
    radial-gradient(1100px 520px at 12% -12%, var(--bg-2), transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.skip-link {
  position: absolute; left: 1rem; top: 1rem; z-index: 50;
  padding: .6rem 1.1rem; border-radius: var(--pill);
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; text-decoration: none;
  transform: translateY(-250%);
}
.skip-link:focus { transform: translateY(0); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.wrap { max-width: 1120px; margin-inline: auto; padding-block: 2.75rem 3rem; padding-inline: 1.25rem; }

/* ---- masthead -------------------------------------------------------- */
.masthead { position: relative; max-width: 46rem; }
.eyebrow {
  margin: 0 0 .35rem;
  font-size: .8rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 400;
}
.masthead h1 {
  margin: 0;
  font-size: clamp(2.6rem, 6vw, 4rem);
  line-height: 1;
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: -0.01em;
  position: relative;
  display: inline-block;
}
/* A single beam runs under the title: red, green and blue meeting as white. */
.masthead h1::after {
  content: "";
  position: absolute; left: 0; right: -1.5rem; bottom: -.45rem;
  height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, #ff4a3d 0%, #ffe04a 30%, #3dff6e 50%, #3df2ff 70%, #4a6dff 85%, #ffffff 100%);
  box-shadow: 0 0 12px rgba(255, 224, 74, .45);
}
.lede { margin: 1.15rem 0 0; color: var(--ink-2); font-size: 1.08rem; max-width: 40rem; }

/* ---- layout ---------------------------------------------------------- */
.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2rem;
  margin-top: 2.25rem;
  align-items: start;
}
@media (max-width: 900px) { .game { grid-template-columns: 1fr; } }

/* ---- board ----------------------------------------------------------- */
.stage {
  position: relative;
  border-radius: var(--radius);
  background: var(--table);
  padding: 10px;
  box-shadow:
    0 1px 0 rgba(255,255,255,.04) inset,
    0 30px 60px -30px rgba(0,0,0,.55),
    0 12px 24px -16px rgba(0,0,0,.4);
}
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 3px;
  width: 100%;
}
.board__row { display: contents; }

/* The canvas covers the stage exactly. Its drawing size is set in JS from the
   cells themselves, so beams can never drift away from the cells they cross. */
.beams {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  border-radius: var(--radius);
}

.cell {
  aspect-ratio: 1;
  min-width: 0;
  margin: 0; padding: 0; border: 0;
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 50%, #1c2431 0 7%, transparent 8%),
    var(--cell);
  color: var(--board-ink);
  font: inherit;
}
button.cell { cursor: pointer; touch-action: manipulation; }
@media (hover: hover) { button.cell:hover { background-color: var(--cell-hover); } }
.cell:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  border-radius: 4px;
}
.cell--wall {
  background: linear-gradient(160deg, var(--wall-edge), var(--wall) 55%);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.35);
}
.cell--placed { background-color: #121a26; }

.stage.is-solved { box-shadow:
    0 0 0 1px rgba(255, 224, 74, .25),
    0 30px 60px -30px rgba(0,0,0,.55),
    0 0 50px -10px rgba(255, 224, 74, .25); }

.board-help { margin: .8rem 0 0; color: var(--ink-3); font-size: .92rem; }

/* ---- solved card ----------------------------------------------------- */
.result {
  margin-top: .9rem;
  background: #0e1219;
  color: #f3f1ec;
  border: 1px solid rgba(255, 224, 74, .35);
  border-radius: 12px;
  padding: .95rem 1.15rem 1rem;
  box-shadow: 0 16px 32px -18px rgba(0,0,0,.6);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .2rem 1.25rem;
  align-items: center;
}
.result > :not(.result__actions) { grid-column: 1; }
.result__actions { grid-column: 2; grid-row: 1 / span 3; }
@media (max-width: 560px) {
  .result { grid-template-columns: 1fr; }
  .result__actions { grid-column: 1; grid-row: auto; margin-top: .4rem; }
}
.result[hidden] { display: none; }
.result__kicker {
  margin: 0; font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; color: #ffe04a;
}
.result__title { margin: .15rem 0 .2rem; font-family: var(--display); font-size: 1.6rem; font-weight: 400; }
.result__body { margin: 0; color: #c8ccd4; font-size: .98rem; }
.result__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.result .btn { color: #f3f1ec; border-color: rgba(255,255,255,.35); }
.result .btn:hover:not(:disabled) { background: rgba(255,255,255,.08); }
.result .btn--primary { background: #ffe04a; border-color: #ffe04a; color: #14120a; }
.result .btn--primary:hover:not(:disabled) { background: #ffe86e; }

@media (prefers-reduced-motion: no-preference) {
  .result.is-in { animation: rise 320ms cubic-bezier(.2, .8, .2, 1); }
  @keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* ---- panel ----------------------------------------------------------- */
.panel { display: grid; gap: 1rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.15rem;
}
.card__kicker {
  margin: 0 0 .55rem;
  font-size: .76rem; font-weight: 400;
  letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3);
}
.level-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.75rem; line-height: 1.15;
  font-weight: 400; letter-spacing: -0.005em;
}
.level-hint { margin: .45rem 0 0; color: var(--ink-2); font-size: .98rem; font-style: italic; }

.budget { display: flex; align-items: center; gap: .65rem; margin-top: .9rem; }
.budget__pips { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.budget__text { font-variant-numeric: tabular-nums lining-nums; font-weight: 400; color: var(--ink); font-size: .95rem; }
.pip {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--control);
}
.pip.is-used { background: var(--accent); border-color: var(--accent); }
.budget.is-full .budget__text { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .budget.is-refused { animation: nudge 360ms ease; }
  @keyframes nudge {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
  }
}

.controls { display: flex; flex-wrap: wrap; gap: .45rem; }
.controls--nav { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--line); }

.btn {
  font: inherit; font-size: .93rem; font-weight: 400;
  padding: .45rem .95rem;
  min-height: 2.35rem;
  border-radius: var(--pill);
  border: 1px solid var(--control);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }

.keys { margin-top: .8rem; font-size: .9rem; color: var(--ink-2); }
.keys summary { cursor: pointer; color: var(--ink-2); }
.keys dl { margin: .5rem 0 0; display: grid; gap: .2rem; }
.keys dl div { display: grid; grid-template-columns: 4.5rem 1fr; gap: .5rem; }
.keys dt { font-weight: 700; color: var(--ink); font-variant-numeric: lining-nums; }
.keys dd { margin: 0; }

.picker__group + .picker__group { margin-top: .8rem; }
.picker__chapter { margin: 0 0 .4rem; font-size: .9rem; font-weight: 400; color: var(--ink-2); font-style: italic; }
.picker { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  font: inherit; font-size: .86rem; font-variant-numeric: tabular-nums lining-nums;
  width: 2.25rem; height: 2.25rem;
  border-radius: var(--pill);
  border: 1px solid var(--control);
  background: transparent; color: var(--ink-2);
  cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--ink-2); }
/* Solved, seen and current differ by fill, border style and weight, never by colour alone. */
.chip.is-done { border: 2px solid var(--done); color: var(--done); font-weight: 700; }
.chip.is-seen { border-style: dashed; }
.chip.is-current { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.picker-key { margin: .75rem 0 0; font-size: .82rem; color: var(--ink-3); display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.key-done, .key-seen { display: inline-block; width: 13px; height: 13px; border-radius: 50%; }
.key-done { border: 2px solid var(--done); }
.key-seen { border: 1px dashed var(--control); margin-left: .5rem; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.legend li { display: grid; grid-template-columns: 34px 1fr; gap: .65rem; align-items: center; font-size: .9rem; color: var(--ink-2); line-height: 1.4; }
.legend__icon { width: 34px; height: 34px; border-radius: 7px; background: var(--cell); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

footer { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--line); color: var(--ink-3); font-size: .9rem; }
footer p { margin: 0 0 .4rem; }
footer a, .linkish { color: var(--ink-2); }
.linkish {
  font: inherit; background: none; border: 0; padding: 0;
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}

.noscript { max-width: 40rem; margin: 2rem auto; padding: 1rem; font-family: var(--serif); }

/* Short viewports, which is what an embedded frame on a games portal gives you.
 * The game has to be usable without scrolling at about 700px of height, so the
 * chrome tightens and the standfirst drops out rather than the board shrinking.
 */
@media (max-height: 820px) and (min-width: 901px) {
  .wrap { padding-block: 1.25rem 1.5rem; }
  .eyebrow, .lede { display: none; }
  .masthead h1 { font-size: 2rem; }
  .game { margin-top: 1.2rem; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) 270px; }
  .panel { gap: .7rem; }
  .card { padding: .8rem .9rem; }
  .legend li { font-size: .82rem; }
}

/* The fullscreen control is hidden unless the browser exposes the API, so it
 * never sits there doing nothing. */
#fullscreen[hidden] { display: none !important; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .wrap { padding-inline: 16px; padding-top: 1.75rem; }
  .stage { padding: 6px; }
  .board { gap: 2px; }
  .game { margin-top: 1.5rem; }
}

/* On one column, the level's name, hint and budget come before the board,
 * and the rest of the panel follows it. */
@media (max-width: 900px) {
  .panel { display: contents; }
  .card--level { order: -1; }
  .game { gap: 1rem; }
}
