:root {
  --ink: #1E1E1E;
  --ink-2: #4A4A48;
  --paper: #FBFAF6;
  --rule: #E4E1D8;
  --red: #C62828;
  --hl: #FFE45C;
  --card: #FFFFFF;
  --soft: #F3F0E7;
  --green: #2F7D4F;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
}
.paper {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(90deg, transparent 47px, rgba(198,40,40,.35) 47px, rgba(198,40,40,.35) 49px, transparent 49px),
    repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  font-family: var(--sans); font-weight: 800; font-size: .85em;
  background: var(--card); border: 1.5px solid var(--ink); border-bottom-width: 3px;
  border-radius: 6px; padding: 0 .4em;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 12px 18px 4px 64px;
}
.home {
  justify-self: start; display: inline-flex; align-items: center; gap: 8px;
  color: var(--ink); text-decoration: none; font-weight: 800;
  background: var(--card); border: 2px solid var(--ink); border-radius: 999px;
  padding: 3px 14px 3px 3px; box-shadow: 3px 3px 0 var(--ink);
}
.home img { border-radius: 50%; border: 1.5px solid var(--ink); }
.home:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.title {
  margin: 0; font-family: var(--serif); font-weight: 800; letter-spacing: -.01em;
  font-size: clamp(26px, 4.2vw, 52px); line-height: 1.05; text-align: center;
  padding: 0 .25em; outline: none; border-radius: 6px;
  background: linear-gradient(180deg, transparent 58%, var(--hl) 58%, var(--hl) 92%, transparent 92%);
}
.title:focus { box-shadow: 0 0 0 2px var(--ink); }
.bar-btns { justify-self: end; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip-btn {
  background: var(--card); border: 2px solid var(--ink); border-radius: 999px;
  padding: 6px 14px; font-weight: 800; font-size: 14px; box-shadow: 2px 2px 0 var(--ink);
}
.chip-btn.icon { padding: 6px 10px; display: inline-flex; align-items: center; }
.chip-btn:hover { background: var(--hl); }
.chip-btn:active { transform: translate(2px,2px); box-shadow: none; }
#soundBtn .mute { display: none; }
#soundBtn[aria-pressed="false"] .mute { display: inline; }
#soundBtn[aria-pressed="false"] .waves { display: none; }

/* ---------- layout ---------- */
.main {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px;
  padding: 6px 22px 22px 64px; min-height: calc(100vh - 80px);
}
.main.desk-off { grid-template-columns: minmax(0, 1fr); }
.main.desk-off .desk { display: none; }
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; }
.wheel-wrap {
  position: relative; aspect-ratio: 1 / 1;
  width: min(100%, calc(100vh - 150px)); max-width: 900px; min-width: 240px;
}
.main.desk-off .wheel-wrap { width: min(100%, calc(100vh - 140px)); }
.wheel-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.nib {
  position: absolute; right: -4%; top: 50%; width: 10%; transform: translateY(-50%);
  transform-origin: 85% 50%; filter: drop-shadow(3px 3px 0 rgba(0,0,0,.18)); z-index: 2;
}
.nib svg { display: block; width: 100%; height: auto; }
.nib.flick { animation: flick .14s ease-out; }
@keyframes flick { 0% { transform: translateY(-50%) rotate(0); } 40% { transform: translateY(-50%) rotate(-14deg); } 100% { transform: translateY(-50%) rotate(0); } }
.hub {
  position: absolute; left: 50%; top: 50%; width: 21%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: 4px solid var(--ink); background: var(--hl);
  font-family: var(--serif); font-weight: 800; font-size: clamp(16px, 3.2vw, 40px); letter-spacing: .01em;
  box-shadow: 0 5px 0 var(--ink), 0 10px 22px rgba(0,0,0,.18); z-index: 3;
  transition: transform .12s ease, box-shadow .12s ease;
}
.hub:hover { transform: translate(-50%, -52%); box-shadow: 0 7px 0 var(--ink), 0 14px 26px rgba(0,0,0,.2); }
.hub:active { transform: translate(-50%, -46%); box-shadow: 0 1px 0 var(--ink); }
.hub:disabled { cursor: default; filter: saturate(.6); transform: translate(-50%, -50%); }
.cue { margin: 12px 0 0; font-weight: 700; color: var(--ink-2); }
.cue b { color: var(--red); }

/* ---------- teacher's desk ---------- */
.desk {
  align-self: start; position: sticky; top: 12px;
  background: var(--card); border: 2px solid var(--ink); border-radius: 14px;
  box-shadow: 6px 6px 0 var(--ink); padding: 14px 16px 16px;
  max-height: calc(100vh - 100px); overflow: auto;
}
.desk-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.tape {
  display: inline-block; background: var(--hl); border: 1.5px solid var(--ink); transform: rotate(-2deg);
  padding: 2px 10px; font-weight: 900; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.warn { font-size: 12px; font-weight: 700; color: var(--red); text-align: right; }
.step { border-top: 1.5px dashed var(--rule); padding: 12px 0 6px; }
.step:first-of-type { border-top: 0; }
.step h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-family: var(--serif); font-size: 20px; font-weight: 800; }
.step h2 b {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); color: #fff; font-family: var(--sans); font-size: 14px;
}
.count { font-family: var(--sans); font-size: 14px; color: var(--ink-2); font-weight: 700; }
.tools-row { display: flex; gap: 6px; margin-bottom: 8px; }
.mini {
  background: var(--soft); border: 1.5px solid var(--ink); border-radius: 8px;
  padding: 4px 10px; font-weight: 800; font-size: 13px;
}
.mini:hover:not(:disabled) { background: var(--hl); }
.mini:disabled { opacity: .45; cursor: default; }
textarea {
  width: 100%; resize: vertical; min-height: 140px; border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 8px 10px; line-height: 1.5; font-weight: 600; background: #fff;
  background-image: repeating-linear-gradient(180deg, transparent 0 23px, #F0EDE4 23px 24px);
  background-attachment: local; background-position: 0 8px;
}
textarea:focus, select:focus { outline: 3px solid var(--hl); outline-offset: 1px; }
.lists { display: flex; gap: 6px; margin-top: 8px; }
.lists[hidden] { display: none; }
.lists input { flex: 1; min-width: 0; border: 1.5px solid var(--ink); border-radius: 8px; padding: 4px 8px; font-weight: 600; font-size: 14px; }
.lists input:focus { outline: 3px solid var(--hl); outline-offset: 1px; }
.lists select { flex: 1; min-width: 0; border: 1.5px solid var(--ink); border-radius: 8px; padding: 4px 6px; background: #fff; font-weight: 600; font-size: 14px; }
.hint { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-2); line-height: 1.4; }
.link { margin-left: auto; background: none; border: 0; color: var(--red); font-weight: 800; font-size: 13px; font-family: var(--sans); text-decoration: underline; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .empty { font-size: 13px; color: var(--ink-2); }
.pick {
  position: relative; border: 1.5px solid var(--ink); background: #fff; border-radius: 999px;
  padding: 4px 12px; font-weight: 700; font-size: 14px;
}
.pick:hover { background: var(--soft); }
.pick.on { background: var(--ink); color: #fff; padding-left: 6px; }
.pick .n {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px;
  background: var(--hl); color: var(--ink); font-size: 12px; font-weight: 900; margin-right: 6px; padding: 0 5px;
}
.next {
  margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--soft);
  border: 1.5px dashed var(--ink-2); font-weight: 700; font-size: 14px;
}
.next strong { font-family: var(--serif); font-size: 17px; margin-left: 4px; }
.next.set { background: #FFF6C2; border-style: solid; border-color: var(--ink); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; font-size: 14px; line-height: 1.35; margin-bottom: 10px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 1px 0 0; flex: none; }
.len { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; font-weight: 700; }
.len span { margin-right: 4px; }
.len label { position: relative; }
.len input { position: absolute; opacity: 0; pointer-events: none; }
.len label { border: 1.5px solid var(--ink); border-radius: 999px; padding: 3px 11px; background: #fff; cursor: pointer; font-weight: 700; }
.len label:has(input:checked) { background: var(--ink); color: #fff; }
.len label:has(input:focus-visible) { outline: 3px solid var(--hl); }
.tips summary { cursor: pointer; font-family: var(--serif); font-weight: 800; font-size: 17px; }
.tips ul { margin: 8px 0 0; padding-left: 18px; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.tips li { margin-bottom: 6px; }
.log { margin: 0; padding-left: 22px; font-size: 14px; max-height: 150px; overflow: auto; }
.log li { padding: 2px 0; font-weight: 700; }
.log li small { color: var(--ink-2); font-weight: 600; margin-left: 6px; }
.log li .chosen { color: var(--red); font-size: 12px; font-weight: 800; margin-left: 6px; }
.log:empty::before { content: "No spins yet."; display: block; margin-left: -22px; color: var(--ink-2); font-size: 13px; }
.desk-foot { display: grid; gap: 8px; margin-top: 10px; }
.btn {
  border: 2px solid var(--ink); background: var(--ink); color: #fff; border-radius: 12px;
  padding: 10px 14px; font-weight: 800; font-size: 15px; box-shadow: 3px 3px 0 rgba(0,0,0,.25);
}
.btn:hover { background: #333; }
.btn:active { transform: translate(2px,2px); box-shadow: none; }
.btn.big { padding: 13px 14px; font-size: 16px; background: var(--red); border-color: var(--ink); }
.btn.big:hover { background: #A61F1F; }
.btn.ghost { background: #fff; color: var(--ink); }
.btn.ghost:hover { background: var(--hl); }

/* ---------- teacher remote window ---------- */
.remote-only { display: none; }
body.remote .remote-only { display: block; }
body.remote .not-remote { display: none; }
body.remote .stage, body.remote #deskBtn, body.remote #fullBtn, body.remote .cue { display: none; }
body.remote .main { grid-template-columns: minmax(0, 560px); justify-content: center; padding: 6px 14px 20px; }
body.remote .desk { position: static; max-height: none; }
body.remote .title { font-size: 26px; }
body.remote .bar { padding-left: 14px; }
.remote-head { margin: 6px 0 8px; }
.remote-head .btn { width: 100%; }
.remote-last { margin: 8px 0 0; font-weight: 700; }
.remote-last strong { font-family: var(--serif); font-size: 20px; }

/* ---------- winner ---------- */
.win {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(30,30,30,.45); backdrop-filter: blur(2px); padding: 20px;
}
.win[hidden] { display: none; }
.win-card {
  position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 10px 10px 0 var(--ink); padding: 26px 30px 24px; text-align: center;
  min-width: min(520px, 92vw); max-width: 92vw; animation: pop .42s cubic-bezier(.2,1.4,.4,1);
  background-image: linear-gradient(90deg, transparent 30px, rgba(198,40,40,.3) 30px, rgba(198,40,40,.3) 32px, transparent 32px);
}
@keyframes pop { from { transform: scale(.6) rotate(-4deg); opacity: 0; } to { transform: none; opacity: 1; } }
.win-kicker { margin: 0; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: .08em; font-size: 14px; }
.win-name {
  margin: 8px 0 20px; font-family: var(--serif); font-weight: 800; line-height: 1.05;
  font-size: clamp(44px, 9vw, 110px); word-break: break-word;
}
.win-name span { background: linear-gradient(180deg, transparent 55%, var(--hl) 55%, var(--hl) 92%, transparent 92%); padding: 0 .12em; }
.win-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.win-btns .btn { min-width: 110px; }
.party { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 30; }

/* ---------- small screens ---------- */
@media (max-width: 920px) {
  .main { grid-template-columns: minmax(0, 1fr); padding: 6px 12px 22px 12px; }
  .desk { position: static; max-height: none; }
  .wheel-wrap { width: min(88vw, 66vh); }
  .main.desk-off .wheel-wrap { width: min(88vw, 76vh); }
  .bar { grid-template-columns: 1fr auto; padding: 10px 12px 4px; }
  .bar .title { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
  .paper { background: repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px); }
}
@media (max-width: 480px) {
  .home span { display: none; }
  .home { padding-right: 3px; }
  .chip-btn { padding: 5px 10px; font-size: 13px; }
  .win-card { padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .win-card, .nib.flick { animation: none; }
}
