:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #171a2b;
  --muted: #5d6380;
  --border: #dfe3ee;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eceafe;
  --danger: #c62839;
  --ok: #138a52;
  --warn: #a15c00;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 8px 24px rgba(20, 24, 50, .06);
  --w0: #4f46e5; --w1: #d9480f; --w2: #0b7a75; --w3: #b5179e; --w4: #1d6fd8; --w5: #5c7c0a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1120; --surface: #181b2e; --surface-2: #20243b; --text: #eef0fa; --muted: #a2a8c6;
    --border: #2d3250; --accent: #8b85ff; --accent-ink: #0f1120; --accent-soft: #272a52;
    --danger: #ff6b7a; --ok: #4ade80; --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --w0: #a5a0ff; --w1: #ff9a62; --w2: #4fd1c5; --w3: #f472d0; --w4: #6fb2ff; --w5: #b5d65a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1120; --surface: #181b2e; --surface-2: #20243b; --text: #eef0fa; --muted: #a2a8c6;
  --border: #2d3250; --accent: #8b85ff; --accent-ink: #0f1120; --accent-soft: #272a52;
  --danger: #ff6b7a; --ok: #4ade80; --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --w0: #a5a0ff; --w1: #ff9a62; --w2: #4fd1c5; --w3: #f472d0; --w4: #6fb2ff; --w5: #b5d65a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1100px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; display: inline-grid; place-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 200px; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

h1 { font-size: clamp(26px, 5vw, 40px); line-height: 1.2; margin: 0 0 8px; letter-spacing: -.02em; }
.hero { text-align: center; padding: 28px 0 8px; }
.hero p { margin: 0 auto 24px; max-width: 520px; }

label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 11px 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 76px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.choice { position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer; background: var(--surface); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice b { display: block; font-size: 15px; }
.choice small { color: var(--muted); font-size: 13px; line-height: 1.35; display: block; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-soft); }

.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { padding: 14px 22px; font-size: 17px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.code-entry { display: flex; gap: 10px; max-width: 420px; margin: 0 auto; }
.code-entry input { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: .25em; }

.topic { font-size: clamp(22px, 4.5vw, 32px); font-weight: 700; line-height: 1.3; margin: 4px 0 16px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600; }
.pill.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.pill.off::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }

.answer-form { display: flex; gap: 10px; }
.answer-form input { font-size: 18px; padding: 13px 14px; }
.answer-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.msg { min-height: 24px; font-size: 14px; font-weight: 600; margin-top: 8px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---- the cloud ---- */
.cloud {
  --scale: 1;
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center; align-items: center;
  gap: .15em .55em; padding: 16px; min-height: 220px; text-align: center;
}
.cloud.fixed { height: 100%; min-height: 0; overflow: hidden; }
.cloud.empty::before { content: attr(data-empty); color: var(--muted); font-size: 16px; }
.word {
  font-size: calc(var(--fs, 20) * var(--scale) * 1px);
  font-weight: 700; line-height: 1.2; letter-spacing: -.01em;
  padding: .06em .12em; border: 0; background: none; border-radius: .2em;
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  transition: font-size .35s ease;
}
.cloud.measuring .word { transition: none; }
button.word { cursor: pointer; }
button.word:hover { background: var(--surface-2); }
.word.c0 { color: var(--w0); } .word.c1 { color: var(--w1); } .word.c2 { color: var(--w2); }
.word.c3 { color: var(--w3); } .word.c4 { color: var(--w4); } .word.c5 { color: var(--w5); }
.word.new { animation: pop .5s ease-out; }
.word.bump { animation: bump .45s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: none; } }
@keyframes bump { 40% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .word, .word.new, .word.bump { animation: none; transition: none; } }

.stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.stats b { color: var(--text); }

/* ---- present ---- */
body.present { overflow: hidden; }
.present-wrap { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; padding: 2.5vh 3vw; gap: 1.5vh; }
.present-topic { font-size: clamp(22px, 3.6vw, 54px); font-weight: 800; text-align: center; line-height: 1.2; letter-spacing: -.02em; overflow-wrap: anywhere; }
.present-stage { position: relative; min-height: 0; }
.present-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.join { display: flex; align-items: center; gap: 16px; }
.join .qr { width: clamp(80px, 11vh, 150px); height: clamp(80px, 11vh, 150px); background: #fff; border-radius: 10px; padding: 6px; }
.join .qr svg { width: 100%; height: 100%; display: block; }
.join-text { font-size: clamp(14px, 1.6vw, 24px); line-height: 1.35; }
.join-text b { font-size: 1.35em; color: var(--accent); letter-spacing: .04em; }
.present-tools { display: flex; gap: 8px; opacity: .35; transition: opacity .2s; }
.present-tools:hover, .present-tools:focus-within { opacity: 1; }
.big-qr { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); display: grid; place-items: center; z-index: 10; cursor: pointer; }
.big-qr > div { text-align: center; }
.big-qr .qr { width: min(70vh, 80vw); height: min(70vh, 80vw); background: #fff; padding: 16px; border-radius: 18px; margin: 0 auto 16px; }
.big-qr .qr svg { width: 100%; height: 100%; display: block; }
.big-qr p { font-size: clamp(18px, 3vw, 36px); margin: 0; font-weight: 700; }

/* ---- admin ---- */
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .admin-grid { grid-template-columns: 1fr; } }
.preview { height: 380px; border: 1px dashed var(--border); border-radius: 12px; background: var(--bg); }
.share-qr { width: 132px; height: 132px; background: #fff; border-radius: 10px; padding: 6px; flex: none; }
.share-qr svg { width: 100%; height: 100%; display: block; }
.linkbox { font-family: ui-monospace, Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; max-height: 460px; overflow: auto; }
.list li { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .t { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.list .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; min-width: 2.5em; text-align: right; }
.list li.hidden .t { text-decoration: line-through; color: var(--muted); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.tag.pending { color: var(--warn); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600; }
.tabs button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.mylist { list-style: none; padding: 0; margin: 0; }
.mylist li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.mylist li .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: .05em; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 520px) {
  .wrap { padding-top: 16px; }
  .card { padding: 16px; }
  .answer-form { flex-direction: column; }
  .present-foot { flex-direction: column; align-items: stretch; }
}
