/* Terminal theme for Refine-o-matic.
   Dark = green-phosphor CRT (glow + scanlines). Light = "printout": dark ink on cream paper.
   Monospace everywhere, square corners, bracketed buttons, inverted selection. */

:root {
  /* Light: printout */
  --bg: #f4f1e6;
  --bg-solid: #f4f1e6;
  --fg: #1d2b1f;
  --fg-dim: rgba(29, 43, 31, .62);
  --fg-faint: rgba(29, 43, 31, .14);
  --accent: #0a7d2c;
  --on-accent: #fff;
  --warn: #b3261e;
  --glow: none;
  --glow-strong: none;
  --font: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  /* Dark: green phosphor CRT */
  --bg: radial-gradient(ellipse 120% 90% at 50% 40%, #0d1d10, #050a06 70%, #020402);
  --bg-solid: #071009;
  --fg: #39ff6e;
  --fg-dim: rgba(57, 255, 110, .62);
  --fg-faint: rgba(57, 255, 110, .16);
  --accent: #ffcc33;          /* amber highlight */
  --on-accent: #071009;
  --warn: #ff6b5e;
  --glow: 0 0 4px rgba(57, 255, 110, .45);
  --glow-strong: 0 0 8px rgba(57, 255, 110, .8), 0 0 18px rgba(57, 255, 110, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg-solid); }
body {
  margin: 0; min-height: 100dvh;
  font: 400 1rem/1.55 var(--font);
  color: var(--fg); background: var(--bg); background-attachment: fixed;
  text-shadow: var(--glow);
}
/* CRT scanlines + gentle flicker (dark mode only) */
:root[data-theme="dark"] body::after {
  content: ""; position: fixed; inset: 0; z-index: 80; pointer-events: none;
  background: repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, .22) 2px 3px);
  animation: crt-flicker 6s steps(1, end) infinite;
}
@keyframes crt-flicker { 0%, 100% { opacity: .9; } 47% { opacity: .75; } 48% { opacity: .95; } }

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; text-shadow: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px dashed var(--accent); outline-offset: 3px; }
::selection { background: var(--fg); color: var(--bg-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: status line ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: var(--bg-solid);
  border-bottom: 1px solid var(--fg-dim);
}
.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; color: var(--fg); text-decoration: none; white-space: nowrap; }
.brand::before { content: "> "; color: var(--fg-dim); }
.brand::after { content: "_"; animation: cursor-blink 1s steps(1, end) infinite; }
@keyframes cursor-blink { 50% { opacity: 0; } }
.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: 1px solid var(--fg-faint);
}
.nav-session-label { font-size: .6875rem; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .08em; }
.nav-session-name {
  font-weight: 700; font-size: .875rem;
  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;
  transition: background-color .15s ease, color .15s ease;
}
.icon-button svg {
  width: 1.25rem; height: 1.25rem;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter;
  filter: drop-shadow(var(--glow));
}
:root:not([data-theme="dark"]) .icon-button svg { filter: none; }
.icon-button svg .dot { fill: currentColor; stroke: none; }
@media (hover: hover) { .icon-button:hover { background: var(--fg); color: var(--bg-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: prompt style ---------- */
h1 {
  font-size: 1.625rem; line-height: 1.25; font-weight: 700;
  margin: 1.75rem 0 .75rem; overflow-wrap: anywhere;
}
h1::before { content: "$ "; color: var(--fg-dim); }
h2 {
  font-size: .875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em;
  color: var(--fg-dim); margin: 1.5rem 0 .5rem;
}
h2::before { content: "// "; }
.lead { color: var(--fg-dim); margin: 0 0 1.5rem; max-width: 40rem; }
.progress { color: var(--fg-dim); margin: 0; font-size: .9375rem; }
.progress::before { content: "> "; }

/* ---------- Join form ---------- */
.panel { max-width: 32rem; padding: 1.25rem; border: 1px solid var(--fg-dim); }
.field { margin: 0 0 1.25rem; }
label { display: block; font-weight: 700; margin-bottom: .375rem; text-transform: lowercase; }
label::after { content: ":"; }
.switch, .switch::after { text-transform: none; }
.switch::after { content: none; }
input {
  display: block; width: 100%; padding: .625rem .75rem;
  background: transparent; color: var(--fg); caret-color: var(--fg);
  border: 1px solid var(--fg-dim); border-radius: 0;
  font-size: 1rem; /* 16px: no iOS zoom */
  text-shadow: var(--glow);
}
input:focus-visible { outline: 2px dashed var(--accent); outline-offset: 2px; border-color: var(--fg); }

/* ---------- Buttons: [ bracketed ] ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35em;
  min-height: 2.875rem; padding: .5rem 1rem;
  border: 1px solid var(--fg); border-radius: 0;
  font-weight: 700; text-transform: lowercase;
  transition: background-color .12s ease, color .12s ease;
}
.btn:not(.react-toggle)::before { content: "["; opacity: .7; }
.btn:not(.react-toggle)::after { content: "]"; opacity: .7; }
.btn-primary { background: var(--fg); color: var(--bg-solid); text-shadow: none; box-shadow: var(--glow-strong); }
.btn-secondary { background: transparent; color: var(--fg); }
@media (hover: hover) {
  .btn-secondary:hover:not(:disabled) { background: var(--fg-faint); }
  .btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.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; }
.error:not(:empty) { margin: .5rem 0; }
.error:not(:empty)::before { content: "ERR: "; }

/* ---------- Team: a process list ---------- */
.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 solid var(--fg-faint);
  transition: border-color .2s ease, opacity .2s ease;
}
.person.voted { border-color: var(--fg-dim); }
.person.offline { opacity: .45; }
.person .status { display: none; }
.avatar {
  flex: none; min-width: 2.25rem; padding: 0 .15rem; text-align: center;
  font-size: .75rem; font-weight: 700; color: var(--fg-dim);
}
.avatar::before { content: "["; } .avatar::after { content: "]"; }
.who { flex: 1; min-width: 0; }
.person-name {
  display: block; font-weight: 700; font-size: .9375rem; line-height: 1.25;
  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: block; margin-top: .1rem;
  font-size: .6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent);
}
.person .tag::before { content: "!! "; }
.person.extreme { border-color: var(--accent); }

/* Seat card: 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: 1px solid var(--fg);
  background: repeating-linear-gradient(0deg, var(--fg-dim) 0 1px, transparent 1px 4px);
  background-size: 100% 4px;
  animation: crt-roll 1.2s linear infinite;
}
@keyframes crt-roll { to { background-position: 0 4px; } }
.mini-front { transform: rotateY(180deg); border: 1px solid var(--fg); background: var(--bg-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(--bg-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: .14em; color: var(--fg-dim); }
.summary-label::before { content: "== "; } .summary-label::after { content: " =="; }
.summary .big { font-size: 3.25rem; font-weight: 700; line-height: 1.05; text-shadow: var(--glow-strong); }
.summary-side { display: flex; flex-direction: column; gap: .5rem; flex: 1 1 12rem; min-width: 0; }
.summary .meta { font-weight: 700; }
.bar-v { font-size: 1rem; }
.summary.is-consensus { background: var(--fg); color: var(--bg-solid); text-shadow: none; --bar-top: currentColor; }
.summary.is-consensus .summary-label { color: inherit; opacity: .75; }
.summary.is-consensus .big { text-shadow: none; }

/* ---------- Your hand ---------- */
.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: 1px solid 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 .12s ease, color .12s ease, border-color .12s 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(.96); }
.card[aria-pressed="true"] {
  background: var(--fg); color: var(--bg-solid); border-color: var(--fg);
  text-shadow: none; box-shadow: var(--glow-strong);
  transform: translateY(-5px);
}
.card:disabled { opacity: .35; cursor: not-allowed; transform: none; }

/* ---------- Wide screens: list left, hand right ---------- */
@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: everything on one screen ---------- */
@media (max-width: 40rem) {
  .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 { min-width: 2rem; font-size: .6875rem; }
  .person-name { font-size: .875rem; }
  .actions { max-width: none; }
  .deck { max-width: none; gap: .375rem; }
}

/* ---------- Shared components (menu.css, motion.css, shared.css) ---------- */
:root {
  --menu-bg: var(--bg-solid);
  --menu-fg: var(--fg);
  --menu-border: var(--fg);
  --menu-hover: var(--fg-faint);
  --menu-accent: var(--accent);
  --menu-radius: 0;
  --menu-item-radius: 0;
  --menu-shadow: 4px 4px 0 var(--fg-faint);
  --motion-accent: var(--fg);
  --motion-ok: var(--accent);
  --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); }
.meter { margin-top: .5rem; height: 8px; }
.design-menu-title::before { content: "// "; }

@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] body::after { animation: none; }
  .brand::after { 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); }
  :root[data-theme="dark"] body::after { display: none; }
}
