:root {
  --bg: #0b0f1a;
  --panel: #141b2e;
  --panel-2: #1b2440;
  --text: #eef2ff;
  --muted: #8b96b8;
  --accent: #5b8cff;
  --good: #35d6a4;
  --warn: #ffb020;
  --bad: #ff5c6c;
  --ring: #27314f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(91, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(53, 214, 164, 0.10), transparent 55%),
    var(--bg);
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 20px 56px;
}

h1 {
  font-size: 28px;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 15px;
}

.grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--ring);
  border-radius: 18px;
  padding: 22px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 16px;
  font-weight: 600;
}

/* ---- QR card ---- */
#qr {
  background: #fff;
  width: 232px;
  height: 232px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  padding: 12px;
}
#qr img, #qr canvas { width: 208px !important; height: 208px !important; }

.phone-url {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  text-align: center;
  margin-top: 8px;
}

.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---- Live readout ---- */
.readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0 4px;
}

.big-number {
  font-size: 92px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.big-number .unit { font-size: 30px; color: var(--muted); font-weight: 600; margin-left: 6px; }

.status-line {
  font-size: 15px;
  color: var(--muted);
  min-height: 22px;
}
.status-line.good { color: var(--good); }
.status-line.warn { color: var(--warn); }
.status-line.bad { color: var(--bad); }

.ruler {
  position: relative;
  height: 54px;
  margin: 22px 4px 8px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--bad) 0%, var(--warn) 22%, var(--good) 45%, var(--good) 70%, var(--warn) 88%, var(--bad) 100%);
  opacity: 0.85;
}
.ruler .marker {
  position: absolute;
  top: -8px;
  width: 4px;
  height: 70px;
  background: var(--text);
  border-radius: 3px;
  transform: translateX(-50%);
  box-shadow: 0 0 0 3px rgba(11, 15, 26, 0.6);
  transition: left 0.08s linear;
}
.ruler .labels {
  position: absolute;
  bottom: -22px;
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 12px;
  margin-top: 34px;
}
.stat {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }

.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 7px;
  vertical-align: middle;
}
.dot.on { background: var(--good); box-shadow: 0 0 0 4px rgba(53, 214, 164, 0.18); }
.dot.off { background: var(--bad); }

.conn { font-size: 13px; color: var(--muted); margin-top: 18px; }

/* ================= PHONE PAGE ================= */
.phone {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.reading-card {
  background: #fff;
  color: #111;
  border-radius: 16px;
  padding: 26px 22px;
  margin-bottom: 16px;
}
.reading-card .r1 { font-size: 30px; font-weight: 700; margin: 0 0 14px; line-height: 1.2; }
.reading-card .r2 { font-size: 21px; margin: 0 0 12px; line-height: 1.35; }
.reading-card .r3 { font-size: 15px; margin: 0; line-height: 1.4; color: #333; }

.chip {
  position: sticky;
  top: 10px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--ring);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.chip .d { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip .d .unit { font-size: 16px; color: var(--muted); margin-left: 4px; }
.chip-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chip .state { font-size: 13px; color: var(--muted); text-align: right; }
.chip .conn { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.conn-dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(53, 214, 164, 0.18); }
.conn-dot.off { background: var(--bad); }

.preview-wrap {
  position: relative;
  width: 160px;
  margin: 0 auto 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--ring);
  aspect-ratio: 4 / 3;
  background: #000;
}
.preview-wrap video, .preview-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-wrap video { transform: scaleX(-1); }

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 15px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  background: var(--accent);
  color: #fff;
}
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--ring); }
.btn + .btn { margin-top: 10px; }
.btn:disabled { opacity: 0.5; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 20, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  z-index: 20;
}
.overlay h2 { font-size: 22px; margin: 0 0 10px; }
.overlay p { color: var(--muted); max-width: 320px; margin: 0 0 24px; line-height: 1.5; }
.overlay .btn { max-width: 300px; }

.cal-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 12px; line-height: 1.5; }
.hidden { display: none !important; }

/* Sticky submit / measure-again bar on the phone */
.submit-bar {
  position: sticky;
  bottom: 0;
  padding: 14px 0 10px;
  margin-top: 8px;
  background: linear-gradient(transparent, var(--bg) 35%);
}
.submit-bar .btn { margin-top: 0; }

/* Personal feedback banner on the phone */
.me {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.4;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--ring);
  color: var(--muted);
}
.me.ok { background: rgba(53, 214, 164, 0.12); border-color: rgba(53, 214, 164, 0.4); color: #bff3e2; }
.me.myopia { background: rgba(255, 92, 108, 0.12); border-color: rgba(255, 92, 108, 0.4); color: #ffd3d8; }
.me.far { background: rgba(91, 140, 255, 0.12); border-color: rgba(91, 140, 255, 0.4); color: #d4e0ff; }

/* ================= HUB / LANDING PAGE ================= */
.hub { max-width: 1120px; margin: 0 auto; padding: 40px 22px 64px; }
.hub-head { margin-bottom: 36px; }
.hub-head h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: -0.02em; }
.hub-sub { color: var(--text); font-size: 17px; margin: 0 0 10px; opacity: 0.85; }
.hub-disclaimer { color: var(--muted); font-size: 14px; margin: 0; }
.hub-disclaimer strong { color: var(--warn); }

.hub-section { margin-bottom: 36px; }
.hub-section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600; margin: 0 0 14px;
}
.hub-note { color: var(--muted); font-size: 14px; line-height: 1.5; margin: -4px 0 16px; max-width: 760px; }
.hub-note strong { color: var(--text); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.test-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--ring);
  border-radius: 16px;
  padding: 20px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.tc-icon { font-size: 26px; line-height: 1; margin-bottom: 12px; }
.tc-title { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tc-desc { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 8px 0 0; }

.tc-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(255,255,255,0.08); color: var(--muted);
}
.tc-badge.live { background: rgba(53, 214, 164, 0.25); color: #bff3e2; }

/* Live cards are interactive */
.test-card.live { cursor: pointer; border-color: rgba(53, 214, 164, 0.45); }
.test-card.live:hover { transform: translateY(-3px); border-color: var(--good); background: linear-gradient(180deg, #16233a, #1b2b48); }

/* Planned cards are placeholders — visibly inert */
.test-card.planned { opacity: 0.72; cursor: default; }
.test-card.planned .tc-icon { filter: grayscale(0.3); }
.test-card.research { border-style: dashed; }

/* ================= HOST / ROOM PAGE (slide layout) ================= */
/* 2x2 slide: top-left QR, top-right average, bottom participants (full width). */
.slide {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, auto) minmax(0, 1fr);
  grid-template-areas:
    "join summary"
    "board board";
  gap: 18px;
  height: 100vh;
  padding: 18px;
}

.quad {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--ring);
  border-radius: 18px;
  padding: 20px;
  min-width: 0;
  min-height: 0;
}

/* Top-left: big QR */
.q-join {
  grid-area: join;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.q-title { font-size: 20px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.q-join #qr {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  width: min(42vw, 52vh);
  height: min(42vw, 52vh);
  display: flex; align-items: center; justify-content: center;
}
.q-join #qr img, .q-join #qr canvas { width: 100% !important; height: 100% !important; image-rendering: pixelated; }
.room-code { font-size: 18px; color: var(--text); letter-spacing: 0.02em; }
.room-code b { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 22px; color: var(--good); letter-spacing: 0.12em; }
.join-url { font-size: 14px; color: var(--muted); word-break: break-all; text-align: center; }

/* Top-right: average + status */
.q-summary {
  grid-area: summary;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}
.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 8px; }
.back-link:hover { color: var(--text); }
.q-head h1 { font-size: 26px; margin: 0 0 2px; }
.disclaimer { color: var(--muted); font-size: 14px; margin: 0; }
.disclaimer strong { color: var(--warn); }

.avg-block { display: flex; align-items: baseline; gap: 18px; }
.avg-number { font-size: clamp(64px, 9vw, 128px); font-weight: 700; line-height: 0.9; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.avg-number .unit { font-size: 0.35em; color: var(--muted); margin-left: 8px; }
.avg-label { color: var(--muted); font-size: 18px; line-height: 1.25; }

.counts { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 2px; }
.count { font-size: 17px; color: var(--text); }
.count span:last-child { font-weight: 700; }
.cdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.cdot.people { background: var(--accent); }
.cdot.done { background: var(--good); }
.cdot.myopia { background: var(--bad); }
.cdot.far { background: var(--accent); opacity: 0.7; }

.room-status { font-size: 17px; color: var(--muted); line-height: 1.4; }
.room-status.good { color: var(--good); }
.room-status.warn { color: var(--warn); }

/* Bottom: participants fill the quadrant and scroll internally if crowded. */
.q-board {
  grid-area: board;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Participant grid — reflows as people join (compact enough for ~50) */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-auto-rows: min-content;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
}
.empty-hint { color: var(--muted); font-size: 16px; text-align: center; margin: auto; }

.pbox {
  border-radius: 14px;
  padding: 14px 14px 12px;
  border: 1px solid var(--ring);
  background: var(--panel);
  transition: background 0.3s ease, border-color 0.3s ease, opacity 0.3s ease;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pbox-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pnum { font-size: 13px; font-weight: 700; color: var(--muted); }
.pbadge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 7px; border-radius: 999px; background: rgba(255,255,255,0.08); color: var(--muted); white-space: nowrap; }
.pcm { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pcm .u { font-size: 15px; color: var(--muted); margin-left: 3px; }
.pstatus { font-size: 11px; color: var(--muted); line-height: 1.3; margin-top: auto; }

/* Status colors turn the board into a room heatmap */
.pbox.s-ok     { background: rgba(53, 214, 164, 0.14); border-color: rgba(53, 214, 164, 0.45); }
.pbox.s-ok     .pbadge { background: rgba(53, 214, 164, 0.3); color: #d6fff2; }
.pbox.s-myopia { background: rgba(255, 92, 108, 0.16); border-color: rgba(255, 92, 108, 0.5); }
.pbox.s-myopia .pbadge { background: rgba(255, 92, 108, 0.35); color: #ffe0e4; }
.pbox.s-far    { background: rgba(91, 140, 255, 0.14); border-color: rgba(91, 140, 255, 0.45); }
.pbox.s-far    .pbadge { background: rgba(91, 140, 255, 0.3); color: #e2ebff; }
.pbox.s-none   { background: var(--panel); }
.pbox.stale    { opacity: 0.4; }

/* Submitted / locked-in boxes: solid, checked, never dimmed */
.pbox.done { opacity: 1; box-shadow: inset 0 0 0 2px var(--good); }
.pbox.done .pbadge { background: var(--good); color: #042; font-weight: 700; }
