:root {
  color-scheme: light;
  --ink: #14213d;
  --muted: #697386;
  --navy: #183153;
  --blue: #2f6bff;
  --coral: #ff684d;
  --paper: #fffdf8;
  --line: #dfe5ee;
  --shadow: 0 20px 60px rgba(39, 61, 94, .15);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(255,255,255,.72) 0 8%, transparent 28%),
    linear-gradient(135deg, #ffd36d 0%, #ffae78 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: clamp(16px, 2.6vw, 34px);
  gap: clamp(14px, 2vw, 24px);
}

.topbar {
  width: min(1440px, 100%);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--navy);
  font-weight: 900;
  letter-spacing: -.04em;
  box-shadow: 0 8px 20px rgba(24,49,83,.22);
}
.brand h1 { font-size: clamp(1.28rem, 2vw, 1.65rem); margin: 0; letter-spacing: -.035em; }
.brand p { margin: 1px 0 0; color: rgba(20,33,61,.68); font-size: .9rem; font-weight: 650; }

.header-actions { display: flex; gap: 10px; }
.manage-button, .icon-button {
  min-height: 44px;
  border: 1px solid rgba(20,33,61,.13);
  background: rgba(255,255,255,.84);
  color: var(--ink);
  border-radius: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 750;
  box-shadow: 0 6px 18px rgba(47,59,89,.1);
}
.icon-button { width: 44px; padding: 0; }
.manage-button svg, .icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.manage-button:hover, .icon-button:hover { background: #fff; transform: translateY(-1px); }

.workspace {
  width: min(1440px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 370px);
  gap: clamp(16px, 2vw, 26px);
}

.wheel-panel, .roster-panel {
  border: 1px solid rgba(255,255,255,.7);
  background: rgba(255,255,255,.42);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.wheel-panel {
  position: relative;
  min-width: 0;
  border-radius: 28px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 18px clamp(16px, 3vw, 34px) 22px;
  overflow: hidden;
}

.class-switcher { display: flex; align-items: center; gap: 10px; z-index: 2; }
.class-switcher label { font-size: .84rem; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.class-switcher select {
  min-width: 180px;
  min-height: 40px;
  padding: 0 34px 0 12px;
  color: var(--ink);
  border: 1px solid rgba(20,33,61,.15);
  border-radius: 11px;
  background: rgba(255,255,255,.78);
  font-weight: 750;
}

.wheel-stage { min-height: 0; position: relative; display: grid; place-items: center; padding: 18px 0 10px; }
.wheel-wrap {
  position: relative;
  width: min(66vh, 66vw, 720px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: white;
  border: clamp(8px, 1vw, 14px) solid rgba(255,255,255,.96);
  box-shadow: 0 20px 35px rgba(72,55,48,.23), 0 3px 0 rgba(255,255,255,.75) inset;
  transition: transform 4.8s cubic-bezier(.12,.72,.12,1);
  will-change: transform;
}
.wheel-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(20,33,61,.08);
  pointer-events: none;
}
#wheelCanvas { width: 100%; height: 100%; display: block; border-radius: 50%; }
.wheel-hub {
  position: absolute;
  width: 8%;
  aspect-ratio: 1;
  border-radius: 50%;
  left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: #fff;
  border: 5px solid var(--navy);
  box-shadow: 0 3px 12px rgba(20,33,61,.25);
}
.pointer {
  position: absolute;
  z-index: 5;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: clamp(18px, 2.2vw, 27px) solid transparent;
  border-right: clamp(18px, 2.2vw, 27px) solid transparent;
  border-top: clamp(31px, 3.5vw, 47px) solid var(--navy);
  filter: drop-shadow(0 5px 4px rgba(20,33,61,.22));
}

.spin-controls { display: flex; justify-content: center; align-items: center; gap: 20px; padding-top: 4px; }
.spin-button {
  min-width: 142px;
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  background: var(--coral);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 900;
  box-shadow: 0 11px 0 #d94735, 0 17px 28px rgba(153,53,36,.25);
  transform: translateY(-5px);
}
.spin-button:hover:not(:disabled) { background: #ff755e; }
.spin-button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #d94735, 0 8px 18px rgba(153,53,36,.22); }
.spin-button:disabled { opacity: .48; cursor: not-allowed; box-shadow: none; transform: none; }

.remove-toggle { display: flex; align-items: center; gap: 9px; font-size: .94rem; font-weight: 700; cursor: pointer; }
.remove-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 42px; height: 24px; border-radius: 999px; background: rgba(20,33,61,.25); padding: 3px; transition: background .2s; }
.toggle-track span { display: block; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: transform .2s; }
.remove-toggle input:checked + .toggle-track { background: var(--blue); }
.remove-toggle input:checked + .toggle-track span { transform: translateX(18px); }
.remove-toggle input:focus-visible + .toggle-track { outline: 3px solid rgba(47,107,255,.35); outline-offset: 2px; }

.roster-panel {
  min-height: 0;
  border-radius: 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
.roster-heading { display: flex; justify-content: space-between; align-items: center; padding: 22px 20px 16px; border-bottom: 1px solid rgba(20,33,61,.1); }
.roster-heading h2 { margin: 0; font-size: 1.1rem; letter-spacing: -.02em; }
.roster-heading p { margin: 3px 0 0; color: var(--muted); font-size: .86rem; font-weight: 650; }
.roster-actions { display: flex; gap: 5px; }
.roster-actions button { border: 0; color: var(--blue); background: rgba(255,255,255,.55); border-radius: 8px; padding: 7px 9px; font-size: .8rem; font-weight: 800; }
.roster-list { min-height: 0; padding: 8px 12px 14px; overflow: auto; scrollbar-color: rgba(20,33,61,.28) transparent; }
.student-row { display: flex; align-items: center; gap: 11px; min-height: 43px; padding: 5px 9px; border-radius: 10px; font-size: .95rem; font-weight: 640; cursor: pointer; }
.student-row:hover { background: rgba(255,255,255,.58); }
.student-row input { width: 19px; height: 19px; margin: 0; accent-color: var(--blue); }
.student-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-roster { align-self: start; margin: 22px; color: var(--muted); line-height: 1.55; }

dialog { border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(13,24,43,.58); backdrop-filter: blur(6px); }
.winner-dialog { overflow: visible; }
.winner-card {
  min-width: min(460px, calc(100vw - 36px));
  padding: 38px 36px 30px;
  border-radius: 28px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 35px 100px rgba(5,17,38,.36);
  display: grid;
  justify-items: center;
  text-align: center;
  animation: winnerIn .32s cubic-bezier(.2,.9,.25,1.2);
}
.winner-kicker, .eyebrow { color: var(--coral); font-size: .76rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.winner-card strong { margin: 10px 0 26px; font-size: clamp(2rem, 6vw, 3.5rem); line-height: 1; letter-spacing: -.05em; }
.winner-card button, .save-button { border: 0; border-radius: 12px; background: var(--navy); color: #fff; min-height: 45px; padding: 0 22px; font-weight: 850; }
@keyframes winnerIn { from { opacity: 0; transform: scale(.86) translateY(18px); } }

.manage-dialog { width: min(820px, calc(100vw - 28px)); color: var(--ink); }
.dialog-shell { background: var(--paper); border-radius: 24px; overflow: hidden; box-shadow: 0 35px 100px rgba(5,17,38,.36); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 24px 26px 19px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 2px 0 0; font-size: 1.5rem; letter-spacing: -.035em; }
.dialog-close { width: 40px; height: 40px; border: 0; border-radius: 12px; background: #eef1f6; color: var(--ink); font-size: 1.65rem; line-height: 1; }
.manage-grid { min-height: 470px; max-height: min(70vh, 640px); display: grid; grid-template-columns: 235px 1fr; }
.class-list-column { display: flex; min-height: 0; flex-direction: column; border-right: 1px solid var(--line); padding: 14px; background: #f5f7fa; }
.class-list { display: grid; gap: 5px; overflow: auto; }
.class-list-item { width: 100%; border: 0; background: transparent; color: var(--ink); border-radius: 10px; padding: 11px 12px; display: flex; justify-content: space-between; gap: 8px; text-align: left; font-weight: 750; }
.class-list-item span:last-child { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.class-list-item.active { color: #fff; background: var(--navy); }
.class-list-item.active span:last-child { color: rgba(255,255,255,.7); }
.new-class { margin-top: auto; border: 1px dashed #aeb8c8; border-radius: 10px; background: #fff; min-height: 43px; color: var(--blue); font-weight: 850; }
.class-editor { min-width: 0; padding: 24px; display: grid; grid-template-rows: auto auto auto minmax(180px, 1fr) auto; }
.field-label { font-size: .82rem; font-weight: 850; letter-spacing: .035em; }
.text-input, .names-input { width: 100%; border: 1px solid #cdd5e0; border-radius: 11px; color: var(--ink); background: #fff; outline: none; }
.text-input { margin: 7px 0 20px; padding: 0 12px; min-height: 44px; font-weight: 700; }
.names-input { min-height: 190px; padding: 12px 14px; resize: none; line-height: 1.55; }
.text-input:focus, .names-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,107,255,.14); }
.editor-label-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.editor-label-row span { color: var(--muted); font-size: .78rem; }
.editor-footer { display: flex; justify-content: space-between; gap: 12px; padding-top: 20px; }
.delete-button { border: 0; background: transparent; color: #c23b32; font-weight: 800; }
.save-button { background: var(--blue); }
.toast { position: fixed; z-index: 20; bottom: 24px; left: 50%; transform: translate(-50%,20px); opacity: 0; pointer-events: none; color: #fff; background: var(--navy); border-radius: 10px; padding: 10px 15px; font-size: .88rem; font-weight: 750; transition: .22s ease; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

button:focus-visible, select:focus-visible { outline: 3px solid rgba(47,107,255,.5); outline-offset: 2px; }

@media (max-width: 900px) {
  .app-shell { height: auto; }
  .workspace { grid-template-columns: 1fr; }
  .wheel-panel { min-height: 680px; }
  .wheel-wrap { width: min(70vh, 88vw, 620px); }
  .roster-panel { max-height: 520px; }
}

@media (max-width: 560px) {
  .app-shell { padding: 12px; }
  .brand p { display: none; }
  .manage-button { font-size: 0; width: 44px; padding: 0; }
  .manage-button svg { width: 21px; height: 21px; }
  .wheel-panel { min-height: 555px; border-radius: 21px; padding: 14px 10px 18px; }
  .class-switcher { padding-left: 4px; }
  .class-switcher select { min-width: 0; max-width: 210px; }
  .wheel-wrap { width: min(86vw, 480px); }
  .pointer { top: 3px; }
  .spin-controls { flex-direction: column; gap: 16px; }
  .spin-button { min-width: 160px; }
  .manage-grid { min-height: 0; max-height: 78vh; grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .class-list-column { border-right: 0; border-bottom: 1px solid var(--line); max-height: 155px; }
  .class-list { grid-auto-flow: column; grid-auto-columns: minmax(145px, 1fr); overflow-x: auto; }
  .new-class { margin-top: 10px; min-height: 38px; }
  .class-editor { padding: 18px; min-height: 410px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
