:root {
  --text: #f2f3f7;
  --muted: rgba(242, 243, 247, 0.55);
  --glass: rgba(22, 24, 32, 0.42);
  --glass-line: rgba(255, 255, 255, 0.12);
  --field: rgba(0, 0, 0, 0.22);
  --warn: #fbbf77;
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  /* Screen area covered by the panel – set from JS so every mode centres in the free space. */
  --inset-left: 0px;
  --inset-bottom: 0px;
  /* Band below the object where the result appears. */
  --result-space: 96px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: radial-gradient(ellipse at 60% 40%, #1f2330 0%, #111319 70%, #0b0c10 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button,
textarea,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- The view ---------- */

.stage {
  position: fixed;
  inset: 0;
  cursor: pointer;
}

.mode-view {
  position: absolute;
  inset: 0;
}

.mode-view canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 2D modes live in the free area; the 3D canvas stays full-screen and shifts its camera instead. */
.wheel-view,
.slot-view {
  left: var(--inset-left);
  bottom: calc(var(--inset-bottom) + var(--result-space));
  display: grid;
  place-items: center;
}

.wheel-view canvas {
  width: auto;
  height: auto;
}

.mode-view.entering {
  animation: camera-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes camera-in {
  from {
    opacity: 0;
    transform: scale(0.82) rotate(-6deg);
  }
}

.result {
  position: fixed;
  left: var(--inset-left);
  right: 0;
  bottom: calc(var(--inset-bottom) + 22px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px;
  text-align: center;
  pointer-events: none;
  text-shadow:
    0 2px 14px rgba(0, 0, 0, 0.7),
    0 0 2px rgba(0, 0, 0, 0.6);
  animation: result-in 0.4s ease-out;
}

.result-label {
  max-width: 100%;
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.result-meta {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ---------- Floating panel ---------- */

.panel {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  width: 320px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modes {
  display: flex;
  gap: 2px;
}

.modes button,
.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 18px;
  opacity: 0.55;
  transition:
    opacity 0.15s,
    background 0.15s;
}

.modes button:hover,
.icon-btn:hover {
  opacity: 0.9;
}

.modes button[aria-selected='true'] {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

.modes button:disabled {
  cursor: default;
}

.options-input {
  display: block;
  width: 100%;
  min-height: 96px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--field);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}

.options-input:focus {
  border-color: rgba(255, 255, 255, 0.25);
}

.options-input::placeholder {
  color: var(--muted);
}

.toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: 8px;
  background: var(--field);
}

.toggle button {
  padding: 4px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.toggle button[aria-checked='true'] {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

/* ---------- Distribution ---------- */

.dist-bar {
  display: flex;
  height: 4px;
  flex: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--field);
}

.dist-bar span {
  height: 100%;
  transition: width 0.2s ease;
}

.dist-list {
  list-style: none;
  margin: 0 -4px;
  padding: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.dist-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 6px;
}

.dist-row.weighted {
  grid-template-columns: 8px minmax(0, 1fr) 84px auto;
}

.dist-row.is-zero {
  opacity: 0.4;
}

.dist-row.is-winner {
  background: rgba(255, 255, 255, 0.1);
}

.dist-row .swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dist-row .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dist-row .pct {
  min-width: 46px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.dist-row input[type='range'] {
  width: 100%;
  margin: 0;
  accent-color: #e5e7eb;
}

.dist-list .empty {
  color: var(--muted);
  padding: 2px 4px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
}

.hint:empty {
  display: none;
}

.hint.is-warning {
  color: var(--warn);
}

.decide {
  flex: none;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  color: #111318;
  font-weight: 700;
  transition:
    background 0.15s,
    opacity 0.15s;
}

.decide:hover:not(:disabled) {
  background: #fff;
}

.decide:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---------- Slot machine ---------- */

.slot-machine {
  --item-h: 76px;
  width: min(100% - 48px, 640px);
  padding: 10px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 30px 60px -25px rgba(0, 0, 0, 0.8);
}

.slot-reels {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.reel {
  position: relative;
  height: calc(var(--item-h) * 3);
  overflow: hidden;
  border-radius: 10px;
  background: #f4f4f6;
}

.reel::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), transparent 33%, transparent 67%, rgba(0, 0, 0, 0.5));
}

.reel-strip {
  will-change: transform;
}

.reel-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--item-h);
  padding: 0 10px;
  color: #15161c;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}

.reel-item .chip {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.reel-item .text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.reel.is-blurred .reel-strip {
  filter: blur(1.4px);
}

.payline {
  position: absolute;
  left: -4px;
  right: -4px;
  top: var(--item-h);
  height: var(--item-h);
  border-block: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 4px;
  pointer-events: none;
}

.slot-machine.is-win .payline {
  animation: payline-flash 0.3s ease-in-out 3;
}

@keyframes payline-flash {
  50% {
    border-color: rgba(255, 255, 255, 0.1);
  }
}

/* ---------- Phones: panel docks to the bottom ---------- */

@media (max-width: 760px) {
  :root {
    --result-space: 64px;
  }

  .panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: 46vh;
    gap: 8px;
  }

  .options-input {
    min-height: 64px;
  }

  .slot-machine {
    --item-h: 56px;
  }

  .reel-item {
    font-size: 14px;
    padding: 0 6px;
  }
}
