:root {
  --bg: #160d2b;
  --panel: #231543;
  --panel2: #2f1d5a;
  --line: #4a3680;
  --text: #f5f0ff;
  --muted: #b6a8d8;
  --accent: #ffcf3f;
  --accent2: #ff5d73;
  --ink: #1b1030;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(circle at 50% -10%, #3b1f78 0, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 0;
}
h1 { margin: 0; font-size: 2.2rem; font-weight: 900; letter-spacing: .02em; }
h1 span { color: var(--accent); }

.icon-btn {
  font-size: 1.3rem;
  background: var(--panel);
  border: 0;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  cursor: pointer;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ---------- controls ---------- */
.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  padding: 14px;
  border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
}
.row { display: flex; gap: 8px; }

select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
select { flex: 1; }
textarea { resize: vertical; line-height: 1.4; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel2);
  white-space: nowrap;
}
.btn.ghost:hover { background: #3d2770; }
.btn.primary { background: var(--accent); color: var(--ink); }
.btn.danger { background: transparent; color: var(--accent2); box-shadow: inset 0 0 0 1px currentColor; }

.modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: var(--bg);
  padding: 5px;
  border-radius: 12px;
}
.modes button {
  font: inherit;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 4px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.modes button:hover { color: var(--text); }
.modes button[aria-selected="true"] {
  background: var(--panel2);
  color: var(--text);
  box-shadow: inset 0 0 0 2px var(--accent);
}
@media (max-width: 480px) {
  .modes { grid-template-columns: repeat(2, 1fr); }
}

button:disabled, select:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- stage ---------- */
.stage {
  width: 100%;
  min-height: 340px;
  display: grid;
  place-items: center;
}
.hint { min-height: 1.4em; color: var(--muted); font-weight: 600; text-align: center; }

.spin-btn {
  font: inherit;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: .15em;
  padding: 16px 56px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(180deg, #ffe27a, #ffb000);
  box-shadow: 0 6px 0 #b86f00, 0 10px 30px rgba(255, 180, 0, .35);
  transition: transform .08s, box-shadow .08s;
}
.spin-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b86f00, 0 6px 20px rgba(255, 180, 0, .35);
}

.result { min-height: 5.5rem; text-align: center; }
.result small { display: block; color: var(--muted); font-weight: 600; }
.result strong {
  display: block;
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 900;
  color: var(--accent);
  word-break: break-word;
  text-shadow: 0 4px 24px rgba(255, 207, 63, .35);
}
.result.show strong { animation: pop .55s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

.history { width: 100%; }
.history:has(ol:empty) { display: none; }
.history h2 {
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 0 8px;
}
.history ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.history li { background: var(--panel); padding: 6px 12px; border-radius: 999px; font-size: .9rem; }
.history li span { color: var(--muted); font-size: .75rem; margin-left: 6px; }

/* ---------- wheel ---------- */
.wheel { position: relative; width: min(88vw, 440px); aspect-ratio: 1; }
.wheel canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 8px var(--panel2), 0 0 0 14px #ffcf3f33, 0 20px 50px rgba(0, 0, 0, .5);
}
.wheel-pointer {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 38px solid var(--accent);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .5));
  z-index: 2;
}
.wheel-hub {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14%;
  height: 14%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, var(--accent) 40%, #b37a00);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}

/* ---------- slots ---------- */
.slot {
  width: min(92vw, 460px);
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, #e33b55, #9c1d3a);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .3);
}
.slot-window {
  --h: 90px;
  position: relative;
  height: calc(var(--h) * 3);
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
}
.slot-window::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.6), transparent 32%, transparent 68%, rgba(0,0,0,.6));
}
.slot-line {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--h);
  height: var(--h);
  border-top: 3px solid var(--accent);
  border-bottom: 3px solid var(--accent);
  pointer-events: none;
  z-index: 1;
}
.reel { will-change: transform; }
.reel-item {
  height: var(--h);
  line-height: var(--h);
  padding: 0 16px;
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: color-mix(in srgb, var(--c) 35%, white);
  border-bottom: 1px solid rgba(0, 0, 0, .08);
}
@media (max-width: 480px) {
  .slot-window { --h: 72px; }
  .reel-item { font-size: 1.35rem; }
}

/* ---------- lights ---------- */
.lights { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.tile {
  flex: 1 1 130px;
  max-width: 220px;
  min-height: 72px;
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid color-mix(in srgb, var(--c) 45%, transparent);
  font-weight: 700;
  text-align: center;
  word-break: break-word;
  transition: background .1s, color .1s, transform .1s, box-shadow .1s;
}
.tile.on {
  background: var(--c);
  color: var(--ink);
  transform: scale(1.06);
  box-shadow: 0 0 24px var(--c);
}
.tile.win { animation: blink .3s 6 alternate; }
@keyframes blink { to { box-shadow: 0 0 48px 8px var(--c); transform: scale(1.12); } }

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  width: 100%;
}
.card {
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  perspective: 800px;
  font: inherit;
  cursor: default;
}
.pickable .card { cursor: pointer; }
.pickable .card:hover .card-inner { transform: translateY(-8px) rotate(-3deg); }
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.3, 1.4, .5, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-back, .card-front {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
}
.card-back {
  background: repeating-linear-gradient(45deg, #ff5d73 0 8px, #e24563 8px 16px);
  border: 4px solid #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .4);
}
.card-back::after { content: "?"; font-size: 2rem; font-weight: 900; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,.3); }
.card-front {
  transform: rotateY(180deg);
  background: #fff;
  color: var(--ink);
  border: 4px solid var(--c, #ccc);
  padding: 8px;
  font-weight: 800;
  font-size: .95rem;
  text-align: center;
  word-break: break-word;
}
.card.chosen { position: relative; z-index: 2; }
.card.chosen .card-front { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent), 0 0 36px var(--accent); }
.card.dim { opacity: .5; }

/* ---------- dialog ---------- */
dialog {
  width: min(92vw, 460px);
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(10, 5, 25, .7); }
dialog h2 { margin: 0 0 14px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  animation: fall var(--d) var(--delay) cubic-bezier(.2, .6, .4, 1) forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }
