:root {
  --accent: #2f6fdf;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1eee8;
  --text: #22232a;
  --muted: #6b6e78;
  --border: #e3dfd6;
  --up: #1f9d63;
  --down: #d1453b;
  --warn-bg: #fff4d6;
  --warn-text: #7a5a00;
  --s1: color-mix(in srgb, var(--accent) 35%, var(--surface-2));
  --s2: var(--accent);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}
/* Dark tokens: used when the OS prefers dark (theme "auto") or when the user picks "dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161b; --surface: #1e2027; --surface-2: #272a33; --text: #ecedf1; --muted: #9da1ad;
    --border: #33363f; --up: #45c98a; --down: #ff7a70; --warn-bg: #3a3218; --warn-text: #f2d27a;
    --shadow: none; --logo-filter: invert(1); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15161b; --surface: #1e2027; --surface-2: #272a33; --text: #ecedf1; --muted: #9da1ad;
  --border: #33363f; --up: #45c98a; --down: #ff7a70; --warn-bg: #3a3218; --warn-text: #f2d27a;
  --shadow: none; --logo-filter: invert(1); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 4px 0; }

/* ---------- layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark .cat { width: 40px; height: 40px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: .8rem; }
.logos { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.logo { height: 40px; width: auto; display: block; }
.group-logo { height: 48px; width: auto; display: block; }
.invert-dark { filter: var(--logo-filter, none); }
.only-dark { display: none !important; }
:root[data-theme="dark"] .only-dark { display: block !important; }
:root[data-theme="dark"] .only-light { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .only-dark { display: block !important; }
  :root:not([data-theme="light"]) .only-light { display: none !important; }
}
.host-login > summary { font-size: .9rem; font-weight: 600; color: var(--accent); }
.host-login[open] > summary { margin-bottom: 8px; }
.host-login input { max-width: 200px; padding: 6px 10px; }
.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.theme-toggle { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 1.1rem; }
.header-links { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.center { text-align: center; align-items: center; }
.narrow { max-width: 460px; margin: 0 auto; width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--down); }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 8px 12px; border-radius: 10px; font-size: .9rem; margin-top: 8px; }

/* ---------- cats */
.cat { display: inline-block; width: 110px; height: 100px; flex-shrink: 0; }
.cat svg { width: 100%; height: 100%; display: block; }
.cat-photo { margin: 0; width: 160px; height: 160px; border-radius: 50%; overflow: hidden; border: 4px solid var(--surface-2); flex-shrink: 0; }
.cat-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.center > .cat, .center > .cat-photo { margin: 0 auto; }

/* ---------- controls */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 12px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .05s, filter .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); }
.btn.big { padding: 14px 20px; font-size: 1.05rem; }
.btn.small { padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

input[type=text], input:not([type]), input[type=url], input[type=date], input[type=password] {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.field input { font-weight: 400; font-size: 1rem; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.check span { display: flex; flex-direction: column; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; font-size: 1.3rem !important; text-align: center; max-width: 220px; }

details > summary { cursor: pointer; font-weight: 700; font-size: 1.15rem; list-style: none; display: flex; align-items: center; gap: 8px; }
details > summary::before { content: "▸"; transition: transform .15s; color: var(--muted); }
details[open] > summary::before { transform: rotate(90deg); }
details[open] > summary { margin-bottom: 16px; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.phase-round1, .badge.phase-round2 { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.badge.phase-reveal1 { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.code-badge { font-family: ui-monospace, monospace; letter-spacing: .1em; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--down); color: #fff; }

/* ---------- home */
.hero { display: flex; gap: 24px; align-items: center; }
.hero-cat .cat { width: 150px; height: 136px; }
.session-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.session-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.session-item.live { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.session-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.session-title { font-weight: 700; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.session-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.session-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- session */
.session-head { display: flex; flex-direction: column; gap: 8px; }
.session-head h1 { overflow-wrap: anywhere; }
.session-head-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.paper-link { font-weight: 600; text-decoration: none; }
.who { font-size: .9rem; }

.join-card { max-width: 480px; width: 100%; margin: 0 auto; }
.vote-card { max-width: 640px; width: 100%; margin: 0 auto; }
.voted { max-width: 560px; width: 100%; margin: 0 auto; }
.round-tag { align-self: flex-start; font-weight: 700; font-size: .85rem; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 4px 10px; border-radius: 999px; }
.prev-vote { background: var(--surface-2); padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; margin-bottom: 10px; font-size: 1.05rem; }

.choices { display: grid; gap: 8px; }
.choices-rating { grid-template-columns: repeat(5, 1fr); }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body {
  display: flex; align-items: center; gap: 10px; height: 100%;
  padding: 10px 12px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.choice:hover .choice-body { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.choice input:checked + .choice-body { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.choice input:focus-visible + .choice-body { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.choice-num { font-weight: 800; font-size: 1.2rem; min-width: 1ch; }
.choice-title { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.choices-rating .choice-body { flex-direction: column; text-align: center; gap: 4px; padding: 10px 6px; }
.choices-rating .cat { width: 56px; height: 50px; }
.choices-confidence .choice-body { justify-content: flex-start; }
.paws { font-size: .8rem; width: 6.5em; flex-shrink: 0; letter-spacing: -.1em; }

.my-shift { display: flex; align-items: center; gap: 16px; }
.my-shift .cat { width: 72px; height: 66px; }
.my-shift-line { font-size: 1.5rem; font-weight: 800; }

/* ---------- host */
.host-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.join-box { display: flex; gap: 20px; align-items: center; }
.qr { width: 190px; flex-shrink: 0; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { width: 100%; height: auto; display: block; }
.join-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.join-url { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; margin-bottom: 8px; }
.big-code { font-family: ui-monospace, monospace; font-size: 2.6rem; font-weight: 800; letter-spacing: .12em; line-height: 1.1; }
.live-count { font-weight: 700; margin-top: 6px; }

.stepper { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: step; }
.stepper li { counter-increment: step; display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; }
.stepper li::before {
  content: counter(step); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); flex-shrink: 0;
}
.stepper li.done::before { content: "✓"; background: color-mix(in srgb, var(--up) 20%, transparent); color: var(--up); border-color: transparent; }
.stepper li.current { color: var(--text); }
.stepper li.current::before { background: var(--accent); color: #fff; border-color: var(--accent); }
.progress { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--up); border-radius: 999px; transition: width .3s; }

/* ---------- results */
.verdict { display: flex; align-items: center; gap: 14px; }
.verdict .cat { width: 84px; height: 76px; }
.verdict-label { font-size: 1.7rem; font-weight: 800; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.tile-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: .85rem; color: var(--muted); }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.swatch.s1, .bar.s1 { background: var(--s1); }
.swatch.s2, .bar.s2 { background: var(--s2); }
.charts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.chart h3 { margin-bottom: 8px; }
.bar-row { display: grid; grid-template-columns: 10.5em minmax(0, 1fr); gap: 10px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--border); }
.bar-row:last-child { border-bottom: 0; }
.bar-label { font-size: .85rem; line-height: 1.2; }
.bars { display: flex; flex-direction: column; gap: 3px; }
.bar-line { display: flex; align-items: center; gap: 6px; }
.bar { height: 14px; border-radius: 0 4px 4px 0; min-width: 2px; transition: width .4s; }
.bar-count { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.shift-summary { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.table-wrap { overflow-x: auto; }
.people { width: 100%; border-collapse: collapse; font-size: .95rem; }
.people th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.people td { padding: 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.people tr.me td { background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }

/* ---------- responsive */
@media (max-width: 760px) {
  .host-grid, .charts { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .join-box { flex-direction: column; text-align: center; }
  .join-info { align-items: center; }
}
@media (max-width: 560px) {
  .hero { flex-direction: column; text-align: center; }
  .hero .row { justify-content: center; }
  .hero-cat .cat { width: 110px; height: 100px; }
  .choices-rating { grid-template-columns: minmax(0, 1fr); }
  .choices-rating .choice-body { flex-direction: row; text-align: left; gap: 10px; padding: 6px 12px; }
  .choices-rating .cat { width: 44px; height: 40px; }
  .session-item { flex-direction: column; align-items: stretch; }
  .session-actions { justify-content: flex-end; }
  .bar-row { grid-template-columns: 7.5em minmax(0, 1fr); }
  .logo { height: 28px; }
  .brand-text small { display: none; }
  .card { padding: 16px; }
}

/* Projector-friendly: bigger results on large screens */
@media (min-width: 1400px) {
  .host .container, .container { max-width: 1200px; }
}
