@font-face { font-family: Figtree; src: url(/fonts/figtree-latin-400-normal.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: Figtree; src: url(/fonts/figtree-latin-600-normal.woff2) format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: Figtree; src: url(/fonts/figtree-latin-800-normal.woff2) format('woff2'); font-weight: 800; font-display: swap; }

:root {
  --paper: #f7f5f0;
  --card: #ffffff;
  --ink: #161616;
  --muted: #5d5a54;
  --line: #d9d6cf;
  --accent: #ed9d22;
  --accent-soft: #fbe7c6;
  --radius: 2px;
  /* Touch targets scale with the screen but never drop below 64px (shared classroom screens). */
  --tap: clamp(64px, 9vh, 120px);
  --q-size: clamp(1.75rem, 1rem + 3.2vw, 4.5rem);
  --opt-size: clamp(1.25rem, 0.8rem + 1.6vw, 2.6rem);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Figtree, system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
[hidden] { display: none !important; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Top bar — kept minimal */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px clamp(12px, 2vw, 28px); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 12px 8px; font-size: 0.95rem; }
.icon-btn { background: none; border: 0; padding: 10px; color: var(--muted); min-width: 48px; min-height: 48px; border-radius: var(--radius); }
.icon-btn:hover { background: #eceae4; }

.screen { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: clamp(12px, 2vw, 32px); display: flex; flex-direction: column; }

/* Buttons */
.btn { border: 2px solid var(--ink); border-radius: var(--radius); padding: 12px 20px; font-weight: 600; min-height: 48px; background: var(--card); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #333; }
.btn.secondary:hover, .btn.ghost:hover { background: #eceae4; }
.btn.ghost { border-color: var(--line); background: transparent; }
.btn.big { min-height: var(--tap); font-size: clamp(1.2rem, 0.9rem + 1vw, 2rem); padding: 0 40px; }

/* Setup */
#setup h1 { font-size: clamp(1.6rem, 1rem + 2vw, 2.6rem); margin: 8px 0 20px; }
.mode-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 24px; }
.mode-card { text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 22px; min-height: var(--tap); background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); }
.mode-card strong { font-size: 1.4rem; }
.mode-card span { color: var(--muted); }
.mode-card[aria-checked="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
select, input { min-height: 56px; padding: 0 12px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); font-size: 1.1rem; }
.classcode { border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 18px 8px; margin: 0 0 20px; background: var(--card); }
.classcode legend { font-weight: 600; padding: 0 6px; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 0.95rem; }
.code-row { display: flex; gap: 12px; flex-wrap: wrap; }
.code-row input { width: 10ch; text-transform: uppercase; letter-spacing: 0.2em; font-weight: 800; font-size: 1.4rem; text-align: center; }
.code-msg { min-height: 1.4em; margin: 8px 0; font-weight: 600; }
.toggle { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; min-height: 48px; cursor: pointer; }
.toggle input { width: 28px; height: 28px; min-height: 0; accent-color: var(--ink); }
#setupForm .btn.big { align-self: flex-start; }

/* Voting */
#vote { gap: clamp(12px, 2vh, 28px); }
.question-wrap { display: flex; flex-direction: column; gap: clamp(12px, 2.5vh, 32px); }
.q-meta { margin: 0; color: var(--muted); font-weight: 600; font-size: clamp(0.95rem, 0.8rem + 0.4vw, 1.3rem); }
.question { font-size: var(--q-size); line-height: 1.1; margin: 0; letter-spacing: -0.02em; font-weight: 800; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 1.5vw, 24px); }
.options.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .options, .options.three { grid-template-columns: 1fr; } }
.opt {
  display: flex; align-items: center; gap: clamp(12px, 1.4vw, 24px);
  min-height: calc(var(--tap) * 1.3); padding: 12px clamp(14px, 1.6vw, 28px);
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius);
  font-size: var(--opt-size); font-weight: 600; text-align: left;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.2s ease;
}
.opt:hover:not(:disabled) { background: var(--accent-soft); }
.opt:active:not(:disabled) { transform: scale(0.98); }
.badge { flex: none; display: grid; place-items: center; width: 1.8em; height: 1.8em; background: var(--ink); color: #fff; font-weight: 800; border-radius: var(--radius); font-size: 0.85em; }
.opt:disabled { cursor: default; }
.opt.chosen { background: var(--accent); border-color: var(--ink); }
.opt.faded { opacity: 0.35; }

.after { display: flex; gap: 16px; flex-wrap: wrap; }

/* Magpie + speech bubble */
.magpie-row { display: flex; align-items: flex-end; gap: 8px; margin-top: auto; padding-top: 8px; }
.magpie { width: clamp(80px, 11vw, 170px); height: auto; flex: none; transform-origin: bottom center; }
.magpie.hop { animation: hop 0.45s ease; }
@keyframes hop { 0%,100% { transform: translateY(0) } 40% { transform: translateY(-14px) rotate(-4deg) } }
.bubble {
  position: relative; background: var(--card); border: 3px solid var(--ink); border-radius: 18px;
  padding: clamp(10px, 1.2vw, 20px) clamp(14px, 1.6vw, 26px);
  font-size: clamp(1.05rem, 0.8rem + 0.9vw, 2rem); font-weight: 600; max-width: 900px; margin-bottom: clamp(30px, 5vw, 80px);
}
.bubble::before { content: ''; position: absolute; left: -16px; bottom: 14px; border: 14px solid transparent; border-right-color: var(--ink); border-left: 0; }
.bubble::after { content: ''; position: absolute; left: -10px; bottom: 17px; border: 11px solid transparent; border-right-color: var(--card); border-left: 0; }
.bubble:empty { display: none; }
.bubble p { margin: 0; }
.bubble p + p { margin-top: 6px; color: var(--muted); }

/* Results */
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: clamp(10px, 1vw, 16px); }
.r-card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.r-card h2 { margin: 0 0 2px; font-size: clamp(1.05rem, 0.9rem + 0.5vw, 1.5rem); }
.r-total { color: var(--muted); margin: 0 0 12px; font-size: 0.95rem; }
.r-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; margin-bottom: 10px; font-size: clamp(0.95rem, 0.85rem + 0.3vw, 1.25rem); }
.r-row .r-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.r-row .badge { width: 1.6em; height: 1.6em; font-size: 0.8em; }
.r-row .r-pct { font-weight: 800; }
.r-bar { grid-column: 1 / -1; height: 14px; background: #eceae4; border-radius: var(--radius); overflow: hidden; }
.r-bar span { display: block; height: 100%; background: var(--ink); width: 0; transition: width 0.7s ease; }
.r-row.mine .r-bar span { background: var(--accent); }
.r-empty { color: var(--muted); margin: 0; }

/* Teacher bar (shared screen) */
.teacher-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; border-top: 2px solid var(--line); padding-top: 12px; }
.tb-label { font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; }
.tb-code { font-weight: 800; letter-spacing: 0.15em; margin-right: auto; }

/* Done */
#done { align-items: center; justify-content: center; text-align: center; }
.big-magpie { width: 200px; }

/* About dialog */
dialog { border: 3px solid var(--ink); border-radius: var(--radius); max-width: 620px; padding: 24px 28px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog li { margin-bottom: 6px; }

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