:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f7f7f7;
  background: #050507;
  font-synthesis: none;
  --muted: #9b9ba3;
  --line: #29292e;
  --panel: #111113;
  --rainbow: linear-gradient(100deg, #ff637d 0%, #ffad5c 19%, #ffe16b 36%, #76e3a5 54%, #69c8ff 72%, #b497ff 88%, #ff82d4 100%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  min-width: 320px;
  background: #050507;
  color: #f7f7f7;
}
body[data-page="draw"] { overflow: hidden; }
body[data-page="group"] { overflow-x: hidden; overflow-y: auto; }
body[data-page="draw"] > .draw-screen, body[data-page="group"] > .group-screen { position: relative; z-index: 1; }
.ambient-sky { position: fixed; z-index: 0; inset: 0; overflow: hidden; pointer-events: none; }
.draw-screen > .ambient-sky { z-index: 2; }
.ambient-star { position: absolute; width: var(--star-size, 2px); height: var(--star-size, 2px); border-radius: 50%; background: var(--star-color, #e6e9ff); opacity: var(--star-opacity, .55); box-shadow: 0 0 5px var(--star-color, #e6e9ff); }
.ambient-star.twinkle { animation: star-twinkle var(--twinkle-time, 5s) ease-in-out infinite alternate; }
@keyframes star-twinkle { from { opacity: .2; } to { opacity: .85; } }
.shooting-star { position: absolute; width: var(--star-length, 120px); height: var(--star-width, 2px); border-radius: 50%; opacity: 0; background: linear-gradient(90deg, transparent, var(--star-color) 45%, #fff 100%); box-shadow: 0 0 8px 1px var(--star-color); transform-origin: left center; animation: star-flight var(--flight-time, 2.5s) linear forwards; }
.shooting-star::after { position: absolute; top: 50%; right: 0; width: 4px; height: 4px; border-radius: 50%; background: #fff; box-shadow: 0 0 9px 3px var(--star-color); content: ""; transform: translate(50%, -50%); }
@keyframes star-flight {
  0% { opacity: 0; transform: translate(0, 0) rotate(var(--star-angle)) scaleX(.15); }
  12% { opacity: .8; transform: translate(0, 0) rotate(var(--star-angle)) scaleX(1); }
  78% { opacity: .65; transform: translate(var(--star-dx), var(--star-dy)) rotate(var(--star-angle)) scaleX(1); }
  100% { opacity: 0; transform: translate(var(--star-dx), var(--star-dy)) rotate(var(--star-angle)) scaleX(.15); }
}
button, input { font: inherit; }
button, a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid #aebcff; outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .44; }

.rainbow-text, .player-name {
  color: transparent;
  background: var(--rainbow);
  background-size: 250% 100%;
  background-position: 0% 50%;
  background-clip: text;
  -webkit-background-clip: text;
  animation: rainbow-flow 4s ease-in-out infinite alternate;
}
@keyframes rainbow-flow {
  from { background-position: 0% 50%; }
  to { background-position: 100% 50%; }
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { display: grid; width: 27px; height: 27px; flex: 0 0 auto; place-items: center; border-radius: 9px; background: var(--rainbow); color: #090909; font-size: 16px; font-weight: 900; }
.brand h1 { margin: 0; font-size: clamp(23px, 6vw, 30px); letter-spacing: -.055em; line-height: 1.1; }
.secondary-button, .reset-button, .add-button, .draw-button, .group-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition: transform .16s ease, opacity .16s ease, background .16s ease;
}
.secondary-button, .reset-button { min-height: 38px; padding: 7px 11px; background: #ffffff08; color: #dedee4; font-size: 12px; }
.secondary-button:hover:not(:disabled), .reset-button:hover:not(:disabled) { background: #202024; }

/* The draw page is a fixed, full-viewport layout; only the group editor scrolls. */
.draw-screen {
  position: relative;
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
}
.draw-topbar, .group-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.draw-topbar { position: relative; z-index: 4; width: 100vw; flex: 0 0 auto; margin-top: calc(-1 * max(12px, env(safe-area-inset-top))); padding: max(12px, env(safe-area-inset-top)) max(11px, calc((100vw - 760px) / 2)) 8px; background: #08090c; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.group-nav { height: 38px; min-height: 38px; flex: 0 0 auto; padding: 6px 10px; border-color: #ffffff20; background: #ffffff08; color: #efeff3; font-size: 14px; }
.group-nav:hover { background: #ffffff14; }
.nav-count { display: grid; min-width: 20px; height: 20px; place-items: center; padding: 0 5px; border-radius: 99px; background: #ffffff14; font-size: 10px; }
.draw-stage { position: absolute; z-index: 0; inset: 0; display: flex; width: 100%; min-height: 0; flex-direction: column; align-items: stretch; justify-content: stretch; }
.draw-panel { width: min(100%, 560px); padding: clamp(16px, 4vw, 27px); border: 1px solid var(--line); border-radius: 20px; background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: 0 20px 70px #0007; text-align: center; }
.panel-label { margin: 0 0 10px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.reel { position: relative; display: grid; width: 100%; height: 100%; min-height: 0; flex: 1 1 auto; place-items: center; overflow: hidden; isolation: isolate; }
.reel::before, .reel::after { position: absolute; z-index: 1; right: 0; left: 0; height: clamp(42px, 10svh, 100px); content: ""; pointer-events: none; }
.reel::before { top: 0; background: linear-gradient(#050507, transparent); }
.reel::after { bottom: 0; background: linear-gradient(transparent, #050507); }
.reel-track { position: absolute; z-index: 0; top: 0; left: 0; width: 100%; will-change: transform; }
.selection-window { position: absolute; z-index: 2; top: var(--selection-center, 50%); right: 8px; left: 8px; height: 82px; border: 1px solid #ffffff36; border-radius: 17px; background: #ffffff10; box-shadow: inset 0 0 25px #ffffff08, 0 0 30px #a88cff12; transform: translateY(-50%); pointer-events: none; }
.reel-row { display: flex; height: 82px; align-items: center; justify-content: center; gap: 10px; padding: 0 14px; font-size: clamp(28px, 8vw, 48px); font-weight: 850; letter-spacing: -.035em; }
.reel-row img { width: 54px; height: 54px; flex: 0 0 auto; object-fit: contain; }
.reel-row .rainbow-text { max-width: calc(100% - 68px); overflow: hidden; animation-delay: var(--reel-rainbow-delay, 0s); text-overflow: ellipsis; white-space: nowrap; }
.reel-row.winner-reveal { animation: picked-row-pop 1.6s cubic-bezier(.2,.8,.25,1); }
@keyframes picked-row-pop {
  0%, 100% { transform: scale(1); }
  12.5%, 75% { transform: scale(1.16); }
}
.reel-placeholder { position: absolute; z-index: 3; top: var(--selection-center, 50%); left: 0; width: 100%; padding: 0 8px; color: #777780; text-align: center; font-size: 14px; font-weight: 650; transform: translateY(-50%); }
.group-picker-link { display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: #ededf3; text-decoration: none; }
.group-picker-link:focus-visible { border-radius: 6px; outline: 2px solid #aebcff; outline-offset: 4px; }
.group-picker-arrow { font-size: 20px; line-height: 1; transition: transform .16s ease; }
@media (hover: hover) and (pointer: fine) {
  .group-picker-link:hover .group-picker-arrow { transform: translateX(3px); }
}
.result { min-height: 22px; margin: 9px 0 13px; color: var(--muted); font-size: 13px; }
.draw-button { width: min(100%, 360px); min-height: 52px; padding: 12px 20px; border: 0; color: #080808; background: var(--rainbow); background-size: 250% 100%; background-position: 0% 50%; animation: rainbow-flow 4s ease-in-out infinite alternate; font-size: 16px; box-shadow: 0 7px 28px #d98bff20; }
.draw-button:hover:not(:disabled), .add-button:hover:not(:disabled) { transform: translateY(-2px); }
.draw-reset-button { display: inline-flex; height: 38px; min-height: 38px; align-items: center; justify-content: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: #ffffff08; color: #c7c7ce; cursor: pointer; font-size: 14px; font-weight: 750; }
.draw-reset-button:hover:not(:disabled) { background: #202024; }
.button-icon { font-size: 20px; line-height: 1; }
.draw-bottom { position: relative; z-index: 4; display: flex; width: 100vw; flex: 0 0 auto; flex-direction: column; gap: 0; margin: auto 0 0; padding-bottom: max(9px, env(safe-area-inset-bottom)); background: #08090c; }
.draw-controls { position: relative; width: 100%; flex: 0 0 auto; padding: 0 max(11px, calc((100vw - 560px) / 2)); background: transparent; text-align: center; }
.load-error { margin-top: 10px; padding: 12px; border: 1px solid #6b4545; border-radius: 12px; color: #ffc0c0; background: #241313; font-size: 12px; line-height: 1.5; }
.history-panel { position: relative; width: 100%; flex: 0 0 auto; margin: 0; padding: 8px max(11px, calc((100vw - 760px) / 2)) 2px; border-top: 1px solid #ffffff18; background: transparent; }
.history-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.history-heading h2 { margin: 0; color: #e9e9ee; font-size: 12px; font-weight: 750; letter-spacing: .04em; }
.history-count { color: #85858d; font-size: 10px; }
.history-list { display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 4px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.history-list::-webkit-scrollbar { display: none; }
.history-empty { display: flex; min-height: 30px; flex: 1 0 100%; align-items: center; justify-content: center; padding: 3px 0; color: #777780; text-align: center; font-size: 11px; }
.history-chip { display: inline-flex; min-width: 0; align-items: center; gap: 4px; padding: 3px 6px; border: 1px solid #ffffff14; border-radius: 99px; background: #ffffff07; }
.history-chip { flex: 0 0 auto; }
.history-chip img { width: 24px; height: 24px; flex: 0 0 auto; object-fit: contain; }
.history-name { overflow: hidden; font-size: 14px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }

/* Group selector */
.group-screen { width: 100%; min-height: 100vh; min-height: 100dvh; overflow: visible; }
.group-app { width: min(100% - 32px, 760px); margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom)); }
.group-topbar { margin-bottom: 13px; }
.group-topbar .secondary-button, .group-topbar .reset-button { min-height: 39px; }
.group-title { margin: 0; text-align: center; font-size: clamp(17px, 4vw, 21px); font-weight: 800; letter-spacing: -.03em; }
.group-status { min-height: 20px; margin: 0 0 12px; color: var(--muted); text-align: center; font-size: 12px; }
.roster-panel { padding: clamp(8px, 2vw, 16px) 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.roster-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.roster-heading h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.roster-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.selected-heading-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; }
.selected-heading-actions .clear-selected-button { height: 32px; min-height: 32px; padding: 5px 9px; font-size: 11px; }
.start-drawing-button { width: 100%; min-height: 52px; margin: 0 0 14px; padding: 12px 20px; border-radius: 13px; font-size: 16px; }
.library-divider { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin: 17px 0 12px; padding-top: 15px; border-top: 1px solid #ffffff18; }
.library-divider h2 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.library-divider p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.list-count { flex: 0 0 auto; padding-bottom: 2px; color: #85858d; font-size: 11px; }
.count-badge { flex: 0 0 auto; padding: 6px 9px; border: 1px solid var(--line); border-radius: 99px; color: #dedee4; font-size: 12px; font-weight: 700; }
.tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-bottom: 11px; }
.search-wrap { position: relative; }
.search-icon { position: absolute; top: 50%; left: 12px; color: #85858d; transform: translateY(-50%); pointer-events: none; }
.search-input, .add-input { width: 100%; min-width: 0; height: 43px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: #09090b; color: #f7f7f7; }
.search-input { padding-left: 36px; }
.search-input::placeholder, .add-input::placeholder { color: #74747c; }
.selection-tools { display: flex; gap: 7px; }
.secondary-button { min-height: 43px; padding-inline: 12px; }
.add-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-bottom: 15px; }
.add-button { min-height: 43px; padding: 0 15px; border: 0; color: #080808; background: #f0f0f2; font-size: 13px; }
.add-button:disabled { background: #e2e2e5; }
.list-meta { display: flex; justify-content: space-between; gap: 10px; margin: 0 1px 9px; color: #81818a; font-size: 11px; }
.player-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 1px 3px 1px 1px; }
.player-card { position: relative; display: flex; min-width: 0; align-items: center; gap: 9px; padding: 9px 34px 9px 10px; border: 1px solid #29292e; border-radius: 13px; background: #0a0a0c80; color: inherit; cursor: pointer; font: inherit; text-align: left; backdrop-filter: blur(2px); transition: border-color .15s, background .15s, opacity .15s; }
.player-card.selected { border-color: #77717e; background: #17151a99; }
.player-card:disabled { opacity: 1; cursor: not-allowed; }
.player-card.drawn { opacity: .55; }
.avatar { width: 44px; height: 44px; flex: 0 0 auto; object-fit: contain; }
.player-copy { min-width: 0; flex: 1; }
.player-name { display: block; overflow: hidden; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.player-action { position: absolute; top: 5px; right: 5px; display: grid; width: 19px; height: 19px; place-items: center; padding: 0; border: 0; border-radius: 0; background: transparent; color: #eeeeF2; cursor: pointer; font-size: 14px; line-height: 1; }
.player-action:hover:not(:disabled) { background: #ffffff1a; }
@media (hover: hover) and (pointer: fine) {
  .player-card:hover { border-color: #575760; background: #10101399; }
}
.selected-empty { padding-block: 16px; border: 1px dashed #ffffff20; border-radius: 12px; }
.empty-list { grid-column: 1 / -1; padding: 25px 10px; color: var(--muted); text-align: center; font-size: 13px; }
.notice { margin: 13px 0 0; color: #888891; text-align: center; font-size: 11px; line-height: 1.5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 520px) {
  .draw-screen { gap: 5px; padding-right: 11px; padding-left: 11px; }
  .draw-topbar { gap: 5px; }
  .draw-topbar .brand { gap: 6px; }
  .draw-topbar .brand-mark { width: 23px; height: 23px; font-size: 14px; }
  .draw-topbar .brand h1 { font-size: clamp(20px, 5.5vw, 25px); }
  .top-actions { gap: 4px; }
  .draw-reset-button, .group-nav { height: 32px; min-height: 32px; gap: 3px; padding: 4px 5px; font-size: 12px; }
  .nav-count { min-width: 17px; height: 17px; padding-inline: 3px; }
  .draw-controls { width: 100%; }
  .result { margin: 4px 0 8px; }
  .draw-button { width: 100%; min-height: 50px; }
  .group-app { width: min(100% - 22px, 760px); }
  .group-topbar { gap: 6px; }
  .group-topbar .secondary-button, .group-topbar .reset-button { padding-inline: 9px; font-size: 11px; }
  .roster-panel { padding: 8px 0; }
  .roster-heading { flex-wrap: wrap; }
  .selected-heading-actions { margin-left: auto; }
  .player-list { gap: 6px; }
  .player-card { gap: 7px; padding: 8px 30px 8px 7px; }
  .avatar { width: 40px; height: 40px; }
  .selection-tools { gap: 5px; }
  .secondary-button { padding-inline: 9px; font-size: 11px; }
  .tools { gap: 6px; }
  .history-panel { padding-top: 6px; }
  .history-chip { gap: 3px; padding: 2px 5px; }
  .history-chip img { width: 22px; height: 22px; }
  .history-name { font-size: 14px; }
}
@media (max-width: 370px) {
  .selection-tools { grid-column: 1 / -1; }
  .selection-tools .secondary-button { flex: 1; }
}
@media (max-height: 700px) {
  .draw-screen { gap: 3px; padding-top: max(7px, env(safe-area-inset-top)); padding-bottom: 0; }
  .brand-mark { width: 23px; height: 23px; }
  .brand h1 { font-size: 22px; }
  .group-nav { min-height: 34px; }
  .result { min-height: 18px; margin: 5px 0 8px; font-size: 12px; }
  .draw-button { min-height: 45px; padding-block: 9px; }
  .history-panel { padding-top: 5px; }
  .history-heading { margin-bottom: 3px; }
  .history-list { gap: 3px; }
  .history-chip { padding: 1px 4px; }
  .history-chip img { width: 13px; height: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation: none !important; }
}
