:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1b18;
  --muted: #69645c;
  --border: #e2dfd8;
  --accent: #0f6e63;
  --accent-hover: #0b5a51;
  --accent-ink: #ffffff;
  --accent-soft: #e1f0ec;
  --onscreen: #fff3cf;
  --onscreen-border: #e9c46a;
  --onscreen-ink: #7a5800;
  --warn-soft: #fdf0de;
  --warn-ink: #8a4b08;
  --danger: #b42318;
  --shadow: 0 1px 2px rgb(29 27 24 / 0.06), 0 2px 8px rgb(29 27 24 / 0.04);
  --radius: 14px;
  --radius-sm: 9px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1d1c1a;
    --surface-2: #272522;
    --text: #f1efe9;
    --muted: #a49f95;
    --border: #35332f;
    --accent: #4fc1ae;
    --accent-hover: #6fd3c2;
    --accent-ink: #08201c;
    --accent-soft: #163330;
    --onscreen: #3a2e10;
    --onscreen-border: #8f7224;
    --onscreen-ink: #f3d27a;
    --warn-soft: #3a2a14;
    --warn-ink: #f0c48a;
    --danger: #ff8a7a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141312;
  --surface: #1d1c1a;
  --surface-2: #272522;
  --text: #f1efe9;
  --muted: #a49f95;
  --border: #35332f;
  --accent: #4fc1ae;
  --accent-hover: #6fd3c2;
  --accent-ink: #08201c;
  --accent-soft: #163330;
  --onscreen: #3a2e10;
  --onscreen-border: #8f7224;
  --onscreen-ink: #f3d27a;
  --warn-soft: #3a2a14;
  --warn-ink: #f0c48a;
  --danger: #ff8a7a;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.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;
}

/* ---- layout ------------------------------------------------------------ */

.wrap {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom));
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  min-height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.brand img {
  width: 28px;
  height: 28px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.stack > * + * {
  margin-top: 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

/* ---- surfaces ---------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 12px;
}

.section-head h2 {
  font-size: 1.05rem;
  font-weight: 650;
}

.count {
  color: var(--muted);
  font-weight: 500;
}

.notice {
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--warn-soft);
  color: var(--warn-ink);
  font-weight: 500;
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
}

/* ---- controls ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  font-size: 0.9375rem;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.quiet:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.small {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 0.875rem;
}

.btn.big {
  min-height: 48px;
  padding: 12px 20px;
  font-size: 1rem;
}

.btn.danger {
  color: var(--danger);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.field {
  display: block;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 1rem;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.field::placeholder {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}

textarea.field {
  resize: vertical;
  min-height: 96px;
  line-height: 1.45;
}

.label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 6px;
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 500;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 550;
  font-size: 0.9375rem;
  user-select: none;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 42px;
  height: 25px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.15s;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::after {
  transform: translateX(17px);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.onscreen {
  background: var(--onscreen);
  color: var(--onscreen-ink);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn-ink);
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.conn::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c2410c;
}

.conn.on::before {
  background: #16a34a;
}

/* ---- questions --------------------------------------------------------- */

.qlist {
  display: flex;
  flex-direction: column;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.q {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.q.onscreen {
  background: var(--onscreen);
  border-color: var(--onscreen-border);
}

.q.fresh {
  animation: fresh 2.4s ease-out;
}

@keyframes fresh {
  0% {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

.q-body {
  flex: 1;
  min-width: 0;
}

.q-text {
  font-size: 1.02rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.q-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.q-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 52px;
  min-height: 56px;
  padding: 6px 4px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}

.vote svg {
  width: 20px;
  height: 20px;
}

.vote:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.vote[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.vote:active:not(:disabled) {
  transform: scale(0.95);
}

.vote:disabled {
  cursor: default;
}

.tally {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
  flex-shrink: 0;
  padding-top: 2px;
}

.tally strong {
  font-size: 1.5rem;
  line-height: 1.1;
}

.tally span {
  font-size: 0.75rem;
  color: var(--muted);
}

details.answered > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 650;
  margin: 28px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

details.answered > summary::-webkit-details-marker {
  display: none;
}

details.answered > summary::before {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

details.answered[open] > summary::before {
  transform: rotate(45deg);
}

details.answered .q {
  opacity: 0.75;
}

/* ---- student composer -------------------------------------------------- */

.composer textarea {
  border: 0;
  padding: 2px 0 0;
  box-shadow: none;
  min-height: 88px;
  font-size: 1.05rem;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 12px;
  flex-wrap: wrap;
}

.composer-foot .field {
  flex: 1 1 160px;
  min-width: 0;
  padding: 9px 12px;
  font-size: 0.95rem;
}

.chars {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chars.over {
  color: var(--danger);
  font-weight: 650;
}

.room-head {
  padding: 8px 0 18px;
}

.room-head h1 {
  font-size: clamp(1.45rem, 5vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.room-head p {
  margin-top: 4px;
}

/* ---- host -------------------------------------------------------------- */

.share {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
}

.share img {
  width: 104px;
  height: 104px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  display: block;
}

.share-link {
  font-weight: 650;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 28px 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs button {
  border: 0;
  background: transparent;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
}

.tabs button[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tabs .n {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.78rem;
  text-align: center;
}

.tabs .n.alert {
  background: var(--warn-soft);
  color: var(--warn-ink);
}

.rooms {
  display: grid;
  gap: 10px;
}

.room-card {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.room-card .grow {
  flex: 1 1 220px;
  min-width: 0;
}

.room-card h3 {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

/* ---- landing / auth ---------------------------------------------------- */

.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.center .card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
}

.hero-mark {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
}

.center h1 {
  font-size: 1.6rem;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.join-form {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.join-form .field {
  flex: 1;
  min-width: 0;
}

/* ---- presenter --------------------------------------------------------- */

.present {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(300px, 34vw) 1fr;
  background: var(--bg);
}

.present-join {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4vh 3vw;
  background: var(--surface);
  border-right: 1px solid var(--border);
  gap: 2.2vh;
}

.present-join .eyebrow {
  font-size: clamp(1rem, 1.6vw, 1.6rem);
}

.present-join h1 {
  font-size: clamp(2rem, 3.6vw, 4rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.present-qr {
  width: min(26vw, 52vh);
  aspect-ratio: 1;
  background: #fff;
  border-radius: 18px;
  padding: 1vw;
  box-shadow: var(--shadow);
}

.present-qr img {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.present-url {
  font-size: clamp(1rem, 1.6vw, 1.7rem);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.present-url b {
  color: var(--text);
}

.present-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6vh 5vw;
  min-width: 0;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  font-size: clamp(0.85rem, 1.2vw, 1.25rem);
  color: var(--accent);
}

.present-quote {
  margin: 2.5vh 0 0;
  font-size: clamp(1.8rem, 3.6vw, 4.4rem);
  line-height: 1.18;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.present-by {
  margin-top: 3vh;
  font-size: clamp(1rem, 1.6vw, 1.8rem);
  color: var(--muted);
}

.present-list {
  list-style: none;
  margin: 3vh 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.6vh;
}

.present-list li {
  display: flex;
  gap: 1.6vw;
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2vh 1.8vw;
  font-size: clamp(1.1rem, 1.9vw, 2.2rem);
  line-height: 1.25;
  font-weight: 550;
}

.present-list li span:last-child {
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.present-votes {
  flex-shrink: 0;
  min-width: 3.2ch;
  font-weight: 750;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.present-empty {
  font-size: clamp(1.6rem, 3vw, 3.4rem);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin-top: 2vh;
}

.present-empty + p {
  margin-top: 2vh;
  font-size: clamp(1rem, 1.6vw, 1.8rem);
  color: var(--muted);
}

.present.qr-only {
  grid-template-columns: 1fr;
}

.present.qr-only .present-main {
  display: none;
}

.present.qr-only .present-join {
  border-right: 0;
}

.present.qr-only .present-qr {
  width: min(62vh, 80vw);
}

.present-controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  transition: opacity 0.3s;
}

.present-controls.idle {
  opacity: 0;
  pointer-events: none;
}

.present-room {
  position: fixed;
  left: 16px;
  bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

  .present-join {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .present-qr {
    width: min(60vw, 40vh);
  }
}

/* ---- toast ------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 550;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
  z-index: 10;
  animation: toast-in 0.18s ease-out;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.noscript {
  padding: 24px 16px;
  text-align: center;
}

@media (max-width: 520px) {
  .share {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .topbar .hide-sm {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
