:root {
  --bg: #f7f5f2;
  --panel: #ffffff;
  --ink: #1e2230;
  --muted: #6b7280;
  --line: #e6e3dd;
  --in: #1f8a70;
  --in-bg: #e6f4ef;
  --out: #d1495b;
  --out-bg: #fbe9ea;
  --accent: #2f5ea8;
  --accent-soft: #e4ecf6;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wide .wrap { max-width: 980px; }

h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.role-grid {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

.role-btn {
  display: block;
  width: 100%;
  padding: 28px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.15rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}

.role-btn span {
  display: block;
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 6px;
}

.role-btn.presenter { border-color: var(--accent); }
.role-btn.audience { border-color: var(--in); }

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 1.05rem;
  margin-bottom: 16px;
}

input[type="text"].code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 1.4rem;
  text-align: center;
  font-weight: 700;
}

button.primary {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-in {
  width: 100%;
  padding: 34px 20px;
  border-radius: var(--radius);
  border: none;
  background: var(--in);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-out {
  width: 100%;
  padding: 34px 20px;
  border-radius: var(--radius);
  border: none;
  background: var(--out);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}

.status-panel {
  text-align: center;
}

.status-panel .state-label {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 18px;
}

.mini-stat {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}

.status-panel.in .state-label { color: var(--in); }
.status-panel.out .state-label { color: var(--out); }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 14px;
}

.code-display {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-align: center;
  color: var(--accent);
  margin: 4px 0 16px;
}

.qr-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.qr-row img {
  width: 160px;
  height: 160px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.join-url {
  font-size: 0.95rem;
  color: var(--muted);
  word-break: break-all;
  text-align: center;
}

.big-stat {
  text-align: center;
  padding: 8px 0 20px;
}

.big-stat .num {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
}

.big-stat .num .out-count { color: var(--out); }
.big-stat .num .sep { color: var(--muted); font-weight: 400; }
.big-stat .num .total { color: var(--muted); }

.big-stat .label {
  color: var(--muted);
  margin-top: 6px;
  font-size: 1rem;
}

.legend {
  display: flex;
  gap: 18px;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 10px;
}

.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot.in { background: var(--in); }
.dot.out { background: var(--out); }
.dot.slide { background: var(--accent); border-radius: 2px; }

.slide-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 4px 0 16px;
  flex-wrap: wrap;
}

.slide-row label {
  margin-bottom: 0;
  font-weight: 600;
  color: var(--ink);
}

.slide-row input[type="text"] {
  margin-bottom: 0;
  width: 120px;
}

button.secondary {
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

canvas#chart {
  width: 100%;
  height: 220px;
  display: block;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--in-bg);
  color: var(--in);
  font-size: 0.8rem;
  font-weight: 600;
}

footer.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: auto;
  padding-top: 24px;
}

a.back {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 28px;
  width: auto;
  display: block;
}

.reason-panel {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.reason-title {
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.reason-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.reason-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.reason-option input { accent-color: var(--accent); width: 18px; height: 18px; }

#reasonOtherText {
  margin-bottom: 10px;
}

.reason-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
}

.reason-actions .link-btn { margin-top: 0; }

.reason-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.reason-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--accent-soft, #e4ecf6);
  z-index: 0;
}

.reason-label, .reason-count {
  position: relative;
  z-index: 1;
}

.reason-count { font-weight: 700; }

.reason-panel + .reason-panel { margin-top: 10px; }

#reasonPanel.reason-panel {
  margin-top: 4px;
  margin-bottom: 0;
}

.callout-ended {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* ---- v4: session words, PowerPoint sync card ---- */
.code-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 4px;
}

.code-display { font-size: clamp(2.4rem, 8vw, 3.6rem); letter-spacing: 0.12em; }

.sync-steps { margin: 0 0 12px; padding-left: 20px; font-size: 0.92rem; line-height: 1.7; }
.sync-steps code, .cmd-box code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85rem; }
.cmd-box {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.cmd-box code { flex: 1; word-break: break-all; }
.cmd-box button { flex-shrink: 0; }

/* ---- v4: presenter live view (one big pie chart) ---- */
.live-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.live-bar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.live-bar .spacer { flex: 1; }
.live-label { color: var(--muted); font-size: 0.95rem; }
.live-item { display: inline-flex; align-items: baseline; gap: 8px; font-size: 1.1rem; }
.live-key { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
input[type="text"].slide-mini {
  width: 4.2rem;
  margin: 0 0 0 4px;
  padding: 4px 8px;
  font-size: 0.85rem;
  border-radius: 8px;
}
.end-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--out);
  background: var(--panel);
  color: var(--out);
  font-weight: 600;
  cursor: pointer;
}
.ended-badge {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--out-bg);
  color: var(--out);
  font-weight: 700;
}

.pie-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5vw, 80px);
  padding: 20px 24px;
}
.pie-stage svg {
  height: 100%;
  max-width: 62vw;
  aspect-ratio: 1 / 1;
  flex: 0 1 auto;
  min-width: 0;
}
.pie-num { font-size: 26px; font-weight: 800; fill: #fff; }
.pie-pct { font-size: 11px; font-weight: 600; fill: rgba(255, 255, 255, 0.92); }

.pie-legend { display: flex; flex-direction: column; gap: 28px; }
.pie-legend-item { display: flex; flex-direction: column; font-size: clamp(1rem, 2vw, 1.6rem); color: var(--muted); }
.pie-big { font-size: clamp(3.5rem, 11vw, 9rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.pie-legend-item.in .pie-big { color: var(--in); }
.pie-legend-item.out .pie-big { color: var(--out); }

.live-exports {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.live-exports .link-btn { margin-top: 0; }

@media (max-aspect-ratio: 1/1) {
  .pie-stage { flex-direction: column; }
  .pie-stage svg { height: auto; width: 88vw; max-width: none; }
  .pie-legend { flex-direction: row; gap: 48px; }
}

/* ---- v4: audience — one big toggle ---- */
.live-audience { margin-top: 24px; }
.toggle-btn {
  display: block;
  width: 100%;
  min-height: 40vh;
  border: none;
  border-radius: 28px;
  color: #fff;
  font-size: clamp(2.6rem, 14vw, 4.5rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn.is-in { background: var(--out); } /* shows "I'M OUT" (the action) */
.toggle-btn.is-out { background: var(--in); } /* shows "I'M BACK" */
.toggle-btn:active { filter: brightness(0.92); }
.toggle-hint { text-align: center; color: var(--muted); margin: 14px 0 0; font-size: 0.95rem; }

/* ---- v5: PowerPoint connection indicator ---- */
.sync-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c9c4bb;
  margin-right: 8px;
}
.sync-dot.on { background: var(--in); }
