/* ==========================================================================
   /voting.html — the Game Boy.

   The whole page is one handheld: a matrix backdrop, a plastic shell, and a
   four-colour DMG screen that fills most of the viewport. Every screen the
   voting flow has (the list, an amendment review, the name prompt, a poll, the
   results) is a <section class="screen"> inside that one panel, and js/voting.js
   shows exactly one at a time — the shell never moves, so it reads like a
   handheld changing screens rather than a site changing pages.

   Two self-hosted pixel faces, both SIL OFL (see fonts/README.md): Press
   Start 2P for headings and buttons, Silkscreen — narrower, and legible at
   paragraph length — for everything that is actually read.
   ========================================================================== */

@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/press-start-2p.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Silkscreen";
  src: url("/fonts/silkscreen.woff2") format("woff2");
  font-display: swap;
}

.theme-matrix {
  /* The DMG's four greys, greenest first. Every colour on the screen is one
     of these — that constraint is the whole look. */
  --gb-0: #0f380f;  /* darkest — text and outlines */
  --gb-1: #306230;
  --gb-2: #8bac0f;
  --gb-3: #9bbc0f;  /* lightest — the lit screen */

  --shell:    #3d5c2c;
  --shell-hi: #7a9a5c;
  --shell-lo: #1d2e15;

  --pixel: "Press Start 2P", "Courier New", monospace;
  --dot:   "Silkscreen", "Press Start 2P", "Courier New", monospace;

  background: #000 url("/img/voting/bg-matrix.gif") repeat top center;
  background-attachment: fixed;
  font-family: var(--dot);
}

/* The backdrop is loud; hold it back so the screen stays the bright thing. */
.theme-matrix::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 12, 0, .55);
  pointer-events: none;
  z-index: 0;
}

.theme-matrix .footer,
.theme-matrix .gb { position: relative; z-index: 1; }

/* ------------------------------------------------------------------- shell */

.gb {
  max-width: 940px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px) clamp(8px, 3vw, 24px) 8px;
}

.gb__shell {
  border: 4px solid var(--shell-lo);
  border-radius: 14px 14px 26px 14px;
  background:
    linear-gradient(160deg, var(--shell-hi) 0%, var(--shell) 22%, var(--shell) 78%, var(--shell-lo) 100%);
  box-shadow: 0 0 0 2px #0a1206, 0 18px 40px rgba(0, 0, 0, .75);
  padding: clamp(10px, 2.4vw, 20px);
}

/* The recessed frame the glass sits in. */
.gb__bezel {
  border: 3px solid var(--shell-lo);
  border-radius: 10px 10px 28px 10px;
  background: linear-gradient(180deg, #24361a, #35502a);
  padding: clamp(8px, 1.8vw, 16px);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, .75);
}

.gb__lights {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font: 7px/1 var(--pixel);
  letter-spacing: .12em;
  color: #b9cfa2;
  text-transform: uppercase;
}
.gb__led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff4b4b;
  box-shadow: 0 0 8px #ff4b4b, inset 0 -2px 2px rgba(0, 0, 0, .4);
}
/* A hard on/off blink, not a fade — this is an LED, not a breathing light.
   The "off" step keeps the inset so the lens still reads as a lens. */
@media (prefers-reduced-motion: no-preference) {
  .gb__led { animation: led-blink 1.6s steps(1, end) infinite; }
}
@keyframes led-blink {
  0%, 55%   { background: #ff4b4b; box-shadow: 0 0 8px #ff4b4b, inset 0 -2px 2px rgba(0, 0, 0, .4); }
  56%, 100% { background: #5a1414; box-shadow: inset 0 -2px 2px rgba(0, 0, 0, .4); }
}

/* -------------------------------------------------------------- the screen */

/* The glass is a flex box the one visible .screen fills, between a floor and
   a ceiling. Both bounds matter:

     min-height  keeps the handheld looking like a handheld when there is
                 barely anything on the screen;
     max-height  is what makes a long list scroll instead of disappearing —
                 the glass stops growing, .screen stops with it, and
                 .screen__body takes the overflow. Without it a tall screen
                 runs straight past the `overflow: hidden` below and the
                 footer buttons get clipped off the bottom.

   Sizing it this way rather than to one fixed height means a short window
   squeezes the body but never crushes it to nothing: the glass shrinks with
   the viewport, and head and foot (both `flex: none`) keep their room.

   Both bounds are vh only, and there is no width breakpoint on them: a
   narrower window narrows the handheld but never shortens the glass. */
.gb__screen {
  position: relative;
  display: flex;
  min-height: min(calc(66vh + 70px), 630px);
  /* Sized so the whole handheld — bezel, glass and the moulded name under it
     — still fits a laptop window. Past this the list scrolls in the glass. */
  max-height: calc(78vh + 70px);
  border: 3px solid var(--gb-0);
  background: var(--gb-3);
  color: var(--gb-0);
  padding: clamp(12px, 2.2vw, 22px);
  overflow: hidden;
  image-rendering: pixelated;
}

/* Scanlines and a corner glare, drawn over everything but the pointer. */
.gb__screen::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, .16) 0 18%, transparent 42%),
    repeating-linear-gradient(180deg, rgba(15, 56, 15, .16) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

/* Long screens scroll inside the glass, never the page. The screen fills the
   glass and hands the overflow to .screen__body — head and foot are `flex:
   none`, so the buttons stay put and only the middle moves. */
.screen {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.screen[hidden] { display: none; }

.screen__head { flex: none; border-bottom: 3px solid var(--gb-0); padding-bottom: 8px; }

.screen__title {
  margin: 0;
  font: 400 clamp(13px, 2.6vw, 19px)/1.3 var(--pixel);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.screen__sub {
  margin: 6px 0 0;
  font: 12px/1.4 var(--dot);
  color: var(--gb-1);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* The tally's sub-line carries the vote count and, pushed to the far end, the
   copy-a-link button. */
.screen__sub--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.screen__share {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  color: var(--gb-1);
  text-decoration: none;
}
.screen__share:hover,
.screen__share:focus-visible { color: var(--gb-0); }

.screen__share-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
}

/* The flash after a copy. It hangs off the left because the button itself is
   already against the right edge of the glass. */
.screen__share.is-copied::after {
  content: "copied";
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-right: 6px;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--gb-0);
  color: var(--gb-3);
  font: 400 7px/1.2 var(--pixel);
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.screen__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.screen__foot {
  flex: none;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* The list's footer holds the rename at one end and admin mode at the other.
   `margin-left: auto` on the far group is what pins it right whether it is
   one button (ADMIN) or two (EXIT ADMIN, NEW POLL), and `flex-end` keeps it
   against the right edge on a narrow screen too — where the group drops onto
   its own line, and its buttons can wrap again inside it. */
.screen__foot--split { flex-wrap: nowrap; }
.screen__foot-end {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
}

.screen__note {
  margin: 0;
  font: 11px/1.5 var(--dot);
  color: var(--gb-1);
}
.screen__note--warn { color: #7a2f0f; }

/* Nothing on the screen is really white, so the scrollbar isn't either. */
.screen__body::-webkit-scrollbar { width: 10px; }
.screen__body::-webkit-scrollbar-track { background: var(--gb-2); }
.screen__body::-webkit-scrollbar-thumb { background: var(--gb-1); border: 2px solid var(--gb-2); }

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

.gb-btn {
  display: inline-block;
  border: 3px solid var(--gb-0);
  border-radius: 6px;
  background: var(--gb-2);
  box-shadow: 3px 3px 0 var(--gb-1);
  padding: 8px 14px;
  font: 400 9px/1.2 var(--pixel);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--gb-0);
  text-decoration: none;
  cursor: pointer;
}
.gb-btn:hover,
.gb-btn:focus-visible {
  background: var(--gb-0);
  color: var(--gb-3);
  box-shadow: 3px 3px 0 var(--gb-1);
}
.gb-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--gb-1); }
.gb-btn[disabled] { opacity: .45; cursor: default; }
.gb-btn--wide { padding: 12px 22px; font-size: 11px; }
/* The close-this-vote X on an admin's row: square, and the one button on the
   page that reads as a warning rather than a choice. */
.gb-btn--x {
  flex: none;
  padding: 8px 11px;
  color: #7a2f0f;
  border-color: #7a2f0f;
}
.gb-btn--x:hover,
.gb-btn--x:focus-visible { background: #7a2f0f; color: var(--gb-3); }
.gb-btn--x:focus-visible { outline-color: #7a2f0f; }
.gb-btn:focus-visible { outline: 3px solid var(--gb-0); outline-offset: 3px; }

/* -------------------------------------------------------------- the list */

.rows { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 3px solid var(--gb-0);
  background: var(--gb-2);
  box-shadow: 3px 3px 0 var(--gb-1);
  padding: 10px 12px;
}
.row__main { flex: 1 1 auto; min-width: 0; }
.row__title {
  margin: 0;
  font: 400 10px/1.5 var(--pixel);
  letter-spacing: .02em;
  overflow-wrap: anywhere;
}
.row__meta {
  margin: 6px 0 0;
  font: 12px/1.3 var(--dot);
  color: var(--gb-1);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.row__tag {
  flex: none;
  align-self: flex-start;
  border: 2px solid var(--gb-0);
  padding: 2px 5px;
  font: 400 7px/1.4 var(--pixel);
  text-transform: uppercase;
}
.row__tag--poll { background: var(--gb-0); color: var(--gb-3); }
/* One button normally; two when an admin is looking, the X beside it. */
.row__act { flex: none; display: flex; gap: 8px; align-items: center; }

.rows__empty {
  margin: 0;
  padding: 30px 10px;
  text-align: center;
  font: 400 10px/1.9 var(--pixel);
  color: var(--gb-1);
}

/* --------------------------------------------------------------- the diff */

.diff {
  margin: 0;
  border: 3px solid var(--gb-0);
  background: var(--gb-2);
  padding: 12px;
  font: 13px/1.7 var(--dot);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Deletions struck out, additions on grey — the two the review screen needs
   to tell apart at a glance, and they still read in one colour scheme. */
.diff del {
  background: none;
  color: var(--gb-1);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.diff ins {
  background: #6e7d5a;
  color: var(--gb-0);
  text-decoration: none;
  box-shadow: 0 0 0 2px #6e7d5a;
}

.legend { display: flex; gap: 14px; margin: 0 0 10px; font: 11px/1.4 var(--dot); }
.legend del, .legend ins { padding: 0 2px; }

.review__meta {
  margin: 0 0 10px;
  font: 12px/1.6 var(--dot);
  color: var(--gb-1);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.review__label {
  margin: 14px 0 6px;
  font: 400 8px/1.4 var(--pixel);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* --------------------------------------------------------- name + polls */

.field { display: block; margin: 0 0 14px; }
.field__label {
  display: block;
  margin-bottom: 8px;
  font: 400 9px/1.6 var(--pixel);
  text-transform: uppercase;
}
.field__input,
.field__area {
  width: 100%;
  border: 3px solid var(--gb-0);
  background: var(--gb-2);
  padding: 10px;
  font: 14px/1.5 var(--dot);
  color: var(--gb-0);
}
.field__area { min-height: 120px; resize: vertical; }
.field__area--short { min-height: 70px; }
.field__input:focus,
.field__area:focus { outline: 3px solid var(--gb-0); outline-offset: 2px; background: var(--gb-3); }

.poll__details {
  margin: 0 0 16px;
  font: 14px/1.7 var(--dot);
  overflow-wrap: anywhere;
}

/* The tally screen repeats the question — it is read on its own, often long
   after the poll was answered. Same treatment as .poll__details. */
.results__details {
  margin: 0 0 16px;
  font: 14px/1.7 var(--dot);
  color: var(--gb-1);
  overflow-wrap: anywhere;
}

/* Adding a choice sits under the list, set apart by a rule so it doesn't read
   as one more thing to pick. */
.poll__add { margin-top: 16px; border-top: 3px solid var(--gb-1); padding-top: 14px; }
.poll__add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0;
}
.poll__new .field { margin-bottom: 10px; }

/* ------------------------------------------------------- the new-poll form */

/* The poll type is picked with the same drawn radios a voter answers a poll
   with, so the form looks like the thing it is about to make. */
#np-kinds { margin-bottom: 16px; }
.np-field { margin-top: 16px; }
.np-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 0 0 14px;
}
.np-num { display: block; }
.np-num .field__input { width: 8ch; }

.choices { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 3px solid var(--gb-0);
  background: var(--gb-2);
  padding: 10px 12px;
  font: 14px/1.4 var(--dot);
  cursor: pointer;
}
.choice:hover { background: var(--gb-3); }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }

/* The box/dot is drawn, not native — a checkbox with a UA look would be the
   one thing on the screen that isn't from 1989. */
.choice__box {
  flex: none;
  width: 16px;
  height: 16px;
  border: 3px solid var(--gb-0);
  background: var(--gb-3);
}
.choice--radio .choice__box { border-radius: 50%; }
.choice input:checked + .choice__box { background: var(--gb-0); box-shadow: inset 0 0 0 3px var(--gb-3); }
.choice input:focus-visible + .choice__box { outline: 3px solid var(--gb-0); outline-offset: 2px; }
.choice--on { background: var(--gb-3); }

/* ------------------------------------------------------------- results */

/* The proposed amendment, sat above the tally on the results screen. */
.results__amendment { margin-bottom: 18px; }

.tally { display: flex; flex-direction: column; gap: 12px; margin: 0 0 18px; }
.tally__row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.tally__label { font: 400 9px/1.5 var(--pixel); text-transform: uppercase; }
.tally__count { font: 400 9px/1.5 var(--pixel); }
.tally__bar {
  grid-column: 1 / -1;
  height: 14px;
  border: 3px solid var(--gb-0);
  background: var(--gb-2);
}
.tally__fill { height: 100%; background: var(--gb-0); }

.ballots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ballot {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  border-bottom: 2px dotted var(--gb-1);
  padding: 6px 2px;
  font: 13px/1.5 var(--dot);
}
.ballot__who { font-weight: 400; text-transform: uppercase; }
.ballot__what { color: var(--gb-1); text-align: right; overflow-wrap: anywhere; }

/* --------------------------------------------------------------- chrome */

.gb__brand {
  margin: 12px 4px 0;
  /* The model name is the only thing moulded into the shell now, so it gets
     the whole width instead of sharing the row with a subtitle. */
  text-align: center;
  font: 400 clamp(9px, 2.2vw, 13px)/1.4 var(--pixel);
  letter-spacing: .04em;
  color: #d7e8c4;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .5);
}

.gb__back {
  display: inline-block;
  margin: 14px auto 0;
  font: 12px/1.4 var(--dot);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #7cff3f;
  text-decoration: none;
}
.gb__back:hover { color: #d7ffb8; }

.gb__foot { text-align: center; }

/* The alien lives in the footer and does nothing but hover there. */
.alien {
  display: block;
  margin: 6px auto 0;
  image-rendering: pixelated;
  animation: alien-bob 3.4s ease-in-out infinite;
}
@keyframes alien-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
@media (prefers-reduced-motion: reduce) {
  .alien { animation: none; }
}

@media (max-width: 560px) {
  .row { flex-wrap: wrap; }
  .row__act { width: 100%; }
  /* The action button takes the width it can; the X keeps its square. */
  .row__act .gb-btn { flex: 1 1 auto; text-align: center; }
  .row__act .gb-btn--x { flex: none; }
  /* Two footers' worth of buttons don't always fit on one narrow line, so let
     them wrap — the admin group keeps its `margin-left: auto` either way, and
     lands right-aligned on the line it ends up on. */
  .screen__foot--split { flex-wrap: wrap; }
}

/* The shared starfields would tile straight through the matrix; this is the
   one page that brings its own backdrop, so switch them off here. */
html:has(.theme-matrix)::before,
html:has(.theme-matrix)::after { display: none; }
