/* The game companion (doc 36 §11-13, doc 58 §8). Its own stylesheet, not
   site.css: the app shares the printed kit's navy, one signal red and white
   paper, and none of the site's page components. Each game page sets a
   data-theme on <html>: "carnival" is the default below; the other themes
   ("case-file", "storybook", "ledger", "office", "halloways") swap the tokens
   and type in companion-themes.css. */

@font-face {
  font-family: "League Spartan";
  src: url("/assets/fonts/LeagueSpartan-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "League Spartan";
  src: url("/assets/fonts/LeagueSpartan-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Courier Prime";
  src: url("/assets/fonts/CourierPrime-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Courier Prime";
  src: url("/assets/fonts/CourierPrime-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Book Serif";
  src: url("/assets/fonts/BookSerifLF-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #ffffff;
  --mist: #f2f4f6;
  --story: #f1efe9;
  --ink: #14181d;
  --navy: #032643;
  --file-blue: #1d3340;
  --signal-red: #a8332f;
  --error-ink: #7f2825;
  --success: #285b45;
  --hairline: #73818a;
  --muted: #4d5962;
  --line: #d9dde1;
  --sans: "League Spartan", Arial, sans-serif;
  --serif: "Book Serif", Georgia, serif;
  --typed: "Courier Prime", "Courier New", monospace;
  /* Type roles a theme can recast: the view title, and the small uppercase
     labels (eyebrow, section heads, field labels, fold summaries). */
  --display: var(--serif);
  --label: var(--sans);
  --gutter: 20px;
  --bar-h: 64px;
  --bar-compact-h: 48px;
  --rail-h: 14px;
  --dock-h: 64px;
  --chrome-ease: 160ms ease-out;
  scroll-padding-top: calc(var(--bar-compact-h) + var(--rail-h) + 12px);
  scroll-padding-bottom: calc(var(--dock-h) + 12px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

a {
  color: var(--navy);
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 3px solid var(--signal-red);
  outline-offset: 3px;
}

[tabindex="-1"]:focus {
  outline: none;
}

.skip {
  position: absolute;
  top: -100px;
  left: 8px;
  padding: 10px 14px;
  background: var(--navy);
  color: var(--paper);
}

.skip:focus {
  top: 8px;
}

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

/* The wide-screen sidebar (companion-wide.css); phones use the dock. */
.side {
  display: none;
}

/* The case file: one white column on the mist surround, full height so the
   fixed header and dock always sit on its edges. */
.file {
  max-width: 720px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  background: var(--paper);
}

/* App chrome (doc 36 §20): a fixed header that shrinks once the page leaves
   the top, and a fixed dock with Back, Progress and Next. Both hug the case
   file's column; main is padded so neither covers content at rest. Every
   view but Welcome is a game view, with the rail and the dock. */

.app-bar,
.dock {
  position: fixed;
  z-index: 10;
  right: 0;
  left: 0;
  max-width: 720px;
  margin: 0 auto;
  background: var(--paper);
}

.app-bar {
  top: 0;
  border-bottom: 1px solid var(--line);
  transition: box-shadow var(--chrome-ease);
}

/* Empty until the script runs; hidden so the no-JavaScript page has no bare rule. */
.app-bar:empty,
.dock:empty {
  display: none;
}

.app-bar:not(:empty) ~ main {
  padding-top: var(--bar-h);
}

[data-view]:not([data-view="welcome"]) .app-bar:not(:empty) ~ main {
  padding-top: calc(var(--bar-h) + var(--rail-h));
}

.compact .app-bar {
  box-shadow: 0 2px 10px rgb(3 38 67 / 0.12);
}

/* The logo or title fills the first column; the count and Search, where a
   game has documents, take a column each after it. */
.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 16px;
  height: var(--bar-h);
  align-items: center;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  transition: height var(--chrome-ease);
}

.compact .bar-row {
  height: var(--bar-compact-h);
}

/* The logo and the short title share one cell and cross-fade. */
.brand,
.bar-title {
  grid-area: 1 / 1;
  transition:
    opacity var(--chrome-ease),
    visibility var(--chrome-ease);
}

.brand {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-self: start;
}

.brand img {
  display: block;
  width: 144px;
  height: auto;
}

.bar-title {
  margin: 0;
  overflow: hidden;
  color: var(--file-blue);
  font-family: var(--serif);
  font-size: 1.125rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-title,
.compact .brand {
  visibility: hidden;
  opacity: 0;
}

.compact .bar-title {
  visibility: visible;
  opacity: 1;
}

/* The rail shows the count too, and at 320px the row needs the room for Search. */
@media (max-width: 359px) {
  .bar-count:has(+ .bar-search) {
    display: none;
  }
}

.bar-search {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 0 4px;
  font-family: var(--label);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bar-search[aria-current="page"] {
  color: var(--signal-red);
  text-decoration: none;
}

.bar-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.dock {
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 4px;
  min-height: calc(var(--dock-h) + env(safe-area-inset-bottom));
  align-items: center;
  padding: 8px max(var(--gutter), env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  transition:
    transform var(--chrome-ease),
    visibility var(--chrome-ease);
}

[data-view]:not([data-view="welcome"]) main {
  padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom));
}

[data-view]:not([data-view="welcome"]) .page {
  padding-bottom: 32px;
}

.dock-item {
  display: grid;
  min-height: 48px;
  align-content: center;
  color: var(--navy);
  line-height: 1.2;
  text-decoration: none;
}

.dock-item.back {
  justify-self: start;
}

.dock-item.next {
  justify-self: end;
  text-align: right;
}

.dock-hint {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Two exhibit names and Progress fit one row at 320px only unwrapped. */
.dock-label {
  font-size: 0.9375rem;
  font-weight: 700;
  white-space: nowrap;
}

.dock-item.back .dock-hint::before {
  content: "\2039\00a0" / "";
}

a.dock-item.next .dock-hint::after {
  content: "\00a0\203a" / "";
}

/* An open Next is the one filled control in the dock. */
a.dock-item.next {
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--navy);
  color: var(--paper);
}

a.dock-item.next .dock-hint {
  color: inherit;
}

.dock-item.locked {
  color: var(--muted);
}

.dock-item.middle {
  justify-self: center;
  padding: 0 4px;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: underline;
  text-transform: uppercase;
  text-underline-offset: 3px;
}

.dock-item.middle[aria-current="page"] {
  color: var(--signal-red);
  text-decoration: none;
}

/* On a touch screen the keyboard is up while the answer field has focus, and
   the dock would ride on top of it. */
@media (pointer: coarse) {
  .typing .dock {
    visibility: hidden;
    transform: translateY(100%);
  }
}

.page {
  padding: 28px max(var(--gutter), env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--file-blue);
  color: var(--file-blue);
  font-family: var(--display);
  font-size: clamp(2rem, 7vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
  color: var(--file-blue);
  font-family: var(--label);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}


.eyebrow {
  margin-bottom: 8px;
  color: var(--signal-red);
  font-family: var(--label);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.lede,
.story p,
.fold p,
.steps li,
.signature,
.questions span {
  font-family: var(--serif);
  line-height: 1.6;
}

.lede {
  max-width: 34ch;
  font-size: 1.125rem;
}

/* The story is the case note: the one panel with a paper offset. */
.story {
  max-width: 62ch;
  margin-bottom: 28px;
  padding: 18px 18px 2px;
  border-left: 4px solid var(--signal-red);
  background: var(--story);
  box-shadow: 0 4px 0 var(--line);
}

.story p {
  margin-bottom: 16px;
}

.rail {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 6px;
  height: var(--rail-h);
  align-items: start;
  padding: 2px max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}

.rail span {
  height: 6px;
  background: var(--line);
}

.rail .solved {
  background: var(--navy);
}

/* Shape as well as colour: the current step is taller than the rest. */
.rail .open {
  height: 10px;
  margin-top: -2px;
  background: var(--signal-red);
}

.facts {
  display: grid;
  gap: 10px;
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

.facts li {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: baseline;
}

.facts li::before {
  content: "";
  width: 8px;
  height: 2px;
  background: var(--signal-red);
  transform: translateY(-4px);
}

.notice {
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--navy);
}

.actions {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.button {
  display: inline-flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 2px solid var(--navy);
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  background: var(--navy);
  color: var(--paper);
}

.button.secondary {
  background: var(--paper);
  color: var(--navy);
}

.button.text {
  width: auto;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.check,
.saved,
.help {
  margin-bottom: 28px;
}

form {
  display: grid;
  gap: 8px;
}

label {
  color: var(--file-blue);
  font-family: var(--label);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 54px;
  padding: 10px 13px;
  border: 2px solid var(--hairline);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.2rem;
  letter-spacing: 0.04em;
}

input[aria-invalid="true"] {
  border-color: var(--signal-red);
}

/* Error: message, icon and border together, never colour alone. */
.error {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  margin: 0;
  color: var(--error-ink);
  font-size: 0.95rem;
  line-height: 1.4;
}

.error::before {
  content: "!" / "";
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid var(--signal-red);
  border-radius: 50%;
  font-weight: 700;
}

.saved {
  padding: 22px 20px;
  border: 2px solid var(--success);
  border-top-width: 6px;
}

.saved h2 {
  color: var(--success);
}

.saved h2::before {
  content: "\2713\00a0" / "";
}

.answer {
  margin-bottom: 8px;
  color: var(--file-blue);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

.help {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

/* Collapsible panels: the story, each hint and the solution. The summary is
   the whole tap target, and a chevron shows which way it will move. */
.fold {
  margin-bottom: 28px;
}

.fold summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--file-blue);
  font-family: var(--label);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  list-style: none;
  text-transform: uppercase;
  cursor: pointer;
}

.fold summary::-webkit-details-marker {
  display: none;
}

.fold summary::after {
  content: "";
  width: 9px;
  height: 9px;
  flex: none;
  margin-right: 4px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg);
  transition: transform var(--chrome-ease);
}

.fold[open] > summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.fold[open] > summary {
  margin-bottom: 6px;
}

.fold-body > .story {
  margin-bottom: 0;
}

/* Hints and the solution stack as ruled rows inside Help. */
.help .fold {
  margin: 0;
  border-top: 1px solid var(--line);
}

.help .fold summary {
  color: var(--signal-red);
  font-size: 0.8125rem;
}

.help .fold:last-of-type {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

/* Hung numerals in the signal red, like the printed Solutions page. */
.steps {
  margin: 0 0 16px;
  padding-left: 1.75em;
}

.steps li {
  margin-bottom: 6px;
  padding-left: 4px;
}

.steps li::marker {
  color: var(--signal-red);
  font-family: var(--sans);
  font-weight: 700;
}

.note {
  color: var(--muted);
}

.confirm {
  margin: 12px 0;
  padding: 16px;
  border: 1px solid var(--hairline);
  border-left: 4px solid var(--signal-red);
}

.records {
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.row {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  gap: 12px;
  min-height: 52px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

a.row .label {
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row .num {
  color: var(--signal-red);
  font-weight: 700;
}

.row .status {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

/* Muted rather than hairline grey, which is under 4.5:1 on white. */
.row.locked {
  color: var(--muted);
}

.footer-actions {
  padding-top: 12px;
}

/* The questions a letter sets, as the printed Start Here lists them. */
.questions {
  max-width: 62ch;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.questions li {
  display: grid;
  grid-template-columns: 3.4em 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.questions b {
  color: var(--signal-red);
  font-family: var(--label);
  font-size: 0.875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.signature {
  margin-bottom: 28px;
}

.byline {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.4;
}

/* Where to get the printed game, for anyone who reached the app without it. */
.shop {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.shop a {
  font-weight: 700;
}

/* The documents: a word search over the printed file, and each exhibit's
   pictures. */
.search {
  margin-bottom: 8px;
}

.search-status {
  min-height: 1.5em;
  color: var(--muted);
}

.picture {
  margin: 0 0 32px;
}

.picture-frame {
  display: block;
  border: 1px solid var(--line);
  background: var(--story);
}

.picture img {
  display: block;
  width: 100%;
  height: auto;
}

.picture figcaption {
  display: grid;
  gap: 4px;
  padding-top: 10px;
}

.picture .caption {
  font-family: var(--serif);
  line-height: 1.45;
}

.picture .credit {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.4;
}

.picture .full {
  justify-self: start;
  min-height: 44px;
  padding-top: 10px;
  font-weight: 700;
}

@media (min-width: 768px) {
  :root {
    --gutter: 40px;
  }

  .file,
  .app-bar,
  .dock {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }

  .actions {
    grid-template-columns: repeat(auto-fit, minmax(220px, max-content));
  }

  .actions .button,
  form .button {
    width: auto;
    min-width: 220px;
  }

  form {
    grid-template-columns: minmax(0, 360px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
