/* After You! — everything outside the canvas.
   ZX Spectrum rules apply here too: black, bright, chunky, no curves. */

:root {
  --black: #000000;
  --cyan: #00ffff;
  --yellow: #ffff00;
  --magenta: #ff00ff;
  --green: #00ff00;
  --red: #ff0000;
  --white: #ffffff;
  --grey: #5a5a5a;
  --dim: #2a2a3a;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--black);
  color: var(--white);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.04em;
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------------------------------------------------------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--black);
}
.screen.active { display: flex; }

/*
  Centred, but scrollable.

  justify-content: center on an overflowing scroll container puts the top of
  the content above the scrollable area, where it cannot be reached. Auto
  margins centre the child the same way while keeping the whole thing
  scrollable. Adding one more button to the landing page was enough to hide
  the title on a phone.
*/
.screen.center { justify-content: flex-start; align-items: center; text-align: center; }
.screen.center > * { margin-top: auto; margin-bottom: auto; }

/* ---------------------------------------------------------- */

h1, h2, h3 { margin: 0; line-height: 1.05; text-transform: uppercase; }

h1 {
  font-size: clamp(30px, 11vw, 56px);
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--red);
}
h2 { font-size: clamp(18px, 5.5vw, 26px); color: var(--cyan); }
h3 { font-size: 13px; color: var(--grey); letter-spacing: 0.18em; }

.tagline {
  font-size: clamp(13px, 4vw, 17px);
  color: var(--magenta);
  margin: 10px 0 0;
  text-transform: none;
  font-style: italic;
}

p { line-height: 1.6; font-weight: 400; letter-spacing: 0.02em; }
.muted { color: var(--grey); font-size: 13px; }
.small { font-size: 12px; }

/* ---------------------------------------------------------- */

.btn {
  display: block;
  width: 100%;
  padding: 18px 20px;
  margin: 10px 0;
  border: 4px solid var(--cyan);
  background: var(--black);
  color: var(--cyan);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 17px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: none;
}
.btn:active { background: var(--cyan); color: var(--black); }
.btn:disabled { border-color: var(--dim); color: var(--dim); cursor: not-allowed; }
.btn:disabled:active { background: var(--black); color: var(--dim); }

.btn.primary { border-color: var(--yellow); color: var(--yellow); font-size: 21px; padding: 22px; }
.btn.primary:active { background: var(--yellow); color: var(--black); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:active { background: var(--red); color: var(--black); }
.btn.ghost { border-color: var(--dim); color: var(--grey); font-size: 14px; padding: 13px; }
.btn.ghost:active { background: var(--dim); color: var(--white); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin: 10px 0; }

/* ---------------------------------------------------------- */

input[type="text"] {
  display: block;
  width: 100%;
  padding: 16px;
  margin: 8px 0;
  border: 4px solid var(--dim);
  background: var(--black);
  color: var(--white);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 19px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}
input[type="text"]:focus { outline: none; border-color: var(--cyan); }

input[type="range"] { width: 100%; accent-color: var(--cyan); }

label.field { display: block; margin: 14px 0 0; }
label.field > span { display: block; font-size: 12px; color: var(--grey); letter-spacing: 0.16em; }

/* ---------------------------------------------------------- */

.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.swatch {
  width: 42px; height: 42px;
  border: 4px solid var(--dim);
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--white); }

/* ---------------------------------------------------------- */

.qr-wrap {
  background: var(--white);
  padding: 14px;
  width: min(78vw, 62vh);
  height: min(78vw, 62vh);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-wrap svg { width: 100%; height: 100%; display: block; }

.code-display {
  font-size: clamp(34px, 13vw, 60px);
  color: var(--green);
  letter-spacing: 0.28em;
  margin: 14px 0 0;
  text-indent: 0.28em;
}

/* ---------------------------------------------------------- */

.pen { list-style: none; padding: 0; margin: 14px 0; width: 100%; }
.pen li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-left: 8px solid var(--dim);
  margin-bottom: 6px;
  background: #0a0a14;
  font-size: 15px;
}
.pen li .chip { width: 16px; height: 16px; flex: 0 0 16px; }
.pen li .who { flex: 1; text-align: left; text-transform: uppercase; }
.pen li .tag { font-size: 11px; color: var(--grey); letter-spacing: 0.14em; }

.pen-empty { color: var(--grey); font-size: 13px; padding: 20px 0; }

/* ---------------------------------------------------------- */

.results { list-style: none; padding: 0; margin: 12px 0; width: 100%; max-width: 420px; }
.results li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; margin-bottom: 5px;
  border-left: 8px solid var(--dim);
  background: #0a0a14;
  font-size: 15px;
}
.results li.winner { border-left-color: var(--yellow); background: #14140a; }
.results li.me .who { color: var(--cyan); }
.results .rank { width: 34px; color: var(--grey); text-align: right; }
.results .who { flex: 1; text-align: left; text-transform: uppercase; }
.results .chip { width: 16px; height: 16px; flex: 0 0 16px; }

/* ---------------------------------------------------------- */

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--black);
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------- */

.banner {
  border: 3px solid var(--red);
  color: var(--red);
  padding: 12px;
  margin: 12px 0;
  font-size: 13px;
  text-align: center;
}
.banner.ok { border-color: var(--green); color: var(--green); }
.banner.info { border-color: var(--dim); color: var(--grey); }

.stack { width: 100%; max-width: 420px; margin: 0 auto; }

.spacer { flex: 1; min-height: 12px; }

.how { text-align: left; max-width: 420px; margin: 0 auto; }
.how li { margin-bottom: 14px; line-height: 1.55; font-weight: 400; }
.how b { color: var(--yellow); font-weight: 700; }

.pillars { display: grid; gap: 12px; margin: 22px 0; max-width: 420px; }
.pillar { border-left: 6px solid var(--cyan); padding: 10px 0 10px 14px; text-align: left; }
.pillar b { display: block; color: var(--cyan); font-size: 14px; letter-spacing: 0.1em; }
.pillar span { font-size: 13px; color: var(--grey); font-weight: 400; line-height: 1.5; }

.footer { margin-top: 30px; color: var(--dim); font-size: 11px; text-align: center; }
.footer a { color: var(--grey); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 2px solid #14141e;
  font-size: 13px;
}
.toggle-row .val { color: var(--cyan); }

/* ---------------------------------------------------------- */
/* QR scanner overlay                                          */

.scanner {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--black);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 18px calc(28px + env(safe-area-inset-bottom));
}

.scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.scanner-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  pointer-events: none;
}
.scanner-frame i {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 5px solid var(--cyan);
}
.scanner-frame .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scanner-frame .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scanner-frame .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scanner-frame .br { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.scanner-hint,
.scanner-error {
  position: relative;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 13px;
  margin: 0 0 14px;
  text-shadow: 2px 2px 0 var(--black);
}
.scanner-hint { color: var(--cyan); }
.scanner-error {
  color: var(--red);
  text-transform: none;
  letter-spacing: 0.02em;
  line-height: 1.6;
  background: rgba(0, 0, 0, 0.8);
  border: 3px solid var(--red);
  padding: 12px;
}

.scanner-cancel { position: relative; width: 100%; max-width: 420px; margin: 0; }

/* Belt animation on the landing page. Pure decoration, pure nonsense. */
.belt-strip {
  height: 26px;
  background: repeating-linear-gradient(90deg,
    #2e2e2e 0 8px, #4a4a4a 8px 16px);
  background-size: 16px 100%;
  animation: belt 0.9s linear infinite;
  border-top: 2px solid var(--grey);
  margin: 18px 0;
}
@keyframes belt { from { background-position: 0 0; } to { background-position: 16px 0; } }

@media (prefers-reduced-motion: reduce) {
  .belt-strip { animation: none; }
}
