/* Retro CRT theme for Refine-o-matic.
   The page is a screen inside a plastic monitor bezel: rounded, vignetted corners,
   scanlines, an RGB phosphor mask, a slowly rolling scan bar, flicker, colour fringing
   and a power-on animation.
   Dark = amber-phosphor PC monitor. Light = 1980s white-screen computer. */

:root {
  /* Light: white screen, black pixels, beige case */
  --bezel: #d8d0bd;
  --bezel-edge: #b9b09a;
  --screen-solid: #e4e6df;
  --screen: radial-gradient(ellipse 110% 90% at 50% 45%, #eef0e9, #e1e3dc 60%, #cfd2ca);
  --fg: #141618;
  --fg-dim: rgba(20, 22, 24, .62);
  --fg-faint: rgba(20, 22, 24, .14);
  --accent: #141618;           /* mono screen: highlights are inverted */
  --on-accent: #e4e6df;
  --ok: #2b6e2b;
  --warn: #9b1c1c;
  --glow: 0 0 1px rgba(20, 22, 24, .35);
  --bloom: 0 0 2px rgba(20, 22, 24, .4);
  --fringe: -.6px 0 rgba(255, 0, 60, .18), .6px 0 rgba(0, 140, 255, .18);
  --vignette: rgba(0, 0, 0, .28);
  --scan: rgba(0, 0, 0, .07);
  --font: "Px437 IBM VGA8", "Perfect DOS VGA 437", "IBM Plex Mono", ui-monospace, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  /* Dark: amber phosphor, dark plastic case */
  --bezel: #2b2823;
  --bezel-edge: #1a1815;
  --screen-solid: #140c02;
  --screen: radial-gradient(ellipse 110% 90% at 50% 45%, #22160a, #140c02 60%, #070401);
  --fg: #ffb000;
  --fg-dim: rgba(255, 176, 0, .62);
  --fg-faint: rgba(255, 176, 0, .15);
  --accent: #ffe08a;           /* "white-hot" amber */
  --on-accent: #140c02;
  --ok: #ffe08a;
  --warn: #ff6b4a;
  --glow: 0 0 5px rgba(255, 176, 0, .55);
  --bloom: 0 0 8px rgba(255, 176, 0, .85), 0 0 22px rgba(255, 140, 0, .45);
  --fringe: -1px 0 rgba(255, 0, 60, .35), 1px 0 rgba(0, 170, 255, .3);
  --vignette: rgba(0, 0, 0, .65);
  --scan: rgba(0, 0, 0, .32);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* ---------- The monitor: bezel (html) around a rounded screen (body) ---------- */
html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  /* Must be set here: otherwise the body's overflow (clip, below) would be passed on
     to the whole window and the page could no longer scroll. */
  overflow-x: hidden; overflow-y: auto;
  background: var(--bezel);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, .12));
}
body {
  --gap: 10px;
  --corner: 26px;
  margin: var(--gap);
  min-height: calc(100dvh - 2 * var(--gap));
  border-radius: var(--corner);
  overflow: clip;              /* round the screen without breaking the sticky header */
  background: var(--screen); background-color: var(--screen-solid);
  box-shadow: 0 0 0 3px var(--bezel-edge), inset 0 0 0 1px rgba(0, 0, 0, .4);
  font: 400 1rem/1.55 var(--font);
  letter-spacing: .02em;
  color: var(--fg);
  text-shadow: var(--fringe), var(--glow);
  animation: crt-power-on .7s cubic-bezier(.2, .8, .2, 1) both;
}
/* Power on: a bright line opens up into the picture */
@keyframes crt-power-on {
  0%   { transform: scale(.85, .004); filter: brightness(4) saturate(0); opacity: .2; }
  35%  { transform: scale(1, .004);   filter: brightness(4) saturate(0); opacity: 1; }
  70%  { transform: scale(1, 1.02);   filter: brightness(1.6); }
  100% { transform: none;             filter: none; }
}

/* Curvature shading: dark, rounded inner edge of the glass */
body::before {
  content: ""; position: fixed; z-index: 79; pointer-events: none;
  inset: var(--gap); border-radius: var(--corner);
  box-shadow: inset 0 0 70px 12px var(--vignette), inset 0 0 6px 2px rgba(0, 0, 0, .35);
  background: radial-gradient(ellipse 140% 100% at 50% 0%, rgba(255, 255, 255, .06), transparent 40%);
}
/* Scanlines + RGB phosphor mask + flicker */
body::after {
  content: ""; position: fixed; z-index: 80; pointer-events: none;
  inset: var(--gap); border-radius: var(--corner);
  background:
    repeating-linear-gradient(0deg, var(--scan) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 0, 0, .05) 0 1px, rgba(0, 255, 0, .04) 1px 2px, rgba(0, 0, 255, .05) 2px 3px);
  animation: crt-flicker 5s steps(1, end) infinite;
}
@keyframes crt-flicker { 0%, 100% { opacity: 1; } 31% { opacity: .82; } 32% { opacity: 1; } 77% { opacity: .9; } 78% { opacity: 1; } }
/* Scan bar slowly rolling down the screen */
html::after {
  content: ""; position: fixed; z-index: 81; pointer-events: none;
  left: 10px; right: 10px; top: 0; height: 18vh;
  background: linear-gradient(transparent, rgba(255, 255, 255, .045), transparent);
  animation: crt-roll 9s linear infinite;
}
:root[data-theme="dark"]::after { background: linear-gradient(transparent, rgba(255, 190, 80, .06), transparent); }
@keyframes crt-roll { from { transform: translateY(-20vh); } to { transform: translateY(110vh); } }

button, input { font: inherit; color: inherit; letter-spacing: inherit; text-shadow: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px dashed var(--fg); outline-offset: 3px; }
::selection { background: var(--fg); color: var(--screen-solid); }

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

.container {
  max-width: 60rem; margin: 0 auto;
  padding: 0 max(1.5rem, env(safe-area-inset-right)) 2rem max(1.5rem, env(safe-area-inset-left));
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: var(--screen-solid);
  border-bottom: 2px solid var(--fg);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.25rem; }
.brand {
  font-weight: 700; font-size: 1.0625rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--fg); text-decoration: none; white-space: nowrap;
  text-shadow: var(--fringe), var(--bloom);
}
.brand::before { content: "\25A0  "; } /* ■ */
.header-actions { display: flex; align-items: center; gap: .125rem; min-width: 0; }

.nav-session {
  display: flex; flex-direction: column; min-width: 0; line-height: 1.2;
  padding-right: .75rem; margin-right: .375rem; border-right: 2px solid var(--fg-faint);
}
.nav-session-label { font-size: .6875rem; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .1em; }
.nav-session-name {
  font-weight: 700; font-size: .875rem; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem;
}

.icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: 2.75rem; height: 2.75rem; padding: 0;
  background: transparent; color: var(--fg); border: 0; border-radius: 0;
}
.icon-button svg {
  width: 1.25rem; height: 1.25rem;
  fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: square; stroke-linejoin: miter;
  filter: drop-shadow(0 0 3px var(--fg-dim));
}
.icon-button svg .dot { fill: currentColor; stroke: none; }
@media (hover: hover) { .icon-button:hover { background: var(--fg); color: var(--screen-solid); } }
.icon-button:active { background: var(--fg-dim); }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Headings ---------- */
h1 {
  font-size: 1.625rem; line-height: 1.25; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  margin: 1.75rem 0 .75rem; overflow-wrap: anywhere;
  text-shadow: var(--fringe), var(--bloom);
}
h2 {
  font-size: .875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .14em;
  color: var(--fg-dim); margin: 1.5rem 0 .5rem;
}
h2::before { content: "\25B8  "; } /* ▸ */
.lead { color: var(--fg-dim); margin: 0 0 1.5rem; max-width: 40rem; }
.progress { color: var(--fg-dim); margin: 0; font-size: .9375rem; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- Join form ---------- */
.panel { max-width: 32rem; padding: 1.25rem; border: 3px double var(--fg); }
.field { margin: 0 0 1.25rem; }
label { display: block; font-weight: 700; margin-bottom: .375rem; text-transform: uppercase; letter-spacing: .08em; font-size: .875rem; }
input {
  display: block; width: 100%; padding: .625rem .75rem;
  background: var(--fg-faint); color: var(--fg); caret-color: var(--fg);
  border: 0; border-bottom: 2px solid var(--fg); border-radius: 0;
  font-size: 1rem; /* 16px: no iOS zoom */
}
input:focus-visible { outline: 2px dashed var(--fg); outline-offset: 2px; }

/* ---------- Buttons: chunky, inverted ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.875rem; padding: .5rem 1rem;
  border: 2px solid var(--fg); border-radius: 0;
  font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  box-shadow: 4px 4px 0 var(--fg-faint);
  transition: transform .08s ease, box-shadow .08s ease, background-color .12s ease, color .12s ease;
}
.btn-primary { background: var(--fg); color: var(--screen-solid); text-shadow: none; box-shadow: 4px 4px 0 var(--fg-faint), var(--bloom); }
.btn-secondary { background: transparent; color: var(--fg); }
@media (hover: hover) {
  .btn-secondary:hover:not(:disabled) { background: var(--fg-faint); }
  .btn-primary:hover:not(:disabled) { filter: brightness(1.15); }
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--fg-faint); }
.btn:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }
#join-form .btn { width: 100%; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1rem; max-width: 32rem; }

.error { color: var(--warn); font-weight: 700; margin: 0; text-transform: uppercase; }
.error:not(:empty) { margin: .5rem 0; animation: crt-error-blink .5s steps(1, end) 3; }
@keyframes crt-error-blink { 50% { opacity: 0; } }

/* ---------- Team ---------- */
.people {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .375rem;
}
.person {
  display: flex; align-items: center; gap: .5rem;
  min-height: 2.875rem; padding: .25rem .5rem;
  border: 1px dashed var(--fg-faint);
  transition: border-color .2s ease, opacity .2s ease;
}
.person.voted { border: 1px solid var(--fg-dim); }
.person.offline { opacity: .4; }
.person .status { display: none; }
.avatar {
  flex: none; width: 2rem; height: 2rem; display: grid; place-items: center;
  font-size: .75rem; font-weight: 700;
  background: var(--fg-faint); color: var(--fg);
}
.who { flex: 1; min-width: 0; }
.person-name {
  display: block; font-weight: 700; font-size: .9375rem; line-height: 1.25; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.person-name .you { font-weight: 400; color: var(--fg-dim); }
.person .tag:empty { display: none; }
.person .tag {
  display: inline-block; margin-top: .15rem; padding: 0 .3rem;
  font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  background: var(--fg); color: var(--screen-solid); text-shadow: none;
}
.person.extreme { border: 2px solid var(--fg); }

/* Seat card: dithered back, flips on reveal */
.mini { width: 1.75rem; height: 2.375rem; flex: none; perspective: 300px; }
.mini-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .9, .25, 1);
}
.mini.revealed .mini-inner { transform: rotateY(180deg); }
.mini-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center;
  font-size: .9375rem; font-weight: 700;
}
.mini-back { border: 1px dashed var(--fg-faint); }
.mini.voted .mini-back {
  border: 2px solid var(--fg);
  background: repeating-conic-gradient(var(--fg-dim) 0 25%, transparent 0 50%) 0 0 / 4px 4px; /* dither */
}
.mini-front { transform: rotateY(180deg); border: 2px solid var(--fg); background: var(--screen-solid); color: var(--fg); }

/* ---------- Result ---------- */
.summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem;
  margin: .75rem 0 0; padding: 1rem 1.25rem;
  border: 3px double var(--fg);
  background: var(--screen-solid);
  --bar-top: var(--accent);
}
.summary:not(.shown) { display: none; }
.summary-main { display: flex; flex-direction: column; }
.summary-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .16em; color: var(--fg-dim); }
.summary-label::before { content: "\25A0  "; }
.summary .big { font-size: 3.5rem; font-weight: 700; line-height: 1.05; text-shadow: var(--fringe), var(--bloom); }
.summary-side { display: flex; flex-direction: column; gap: .5rem; flex: 1 1 12rem; min-width: 0; }
.summary .meta { font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.bar-v { font-size: 1rem; }
.bar-track i { opacity: .5; }
.summary.is-consensus { background: var(--fg); color: var(--screen-solid); text-shadow: none; --bar-top: currentColor; box-shadow: var(--bloom); }
.summary.is-consensus .summary-label { color: inherit; opacity: .75; }
.summary.is-consensus .big { text-shadow: none; }

/* ---------- Your hand: character-cell cards ---------- */
.deck {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem;
  max-width: 32rem; padding-top: 6px;
}
.card {
  aspect-ratio: 4 / 5; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--fg);
  border: 3px double var(--fg-dim); border-radius: 0;
  font-size: 1.5rem; font-weight: 700;
  user-select: none; -webkit-user-select: none;
  transition: transform .15s ease, background-color .1s ease, color .1s ease, border-color .1s ease, rotate .3s ease-out;
}
@media (hover: hover) { .card:hover:not(:disabled) { border-color: var(--fg); background: var(--fg-faint); } }
.card:active:not(:disabled) { transform: scale(.95); }
.card[aria-pressed="true"] {
  background: var(--fg); color: var(--screen-solid); border-color: var(--fg);
  text-shadow: none; box-shadow: var(--bloom);
  transform: translateY(-5px);
}
.card:disabled { opacity: .35; cursor: not-allowed; transform: none; }

/* ---------- Wide screens ---------- */
@media (min-width: 56rem) {
  #room-view:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem);
    grid-template-areas:
      "title    title"
      "progress side"
      "meter    side"
      "label    side"
      "team     side"
      "actions  side"
      "error    side"
      "note     side";
    grid-template-rows: auto auto auto auto auto auto auto 1fr;
    column-gap: 2rem; align-items: start;
  }
  #room-title { grid-area: title; }
  #room-view .progress { grid-area: progress; }
  #room-view .meter { grid-area: meter; }
  #room-view .section-title { grid-area: label; }
  #room-view .people { grid-area: team; }
  #room-view .actions { grid-area: actions; }
  #room-error { grid-area: error; }
  #observer-note { grid-area: note; }
  #room-view .tray, #room-view .summary { grid-area: side; }
  #room-view .summary { margin-top: 1.5rem; flex-direction: column; align-items: flex-start; }
  #room-view .summary-side { flex: none; width: 100%; }
}

/* ---------- Phones: thinner bezel, everything on one screen ---------- */
@media (max-width: 40rem) {
  body { --gap: 5px; --corner: 16px; }
  html::after { left: 5px; right: 5px; }
  .container { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); padding-bottom: 1rem; }
  .header-inner { gap: .5rem; }
  .brand { font-size: .9375rem; }
  .header-actions { gap: 0; }
  .nav-session { padding-right: .5rem; margin-right: .25rem; }
  .nav-session-name { max-width: 7rem; }
  h1 { font-size: 1.375rem; margin-top: 1.25rem; }
  #room-title { display: none; } /* the session name is in the header */
  .progress { margin-top: .75rem; }
  h2 { margin: 1rem 0 .375rem; }
  .panel { padding: 1rem; }
  .people { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .3rem; }
  .person { min-height: 2.75rem; padding: .2rem .375rem; gap: .375rem; }
  .avatar { width: 1.75rem; height: 1.75rem; font-size: .6875rem; }
  .person-name { font-size: .8125rem; }
  .actions { max-width: none; }
  .deck { max-width: none; gap: .375rem; }
}

/* ---------- Shared components (menu.css, motion.css, shared.css) ---------- */
:root {
  --menu-bg: var(--screen-solid);
  --menu-fg: var(--fg);
  --menu-border: var(--fg);
  --menu-hover: var(--fg-faint);
  --menu-accent: var(--fg);
  --menu-radius: 0;
  --menu-item-radius: 0;
  --menu-shadow: 5px 5px 0 var(--fg-faint), var(--bloom);
  --motion-accent: var(--fg);
  --motion-ok: var(--ok);
  --motion-track: var(--fg-faint);
  --motion-muted: var(--fg-dim);
  --motion-confetti: var(--accent);
  --motion-radius: 0;
  --switch-radius: 0;
  --switch-off: var(--fg-faint);
}
:root .clock { font-family: var(--font); font-size: 1rem; color: var(--fg); text-shadow: var(--fringe), var(--bloom); }
.meter { margin-top: .5rem; height: 10px; border: 1px solid var(--fg-dim); }
.meter-fill { background-image: repeating-linear-gradient(90deg, transparent 0 6px, var(--screen-solid) 6px 8px); } /* segmented bar */

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
  body::after, html::after { animation: none; }
  html::after { display: none; }
  .error:not(:empty) { animation: none; }
  *, *::before, *::after { transition-duration: .01ms !important; transition-delay: 0ms !important; }
  .mini-inner, .mini.revealed .mini-inner { transform: none; }
  .mini-front { transform: none; opacity: 0; }
  .mini.revealed .mini-back { opacity: 0; }
  .mini.revealed .mini-front { opacity: 1; }
  .card[aria-pressed="true"] { transform: none; }
}
@media (prefers-contrast: more) {
  :root { --fg-dim: var(--fg); --fringe: 0 0 transparent; }
  body::after, html::after { display: none; }
}
