:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #65706a;
  --paper: #fffefa;
  --canvas: #f4f1e9;
  --line: #d9d7cf;
  --green: #1f6b4f;
  --green-dark: #164e3a;
  --green-soft: #e2efe8;
  --orange: #b55c24;
  --red: #a13939;
  --shadow: 0 18px 50px rgba(23, 33, 29, .09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1 { letter-spacing: -.035em; }
a { color: var(--green); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.eyebrow { color: var(--green); font-size: .76rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-bottom: .65rem; }
.eyebrow.light { color: #b8dfce; }
.lead { font-size: 1.12rem; line-height: 1.55; }
.quiet { color: var(--muted); }
.button {
  min-height: 48px; border: 1px solid transparent; border-radius: 12px; padding: .78rem 1.15rem;
  font-weight: 750; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; transition: background-color .15s ease, border-color .15s ease;
}
.button:focus-visible, .text-button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid #e7a66d; outline-offset: 2px;
}
.button:disabled { cursor: not-allowed; opacity: .55; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--paper); border-color: var(--line); color: var(--ink); }
.button.danger { background: #fff; color: var(--red); border-color: #d8aaaa; }
.button.full { width: 100%; }
.button.small { min-height: 40px; padding: .55rem .75rem; font-size: .88rem; }
.text-button { border: 0; background: transparent; color: inherit; padding: .5rem; cursor: pointer; text-decoration: underline; }
.danger-text { color: var(--red); }
.form-error { min-height: 1.4em; color: var(--red); margin: .6rem 0 0; }

.participant-page { min-height: 100dvh; }
.participant-shell {
  min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr);
  place-items: center; padding: 1rem;
}
.participant-card {
  width: min(100%, 560px); background: var(--paper); border: 1px solid rgba(23,33,29,.1);
  border-radius: 24px; padding: clamp(1.6rem, 6vw, 3rem); box-shadow: var(--shadow);
}
.centered { text-align: center; }
.centered h1 { font-size: clamp(2rem, 8vw, 3.2rem); margin-bottom: 1rem; }
.join-form { text-align: left; }
.join-form h1, .join-form > p { text-align: center; }
.join-form label { display: block; margin: 1.5rem 0 .5rem; font-weight: 720; }
.join-form input { width: 100%; min-height: 50px; border: 1px solid var(--line); border-radius: 10px; padding: .75rem .85rem; background: white; }
.join-form .button { margin-top: 1rem; }
.success-mark {
  width: 64px; height: 64px; margin: 0 auto 1.5rem; border-radius: 50%; display: grid;
  place-items: center; background: var(--green-soft); color: var(--green); font-size: 2rem; font-weight: 800;
}
.connection-pill { display: inline-flex; align-items: center; gap: .5rem; margin-top: 1.6rem; color: var(--muted); font-size: .9rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #2d8a66; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; margin: 1.5rem auto 0; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.network-banner { position: fixed; z-index: 20; top: 0; left: 0; right: 0; padding: .65rem 1rem; background: #8a411c; color: white; text-align: center; font-weight: 700; }

.chat-layout {
  width: min(100%, 720px); height: calc(100dvh - 2rem); max-height: 900px; background: var(--paper);
  border: 1px solid rgba(23,33,29,.1); border-radius: 22px; box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto 1fr auto auto auto; overflow: hidden;
}
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.15rem; border-bottom: 1px solid var(--line); }
.chat-header .eyebrow { margin: 0 0 .25rem; }
.partner-status { margin: 0; font-weight: 650; font-size: .95rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 820; border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; background: #f8f7f2; }
.timer.large { font-size: 1.5rem; }
.messages { min-height: 0; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .65rem; }
.message { display: flex; }
.message p { max-width: 82%; margin: 0; padding: .75rem .9rem; line-height: 1.42; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 16px 16px 16px 4px; background: #ecebe5; }
.message.outgoing { justify-content: flex-end; }
.message.outgoing p { background: var(--green); color: white; border-radius: 16px 16px 4px 16px; }
.typing-indicator { padding: .2rem 1rem .6rem; color: var(--muted); font-size: .88rem; }
.message-form { display: flex; align-items: flex-end; gap: .55rem; padding: .75rem 1rem max(.75rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.message-form textarea { resize: none; flex: 1; min-height: 46px; max-height: 120px; border: 1px solid var(--line); border-radius: 14px; padding: .72rem .85rem; background: white; }
.send-button { min-height: 46px; border: 0; border-radius: 12px; padding: 0 1rem; color: white; background: var(--green); font-weight: 750; cursor: pointer; }
.message-meta { margin: -.45rem 1.1rem .45rem; color: var(--muted); text-align: right; font-size: .72rem; }
.vote-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2rem; }
.vote-button { min-height: 88px; font-size: 1.15rem; }
.vote-button.human { background: var(--green); color: white; }
.vote-button.ai { background: #273d55; color: white; }
.result-line { font-size: 1.25rem; font-weight: 780; padding: 1rem; border-radius: 14px; }
.result-line.correct { background: var(--green-soft); color: var(--green-dark); }
.result-line.incorrect { background: #f6e5df; color: #7b302f; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 2rem), 520px); padding: .85rem 1rem; border-radius: 12px; background: var(--ink); color: white; box-shadow: var(--shadow); text-align: center; }

.admin-page { background: #ecebe5; min-height: 100vh; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 420px); padding: 2.2rem; border-radius: 22px; background: var(--paper); box-shadow: var(--shadow); }
.login-card h1 { font-size: 2.4rem; }
.login-card label, .stack-actions label { display: block; font-weight: 720; margin: 1.5rem 0 .5rem; }
.login-card input, .stack-actions select { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; background: white; }
.login-card .button { width: 100%; margin-top: 1rem; }
.admin-topbar { min-height: 92px; padding: 1.15rem clamp(1rem, 3vw, 2.5rem); display: flex; justify-content: space-between; align-items: center; background: var(--ink); color: white; }
.admin-topbar h1 { margin: 0; font-size: 1.55rem; }
.admin-topbar .eyebrow { margin-bottom: .2rem; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.admin-network { font-size: .85rem; color: #b8dfce; }
.admin-network.offline { color: #ffc09a; }
.admin-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); max-width: 1500px; margin: 0 auto; min-height: calc(100vh - 92px); }
.workshop-sidebar { padding: 1.4rem; border-right: 1px solid var(--line); background: #f7f6f1; }
.workshop-sidebar h2 { font-size: .82rem; margin: 2rem 0 .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }
.workshop-list { display: grid; gap: .45rem; }
.workshop-item { width: 100%; text-align: left; border: 1px solid transparent; border-radius: 10px; padding: .75rem; background: transparent; cursor: pointer; }
.workshop-item:hover, .workshop-item.active { background: white; border-color: var(--line); }
.workshop-item strong, .workshop-item span { display: block; }
.workshop-item span { margin-top: .22rem; color: var(--muted); font-size: .78rem; }
.dashboard { padding: clamp(1rem, 3vw, 2.5rem); min-width: 0; }
.empty-state { min-height: 60vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.dashboard-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dashboard-heading h2 { font-size: clamp(1.8rem, 3vw, 2.7rem); margin-bottom: 1.5rem; }
.state-badge { padding: .5rem .75rem; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-weight: 750; }
.state-badge[data-state="CLOSED"] { background: #e3e1dc; color: #575e5a; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, .8fr); gap: 1rem; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: clamp(1.1rem, 2vw, 1.6rem); box-shadow: 0 8px 24px rgba(23,33,29,.04); }
.panel h3 { font-size: 1.25rem; }
.qr-panel { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 1.5rem; align-items: center; }
.qr-image { display: block; width: 100%; aspect-ratio: 1; background: white; }
.participant-link { display: block; overflow-wrap: anywhere; margin: 1.2rem 0; }
.inline-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.big-metric { font-size: clamp(3rem, 7vw, 5rem); font-weight: 820; letter-spacing: -.05em; }
.big-metric small { font-size: 1rem; letter-spacing: 0; color: var(--muted); }
.compact-stats { margin: 1rem 0; }
.compact-stats div { display: flex; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.compact-stats dt { color: var(--muted); }
.compact-stats dd { font-weight: 750; }
.stack-actions { margin-top: 1rem; }
.stack-actions label { margin-top: 0; }
.stack-actions .button { margin-top: .65rem; }
.round-panel, .voting-panel, .results-panel { margin-top: 1rem; }
.round-metrics { display: grid; grid-template-columns: repeat(6, 1fr); gap: .7rem; margin: 1.4rem 0; }
.round-metrics div { padding: 1rem; border-radius: 12px; background: #f3f2ec; }
.round-metrics strong, .round-metrics span { display: block; }
.round-metrics strong { font-size: 1.7rem; }
.round-metrics span { margin-top: .25rem; color: var(--muted); font-size: .82rem; }
.progress-track { height: 12px; border-radius: 999px; background: #deddd7; overflow: hidden; margin: 1.2rem 0; }
.progress-track span { display: block; height: 100%; background: var(--green); transition: width .2s ease; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-bottom: 1.25rem; }
.result-grid div { display: grid; gap: .25rem; padding: 1rem; border-radius: 12px; background: #f3f2ec; }
.result-grid strong { font-size: 1.6rem; }
.result-grid small { color: var(--muted); }
.result-grid .total-result { grid-column: 1 / -1; background: var(--green-soft); }
.dashboard-error { margin: 1rem 0; }
.close-row { display: flex; justify-content: flex-end; margin-top: 1rem; }

@media (max-width: 950px) {
  .admin-layout { grid-template-columns: 1fr; }
  .workshop-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .workshop-list { display: flex; overflow-x: auto; }
  .workshop-item { min-width: 190px; }
  .round-metrics { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .participant-shell { padding: 0; }
  .participant-card { min-height: 100dvh; border: 0; border-radius: 0; box-shadow: none; display: grid; align-content: center; }
  .chat-layout { height: 100dvh; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
  .vote-grid { grid-template-columns: 1fr; }
  .admin-topbar { align-items: flex-start; }
  .admin-network { display: none; }
  .dashboard-grid, .qr-panel { grid-template-columns: 1fr; }
  .qr-image { width: min(100%, 300px); margin: 0 auto; order: -1; }
  .round-metrics { grid-template-columns: repeat(2, 1fr); }
  .result-grid { grid-template-columns: 1fr; }
  .result-grid .total-result { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
