:root {
  --blue: #2f6df6;
  --orange: #f5811f;
  --ink: #0b1020;
  --rounded: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;

  /* One spacing scale, so panels, fieldsets and grids line up with each other
     instead of each carrying its own hand-picked margin. */
  --gap-1: 6px;
  --gap-2: 10px;
  --gap-3: 16px;
  --gap-4: 24px;
  --gap-5: 34px;

  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;

  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.24);
  --text-dim: rgba(255, 255, 255, 0.55);
  --text-faint: rgba(255, 255, 255, 0.38);
  --surface: rgba(255, 255, 255, 0.045);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: var(--rounded);
  color: #fff;
  -webkit-font-smoothing: antialiased;
}

/* The camera feed is drawn onto the canvas, never shown directly. */
#camera { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 120% at 50% 0%, #1b2a55 0%, #0b1020 60%);
  z-index: 10;
  overflow-y: auto;
}

.overlay.hidden { display: none; }

.panel {
  width: min(940px, 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--gap-5) var(--gap-5) var(--gap-4);
  text-align: center;
  backdrop-filter: blur(14px) saturate(120%);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.panel.narrow { width: min(560px, 100%); }

h1 {
  font-size: clamp(38px, 6vw, 66px);
  margin: 0 0 8px;
  letter-spacing: -1px;
  background: linear-gradient(105deg, #7dd3fc 0%, #a78bfa 40%, #fb923c 75%, #fbbf24 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(120, 140, 255, 0.35));
}
h2 { font-size: clamp(24px, 3.5vw, 34px); margin: 0 0 10px; }

.wave { display: inline-block; animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(12deg); } }

.sub {
  color: rgba(255, 255, 255, 0.7);
  font-size: clamp(15px, 1.7vw, 18px);
  margin: 0 0 var(--gap-5);
  letter-spacing: 0.2px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--gap-3) var(--gap-3) var(--gap-3);
  margin: 0 0 var(--gap-3);
  text-align: left;
  background: rgba(255, 255, 255, 0.018);
}

legend {
  padding: 0 var(--gap-2);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--text-faint);
}

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--gap-3); }
.row fieldset { margin: 0; }

label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  font-size: 17px;
  cursor: pointer;
  border-radius: 10px;
}

label:hover { background: rgba(255, 255, 255, 0.06); }
label em { color: rgba(255, 255, 255, 0.5); font-style: normal; font-size: 14px; }

input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--blue); cursor: pointer; }

.packs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px;
}

.pack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 14px 10px 11px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.pack:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.09); }

/* The checkbox itself is redundant once the whole card shows the state. */
.pack input { position: absolute; opacity: 0; pointer-events: none; }

.pack:has(input:checked) {
  background: linear-gradient(160deg, rgba(47, 109, 246, 0.32), rgba(139, 92, 246, 0.26));
  border-color: rgba(160, 190, 255, 0.85);
  box-shadow: 0 8px 26px rgba(47, 109, 246, 0.25);
}

/* A tick in the corner, so "on" is unmistakable at a glance. */
.pack:has(input:checked)::after {
  content: "✓";
  position: absolute;
  top: 7px;
  right: 10px;
  font-size: 14px;
  font-weight: 900;
  color: #9ec5ff;
}

.pack-sample { font-size: 27px; line-height: 1.25; }
.pack-name { font-size: 14px; font-weight: 800; text-align: center; line-height: 1.3; }
.pack-count { font-size: 11px; color: rgba(255, 255, 255, 0.45); font-weight: 700; }

button {
  font-family: inherit;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

button:hover { transform: translateY(-2px); filter: brightness(1.08); }
button:active { transform: translateY(0); }

.big {
  background: linear-gradient(135deg, var(--blue), #6a5cff);
  color: #fff;
  font-size: 22px;
  padding: 16px 42px;
  margin-top: 8px;
  box-shadow: 0 10px 30px rgba(47, 109, 246, 0.4);
}

.ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 16px;
  padding: 13px 26px;
}

.buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }

.foot { color: var(--text-faint); font-size: 13px; line-height: 1.65; margin: var(--gap-4) 0 0; }

kbd {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 1px 7px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto 18px;
  border: 5px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#errorText { color: rgba(255, 255, 255, 0.78); line-height: 1.65; font-size: 17px; margin-bottom: 22px; }

.steps {
  text-align: left;
  margin: 0 auto 22px;
  max-width: 560px;
  line-height: 2;
  font-size: 17px;
  color: rgba(255, 255, 255, 0.88);
  padding-left: 26px;
}

.steps code {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  padding: 3px 9px;
  font-family: ui-monospace, monospace;
  font-size: 15px;
}

#graphicsReason {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  opacity: 0.5;
  word-break: break-word;
}

/* Emoji drifting up behind the start screen — motion makes it read as a game. */
.floaties {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.floaties span {
  position: absolute;
  bottom: -12%;
  font-size: 38px;
  opacity: 0.09;
  filter: blur(0.4px);
  animation: drift linear infinite;
}

.floaties span:nth-child(1)  { left:  4%; animation-duration: 21s; animation-delay:  0s; }
.floaties span:nth-child(2)  { left: 14%; animation-duration: 27s; animation-delay: -6s; font-size: 32px; }
.floaties span:nth-child(3)  { left: 24%; animation-duration: 18s; animation-delay: -3s; }
.floaties span:nth-child(4)  { left: 35%; animation-duration: 30s; animation-delay: -12s; font-size: 52px; }
.floaties span:nth-child(5)  { left: 46%; animation-duration: 23s; animation-delay: -17s; }
.floaties span:nth-child(6)  { left: 57%; animation-duration: 26s; animation-delay: -8s; font-size: 36px; }
.floaties span:nth-child(7)  { left: 68%; animation-duration: 19s; animation-delay: -14s; }
.floaties span:nth-child(8)  { left: 78%; animation-duration: 29s; animation-delay: -2s; font-size: 48px; }
.floaties span:nth-child(9)  { left: 88%; animation-duration: 24s; animation-delay: -20s; }
.floaties span:nth-child(10) { left: 95%; animation-duration: 22s; animation-delay: -10s; font-size: 34px; }

@keyframes drift {
  0%   { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-118vh) rotate(24deg); }
}

/* Respect a reduced-motion preference; the game still plays identically. */
@media (prefers-reduced-motion: reduce) {
  .floaties { display: none; }
  .wave { animation: none; }
}

.panel { position: relative; z-index: 1; }

.big {
  background: linear-gradient(135deg, #2f6df6, #8b5cf6 55%, #ec4899);
  font-size: 24px;
  padding: 18px 52px;
  letter-spacing: 0.3px;
  box-shadow: 0 12px 34px rgba(93, 92, 255, 0.45);
}

.big:hover { box-shadow: 0 16px 40px rgba(93, 92, 255, 0.55); }

/* The winner panel arrives with a bounce rather than simply appearing. */
#winner .panel {
  animation: trophy-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

#winner h1 { font-size: clamp(40px, 7vw, 72px); }
#winnerScore { font-size: clamp(20px, 3vw, 30px); letter-spacing: 2px; }

@keyframes trophy-in {
  from { transform: scale(0.72) translateY(24px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #winner .panel { animation: none; }
}

.grades { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.grade {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: inherit;
  text-align: center;
}

.grade.on {
  background: linear-gradient(160deg, rgba(236, 72, 153, 0.34), rgba(139, 92, 246, 0.3));
  border-color: rgba(244, 180, 255, 0.85);
  box-shadow: 0 8px 26px rgba(190, 90, 220, 0.28);
}

.grade-name { font-size: 19px; font-weight: 900; }
.grade-blurb { font-size: 12px; font-weight: 600; color: rgba(255, 255, 255, 0.6); line-height: 1.35; }

.subject + .subject { margin-top: 16px; }

.subject-title {
  margin: 0 0 9px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);
  text-align: left;
}

.subject-packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }

.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
}

.player-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.player.p1 .player-dot { background: var(--blue); box-shadow: 0 0 12px var(--blue); }
.player.p2 .player-dot { background: var(--orange); box-shadow: 0 0 12px var(--orange); }

.player input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 6px 0;
}

.player input::placeholder { color: rgba(255, 255, 255, 0.35); font-weight: 600; }

.rank-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }

.rank-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 var(--gap-2) var(--gap-2);
}

.rank-table th.num { text-align: right; }

.rank-table td {
  padding: var(--gap-2);
  font-size: 17px;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.rank-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rank-table td.num:first-of-type { color: #fff; }
.rank-table tr:nth-child(2) td { font-size: 20px; }
.rank-table tr:nth-child(n+3) td.num { color: var(--text-dim); }
.rank-place { width: 44px; font-size: 20px; }
.rank-empty { color: rgba(255, 255, 255, 0.55); padding: 26px 0 30px; font-size: 17px; }
