/* ==========================================================================
   Graphwar - printed mathematical plate
   A two-ink risograph print of a textbook figure.
   Blue and flo are TEAM inks only; they never decorate.
   ========================================================================== */

:root {
  --paper:      #E2E5DE;
  --paper-deep: #D5DAD1;
  --paper-lift: #EDEFE9;
  --rule:       #A9B1A7;
  --ink:        #141A17;
  --ink-soft:   #5F6A63;
  --blue:       #1B3FD8;
  --flo:        #FF4A18;

  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --font-ui:      'Instrument Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --hair: 1px solid var(--rule);
  --tick: 13px;
  --pad-screen: clamp(16px, 3.2vw, 40px);
  --step: clamp(14px, 2vw, 22px);
}

/* --------------------------------------------------------------- reset -- */

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, dl, dd, ol, ul {
  margin: 0;
  padding: 0;
}

ol, ul { list-style: none; }

canvas, svg, img { max-width: 100%; }

button, input {
  font: inherit;
  color: inherit;
  margin: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

[hidden] { display: none !important; }

::selection {
  background: var(--ink);
  color: var(--paper);
}

/* --------------------------------------------------- focus, everywhere -- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ================================================================ menu == */

.screen { position: relative; }

.screen--menu {
  width: 100%;
  max-width: 1000px;
  margin-inline: auto;
  padding: clamp(40px, 9vh, 96px) var(--pad-screen) clamp(48px, 10vh, 110px);
  display: flex;
  flex-direction: column;
  gap: clamp(32px, 6vh, 64px);
}

/* masthead --------------------------------------------------------------- */

.masthead {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: clamp(18px, 3vh, 30px);
  border-bottom: var(--hair);
}

.masthead__eyebrow {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.masthead__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 12vw, 6rem);
  line-height: 0.92;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.masthead__blurb {
  max-width: 46ch;
  font-size: clamp(0.98rem, 1.6vw, 1.1rem);
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* cards ------------------------------------------------------------------ */

.cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--step);
  align-items: stretch;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: clamp(18px, 2.4vw, 26px);
  background: var(--paper-lift);
  border: var(--hair);
  border-radius: 2px;
}

.card--quiet {
  background: var(--paper-deep);
}

.card__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.card__note {
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.card .button { margin-top: auto; }

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field__input,
.fire__input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.3;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  appearance: none;
  transition: border-color 120ms linear, background-color 120ms linear;
}

.field__input::placeholder,
.fire__input::placeholder {
  color: var(--ink-soft);
  opacity: 0.65;
}

.field__input:hover,
.fire__input:hover { border-color: var(--ink-soft); }

.field__input:focus,
.fire__input:focus {
  border-color: var(--ink);
  background: var(--paper-lift);
}

.field__input--code {
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

/* buttons ---------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink);
  background: var(--paper-lift);
  border: 1px solid var(--ink);
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear;
}

.button:hover {
  background: var(--ink);
  color: var(--paper);
}

.button:active { transform: translateY(1px); }

.button:disabled,
.button[aria-disabled='true'] {
  cursor: not-allowed;
  opacity: 0.42;
}

.button:disabled:hover {
  background: var(--paper-lift);
  color: var(--ink);
}

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

.button--primary:hover {
  background: var(--paper-lift);
  color: var(--ink);
}

.button--primary:disabled:hover {
  background: var(--ink);
  color: var(--paper);
}

/* menu error ------------------------------------------------------------- */

.menu-error {
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--paper-deep);
  border: var(--hair);
  border-left: 3px solid var(--ink);
  border-radius: 2px;
}

/* ================================================================ game == */

.screen--game {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: auto;
  gap: var(--step);
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--pad-screen);
}

/* plate ------------------------------------------------------------------ */

.plate {
  order: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: clamp(13px, 1.6vw, 22px);
  background: var(--paper-lift);
  border: var(--hair);
  border-radius: 2px;
}

.plate__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  padding-bottom: 10px;
  border-bottom: var(--hair);
}

.plate__mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.plate__code {
  padding: 2px 4px 2px 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  background: var(--paper-deep);
  border: var(--hair);
  border-radius: 2px;
}

.plate__code:empty { display: none; }

.plate__turn {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
}

/* the frame, with its registration ticks --------------------------------- */

.plate__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  margin-inline: auto;
  background: var(--paper);
  border: var(--hair);
}

/* the one flourish: four L-shaped corner registration ticks */
.plate__frame::before {
  content: '';
  position: absolute;
  inset: calc(var(--tick) * -0.62);
  pointer-events: none;
  background-image:
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule)),
    linear-gradient(var(--rule), var(--rule));
  background-size:
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick);
  background-position:
    left top, left top,
    right top, right top,
    left bottom, left bottom,
    right bottom, right bottom;
  background-repeat: no-repeat;
}

/* Absolute, not in-flow: a canvas carries an intrinsic size from its width and
   height attributes, and in flow that size fights the frame's aspect-ratio —
   which collapsed the plate to a square on narrow viewports. Out of flow it can
   only ever fill the frame the aspect-ratio already decided. */
#field {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.plate__banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  padding: 14px 22px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.05rem, 2.6vw, 1.7rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  text-align: center;
  text-wrap: balance;
  color: var(--ink);
  background: var(--paper-lift);
  border: 1px solid var(--ink);
  border-radius: 2px;
}

.plate__banner[data-team='0'] {
  color: var(--blue);
  border-color: var(--blue);
}

.plate__banner[data-team='1'] {
  color: var(--flo);
  border-color: var(--flo);
}

.plate__caption {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* margin (the side rail) ------------------------------------------------- */

.margin {
  order: 3;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  min-height: 0;
  padding: clamp(14px, 1.6vw, 20px);
  background: var(--paper-deep);
  border: var(--hair);
  border-radius: 2px;
}

.margin__block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.margin__block--grow { flex: 1 1 auto; }

.margin__title {
  padding-bottom: 7px;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: var(--hair);
}

/* roster ----------------------------------------------------------------- */

.roster {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.roster__item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border-left: 2px solid transparent;
  color: var(--ink);
}

.roster__item[data-team='0'] { color: var(--blue); }
.roster__item[data-team='1'] { color: var(--flo); }

.roster__dot {
  flex: none;
  width: 9px;
  height: 9px;
  background: currentColor;
  border: 1px solid currentColor;
}

.roster__name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster__state {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.roster__item.is-current {
  background: var(--paper-lift);
  border-left-color: currentColor;
}

.roster__item.is-current .roster__name { font-weight: 600; }

.roster__item.is-dead { opacity: 0.45; }

.roster__item.is-dead .roster__name {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.roster__item.is-dead .roster__dot { background: transparent; }

/* figures ---------------------------------------------------------------- */

.figures {
  max-height: 15rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.4;
}

.figures__empty {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-soft);
}

.figures__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  padding: 7px 6px 7px 8px;
  border-top: var(--hair);
  border-left: 2px solid transparent;
  color: var(--ink);
}

.figures__item:first-child { border-top: 0; }

.figures__item[data-team='0'] {
  color: var(--blue);
  border-left-color: var(--blue);
}

.figures__item[data-team='1'] {
  color: var(--flo);
  border-left-color: var(--flo);
}

.figures__n {
  grid-column: 1;
  font-weight: 600;
  color: inherit;
}

.figures__fn {
  grid-column: 2;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.figures__result {
  grid-column: 2;
  margin-top: 2px;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* notation --------------------------------------------------------------- */

.cheats {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cheats__row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr);
  column-gap: 10px;
  align-items: baseline;
  font-size: 0.75rem;
}

.cheats__row dt {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
}

.cheats__row dd {
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* fire bar --------------------------------------------------------------- */

.fire {
  order: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: clamp(10px, 1.3vw, 14px);
  background: var(--paper-lift);
  border: var(--hair);
  border-radius: 2px;
}

.fire__aim {
  flex: none;
  display: flex;
  gap: 6px;
}

.fire__dir {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear, border-color 120ms linear;
}

.fire__dir:hover { border-color: var(--ink); }

.fire__dir.is-on {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

.fire__eq {
  flex: none;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.fire__input {
  flex: 1 1 12ch;
  padding-block: 9px;
  font-size: 1.05rem;
}

.fire__input:focus {
  background: var(--paper);
  border-color: var(--ink);
}

.fire__go {
  flex: none;
  height: 40px;
  padding-block: 0;
}

/* status ----------------------------------------------------------------- */

.status {
  order: 4;
  min-height: 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

/* ====================================================== wide viewports == */

@media (min-width: 640px) and (max-width: 999.98px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1000px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .screen--game {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: 1fr auto;
    align-content: start;
  }

  .plate {
    grid-column: 1;
    grid-row: 1;
  }

  .margin {
    grid-column: 2;
    grid-row: 1 / 3;
    overflow: hidden;
  }

  .fire {
    grid-column: 1;
    grid-row: 2;
  }

  .status {
    grid-column: 1;
    grid-row: 3;
  }

  /* keep the 5:3 plate inside the fold instead of stretching the page */
  .plate__frame {
    max-width: max(420px, calc((100dvh - 310px) * 5 / 3));
  }

  .figures {
    flex: 1 1 auto;
    min-height: 6rem;
    max-height: none;
  }
}

/* ==================================================== small viewports === */

@media (max-width: 460px) {
  :root { --tick: 10px; }

  .plate__code { letter-spacing: 0.2em; }

  .plate__turn {
    width: 100%;
    margin-left: 0;
  }

  .fire__dir {
    width: 38px;
    height: 38px;
  }

  .fire__input { flex-basis: 100%; }

  .fire__go {
    flex: 1 1 auto;
    height: 38px;
  }
}

/* ==================================================== reduced motion ==== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .button:active { transform: none; }
}
