:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #eef3f8;
  --text: #172033;
  --muted: #637083;
  --line: #d9e1eb;
  --primary: #6d45e7;
  --primary-dark: #5633c4;
  --danger: #c9364f;
  --focus: #0b74de;
  --shadow: 0 18px 50px rgba(40, 54, 85, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top, #fff 0, var(--bg) 42rem); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, select, input[type="range"], input[type="file"], input[type="checkbox"], summary { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 9999; background: #111827; color: white; padding: .75rem 1rem; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.site-header, .site-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem clamp(1rem, 3vw, 2.5rem); background: rgba(255,255,255,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.site-header { position: sticky; top: 0; z-index: 100; }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--text); font-weight: 850; font-size: 1.2rem; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: conic-gradient(#ff5b5b, #ffc83d, #42c980, #3c82f6, #9357e7, #ff5b5b); color: white; box-shadow: inset 0 0 0 4px white; }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.plan-badge, .count-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .35rem .7rem; background: #eee9ff; color: #5030b5; font-size: .82rem; font-weight: 750; }

.app-shell { display: grid; grid-template-columns: minmax(310px, 410px) minmax(0, 1fr); min-height: calc(100vh - 138px); }
.control-panel { background: rgba(255,255,255,.96); border-right: 1px solid var(--line); padding: 1rem; overflow: auto; max-height: calc(100vh - 65px); position: sticky; top: 65px; }
.panel-section { padding: 1rem; margin-bottom: .85rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); box-shadow: 0 4px 18px rgba(30, 42, 67, .05); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.eyebrow { margin: 0 0 .25rem; color: var(--primary); font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-size: 1.25rem; line-height: 1.25; }
summary { font-weight: 800; }
details[open] summary { margin-bottom: 1rem; }
label, .label-like { display: block; font-weight: 700; font-size: .9rem; margin-bottom: .45rem; }
textarea, input[type="text"], select, input[type="file"] { width: 100%; border: 1px solid #bac6d6; border-radius: .7rem; background: white; color: var(--text); padding: .72rem .8rem; }
textarea { resize: vertical; min-height: 210px; line-height: 1.45; }
.help-text { color: var(--muted); font-size: .79rem; line-height: 1.45; margin: .5rem 0 0; }
.settings-stack { display: grid; gap: .85rem; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input[type="range"] { width: 100%; }
output { display: block; color: var(--muted); font-size: .78rem; text-align: right; }
.checkbox-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.checkbox-row label, .checkbox-line { display: flex; align-items: center; gap: .45rem; margin: 0; font-weight: 600; }

.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; margin-top: .9rem; }
.button { min-height: 42px; border: 1px solid #b7c3d2; border-radius: .7rem; background: white; color: var(--text); padding: .65rem .8rem; font-weight: 750; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); border-color: #8f9daf; }
.button.primary { background: var(--primary); border-color: var(--primary); color: white; }
.button.secondary { background: var(--surface-muted); }
.button.danger-ghost { color: var(--danger); }
.text-button { border: 0; padding: .2rem; background: transparent; color: var(--primary); font-weight: 750; }

.color-list { display: grid; grid-template-columns: repeat(6, minmax(35px, 1fr)); gap: .45rem; }
.color-item { min-width: 0; }
.color-item input { width: 100%; min-height: 34px; border: 0; padding: 0; background: transparent; }
.color-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .68rem; color: var(--muted); }

.wheel-stage { min-width: 0; padding: clamp(1rem, 2.5vw, 2rem); overflow: hidden; }
.wheel-layout { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 260px); align-items: start; gap: clamp(1rem, 2vw, 1.75rem); }
.wheel-main { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.ad-rail { display: grid; gap: 1rem; align-content: start; position: sticky; top: 85px; }
.ad-slot { width: 100%; border: 1px dashed #aab7c8; border-radius: .8rem; display: grid; place-items: center; align-content: center; background: rgba(255,255,255,.7); color: var(--muted); text-align: center; padding: 1rem; }
.ad-slot-rectangle { min-height: 250px; }
.ad-slot span { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; }
.ad-slot small { margin-top: .25rem; }
.wheel-wrap { position: relative; width: min(78vh, 100%, 900px); aspect-ratio: 1; display: grid; place-items: center; filter: drop-shadow(0 18px 30px rgba(30, 42, 67, .18)); }
#wheelCanvas { width: 100%; height: 100%; display: block; }
.spin-button { position: absolute; z-index: 4; width: clamp(88px, 13vw, 132px); aspect-ratio: 1; border-radius: 50%; border: clamp(6px, .7vw, 10px) solid white; background: var(--primary); color: white; font-size: clamp(1.05rem, 2vw, 1.55rem); font-weight: 900; letter-spacing: .08em; box-shadow: 0 8px 25px rgba(20, 20, 40, .3); }
.spin-button:hover:not(:disabled) { background: var(--primary-dark); transform: scale(1.04); }
.pointer { position: absolute; z-index: 5; top: 49%; right: -2px; transform: translateY(-50%); filter: drop-shadow(0 4px 4px rgba(0,0,0,.25)); }
.pointer-classic { width: 0; height: 0; border-top: 28px solid transparent; border-bottom: 28px solid transparent; border-right: 58px solid #172033; }
.pointer-diamond { width: 42px; height: 42px; background: #172033; transform: translateY(-50%) rotate(45deg); border: 5px solid white; }
.pointer-minimal { width: 58px; height: 12px; border-radius: 10px 0 0 10px; background: #172033; }
.interaction-shield { position: absolute; inset: -100vh -100vw; z-index: 3; cursor: wait; }
.status-message { min-height: 1.5em; margin: 0; font-weight: 700; text-align: center; }
.keyboard-tip { margin: 0; color: var(--muted); font-size: .8rem; }
kbd { padding: .1rem .35rem; border: 1px solid #bcc6d2; border-bottom-width: 2px; border-radius: .3rem; background: white; }

.history-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.history-list { margin: 0; padding-left: 1.4rem; max-height: 170px; overflow: auto; }
.history-list li { padding: .28rem 0; }
.empty-state { margin: .4rem 0 0; color: var(--muted); font-size: .82rem; }
.site-footer { border-top: 1px solid var(--line); border-bottom: 0; color: var(--muted); font-size: .85rem; }
.site-footer nav { display: flex; gap: 1rem; }
.site-footer a { color: inherit; }

.winner-dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: clamp(1rem, 4vw, 3rem);
  overflow: hidden;
  background: transparent;
  color: #fff;
}
.winner-dialog::backdrop {
  background: rgba(4, 8, 20, .86);
  backdrop-filter: blur(9px) saturate(1.15);
}
.winner-dialog[open] { display: grid; place-items: center; }
.winner-card {
  position: relative;
  z-index: 3;
  width: min(92vw, 760px);
  padding: clamp(2rem, 6vw, 4.75rem) clamp(1.25rem, 6vw, 4rem);
  overflow: hidden;
  text-align: center;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: clamp(1.5rem, 4vw, 2.75rem);
  background: linear-gradient(145deg, rgba(29,39,76,.94), rgba(12,17,39,.97));
  box-shadow: 0 32px 100px rgba(0,0,0,.52), inset 0 1px 0 rgba(255,255,255,.2);
  transform: scale(.78) translateY(22px);
  opacity: 0;
}
.winner-dialog.is-intro .winner-card { animation: winner-card-in .55s cubic-bezier(.2,.9,.2,1.2) forwards; }
.winner-intro {
  margin: 0;
  color: #ffd86b;
  font-size: clamp(1rem, 3vw, 1.55rem);
  font-weight: 850;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(12px);
}
.winner-dialog.is-intro .winner-intro { animation: winner-intro-in .45s .28s ease-out forwards; }
.winner-name {
  margin: .6rem 0 .8rem;
  overflow-wrap: anywhere;
  color: #fff;
  font-size: clamp(3rem, 12vw, 7.5rem);
  line-height: .96;
  letter-spacing: -.055em;
  text-shadow: 0 0 18px rgba(255,214,90,.55), 0 0 54px rgba(112,89,255,.55);
  opacity: 0;
  transform: scale(.35) rotate(-3deg);
}
.winner-message {
  margin: 0 auto;
  max-width: 42rem;
  color: rgba(255,255,255,.86);
  font-size: clamp(1.05rem, 3vw, 1.45rem);
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(12px);
}
.winner-actions {
  display: flex;
  justify-content: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 2rem;
  opacity: 0;
  transform: translateY(12px);
}
.winner-dialog.is-revealed .winner-name { animation: winner-name-reveal .78s cubic-bezier(.16,1.25,.28,1) forwards; }
.winner-dialog.is-revealed .winner-message { animation: winner-copy-in .45s .35s ease-out forwards; }
.winner-dialog.is-revealed .winner-actions { animation: winner-copy-in .45s .52s ease-out forwards; }
.winner-spin-again { box-shadow: 0 0 30px rgba(255,198,52,.28); }
.winner-spotlight {
  position: fixed;
  z-index: 1;
  width: min(115vw, 1100px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,224,105,.28) 0 8%, rgba(113,87,255,.18) 30%, transparent 68%);
  opacity: 0;
  transform: scale(.5);
  pointer-events: none;
}
.winner-dialog.is-revealed .winner-spotlight { animation: spotlight-bloom 1.1s ease-out forwards; }
.confetti-layer { position: fixed; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
.confetti-piece {
  position: absolute;
  top: -12vh;
  left: var(--x);
  width: var(--size);
  height: calc(var(--size) * .45);
  border-radius: 2px;
  background: hsl(var(--hue) 90% 60%);
  opacity: 0;
  transform: rotate(var(--rotation));
}
.winner-dialog.is-revealed .confetti-piece {
  animation: confetti-fall var(--duration) var(--delay) cubic-bezier(.15,.65,.35,1) forwards;
}
@keyframes winner-card-in { to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes winner-intro-in { to { opacity: 1; transform: translateY(0); } }
@keyframes winner-name-reveal {
  0% { opacity: 0; transform: scale(.35) rotate(-3deg); }
  62% { opacity: 1; transform: scale(1.08) rotate(1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes winner-copy-in { to { opacity: 1; transform: translateY(0); } }
@keyframes spotlight-bloom { 45% { opacity: 1; transform: scale(1.03); } 100% { opacity: .78; transform: scale(1); } }
@keyframes confetti-fall {
  0% { opacity: 0; transform: translate3d(0,-8vh,0) rotate(var(--rotation)); }
  10% { opacity: 1; }
  100% { opacity: .95; transform: translate3d(var(--drift),118vh,0) rotate(calc(var(--rotation) + 780deg)); }
}

.controls-locked .control-panel { pointer-events: none; user-select: none; opacity: .68; }
.controls-locked .site-header button { pointer-events: none; }

@media (max-width: 1100px) {
  .wheel-layout { grid-template-columns: minmax(0, 1fr) 180px; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .wheel-stage { min-height: auto; }
  .wheel-layout { grid-template-columns: 1fr; }
  .wheel-wrap { width: min(92vw, 720px); }
  .ad-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); position: static; width: min(100%, 720px); margin: .5rem auto 0; }
  .ad-slot-rectangle { min-height: 180px; }
}

@media (max-width: 540px) {
  .site-header, .site-footer { padding: .8rem 1rem; }
  .plan-badge { display: none; }
  .panel-section { padding: .85rem; }
  .button-grid, .two-column, .checkbox-row { grid-template-columns: 1fr; }
  .color-list { grid-template-columns: repeat(4, 1fr); }
  .wheel-stage { padding-inline: .5rem; }
  .wheel-wrap { width: 98vw; }
  .ad-rail { grid-template-columns: 1fr; width: min(100%, 360px); }
  .ad-slot-rectangle { min-height: 250px; }
  .keyboard-tip { display: none; }
  .site-footer { align-items: flex-start; flex-direction: column; }
}

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


@media (max-width: 540px) {
  .winner-dialog { padding: .75rem; }
  .winner-card { width: 100%; padding: 2.5rem 1rem 2rem; }
  .winner-actions { flex-direction: column; }
  .winner-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .winner-card,
  .winner-intro,
  .winner-name,
  .winner-message,
  .winner-actions,
  .winner-spotlight { animation: none !important; opacity: 1 !important; transform: none !important; }
  .confetti-layer { display: none; }
}
