:root {
  --gold-hi: #f8e6b0;
  --gold: #d6ac5a;
  --gold-lo: #8a6424;
  --text: #f3ead2;
  --muted: rgba(243, 234, 210, 0.62);
  /* Wheel diameter: fits width and height on any screen */
  --size: max(240px, min(92vw, calc(100vh - 170px), 660px));
}

@supports (height: 100svh) {
  :root { --size: max(240px, min(92vw, calc(100svh - 170px), 660px)); }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  color: var(--text);
  background-color: #052116;
  background-image:
    radial-gradient(ellipse 80% 65% at 50% 45%, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse at 50% 40%, #146041 0%, #0b3a27 48%, #041a11 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.2vh, 22px);
  /* The spinning square canvas has transparent corners that would widen the page */
  overflow-x: hidden;
  overflow-x: clip;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: clamp(1.55rem, 5.4vw, 2.5rem);
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-align: center;
  color: var(--gold);
  background: linear-gradient(180deg, var(--gold-hi) 10%, var(--gold) 55%, var(--gold-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}

/* ---------- Wheel ---------- */

.scene {
  width: var(--size);
  height: var(--size);
  flex: none;
  perspective: calc(var(--size) * 3);
  perspective-origin: 50% 50%;
}

.wheel {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform-origin: 50% 50%;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}

/* Table shadow under the wheel (sits at the bottom of the wheel body) */
.wheel-floor {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #1a0b04;
  box-shadow:
    0 calc(var(--size) * 0.04) calc(var(--size) * 0.09) rgba(0, 0, 0, 0.6),
    0 calc(var(--size) * 0.01) calc(var(--size) * 0.02) rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* The flat top surface: bowl, rotor and lighting */
.face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: translateZ(0);
  pointer-events: none;
}

/* Cylinder walls built from thin strips (wheel side and hub side) */
.cyl {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  pointer-events: none;
}
.wheel.is-flat .cyl { visibility: hidden; }

.strip {
  position: absolute;
  left: 50%;
  top: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.ball-shadow {
  --bs: calc(var(--size) * 0.042);
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--bs);
  height: var(--bs);
  margin: calc(var(--bs) / -2) 0 0 calc(var(--bs) / -2);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.62) 0%, rgba(0, 0, 0, 0.38) 42%, rgba(0, 0, 0, 0) 72%);
  will-change: transform, opacity;
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}

.rotor {
  will-change: transform;
  transform: translateZ(0);
}

.ball {
  --ball: calc(var(--size) * 0.032);
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--ball);
  height: var(--ball);
  margin: calc(var(--ball) / -2) 0 0 calc(var(--ball) / -2);
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
  background: radial-gradient(circle at 34% 30%, #ffffff 0%, #fbfbfb 18%, #dcdcdc 52%, #9c9c9c 85%, #7a7a7a 100%);
}

.ball.ghost {
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(230, 230, 230, 0.6) 55%, rgba(200, 200, 200, 0) 100%);
}

/* ---------- Centre button (turret) ---------- */

.hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--size) * 0.31);
  height: calc(var(--size) * 0.31);
  transform: translate(-50%, -50%) translateZ(calc(var(--size) * 0.035));
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background: radial-gradient(circle at 35% 28%, #fff4cc 0%, #e6c06a 28%, #a77a2c 62%, #4f3611 100%);
  box-shadow:
    0 calc(var(--size) * 0.012) calc(var(--size) * 0.03) rgba(0, 0, 0, 0.65),
    inset 0 0 0 1px rgba(255, 240, 200, 0.35);
}

.hub:focus { outline: none; }
.hub:focus-visible {
  outline: 3px solid rgba(248, 230, 176, 0.9);
  outline-offset: 4px;
}

/* Pulsing ring invites the first tap */
.hub::after {
  content: "";
  position: absolute;
  inset: -7%;
  border-radius: 50%;
  border: 2px solid rgba(248, 230, 176, 0.6);
  pointer-events: none;
  opacity: 0;
}
.hub[data-state="idle"]::after { animation: pulse 2.2s ease-out infinite; }

@keyframes pulse {
  0%   { transform: scale(0.9);  opacity: 0.9; }
  100% { transform: scale(1.22); opacity: 0; }
}

.hub-face {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 38% 30%, #ffffff 0%, #eef0f2 16%, #bcc2c9 44%, #737a82 76%, #3a3f45 100%);
  box-shadow:
    inset 0 calc(var(--size) * -0.008) calc(var(--size) * 0.02) rgba(0, 0, 0, 0.5),
    inset 0 calc(var(--size) * 0.005) calc(var(--size) * 0.008) rgba(255, 255, 255, 0.6);
  transition: transform 0.14s ease;
}

.hub:active .hub-face { transform: scale(0.94); }

@media (hover: hover) {
  .hub[data-state="idle"]:hover .hub-face,
  .hub[data-state="result"]:hover .hub-face { transform: scale(1.03); }
  .hub[data-state="idle"]:active .hub-face,
  .hub[data-state="result"]:active .hub-face { transform: scale(0.94); }
}

/* Result colour layer */
.hub-face::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  background: #111;
}
.hub[data-color="red"]   .hub-face::before { background: radial-gradient(circle at 38% 30%, #ff5a5f 0%, #d9161f 40%, #8e0910 100%); }
.hub[data-color="black"] .hub-face::before { background: radial-gradient(circle at 38% 30%, #5a5a5a 0%, #222 42%, #050505 100%); }
.hub[data-color="green"] .hub-face::before { background: radial-gradient(circle at 38% 30%, #4fe08f 0%, #12a352 42%, #075a2b 100%); }
.hub[data-state="result"] .hub-face::before { opacity: 1; }

/* Glass highlight */
.hub-face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(ellipse 72% 46% at 50% 16%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 72%);
}

/* Stretches the label upward in 3D so it still reads naturally when tilted */
.hub-comp {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: scaleY(var(--comp, 1));
}

.hub-text {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.hub-spin {
  font-weight: 800;
  font-size: calc(var(--size) * 0.046);
  letter-spacing: 0.16em;
  padding-left: 0.16em;
  color: #2a2e33;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.hub-result {
  opacity: 0;
  transform: scale(0.6);
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.hub-number {
  font-weight: 800;
  font-size: calc(var(--size) * 0.112);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.hub-colour {
  margin-top: calc(var(--size) * 0.006);
  font-weight: 700;
  font-size: calc(var(--size) * 0.024);
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  opacity: 0.92;
}

.hub[data-state="spinning"] { cursor: default; }
.hub[data-state="spinning"] .hub-spin,
.hub[data-state="result"] .hub-spin { opacity: 0; transform: scale(0.8); }
.hub[data-state="result"] .hub-result { opacity: 1; transform: scale(1); }

/* ---------- View toggle ---------- */

.view-toggle {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  box-shadow: inset 0 0 0 1px rgba(248, 230, 176, 0.18);
}

.view-btn {
  min-width: 56px;
  min-height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.view-btn[aria-pressed="true"] {
  color: #2a1d06;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 60%, #b98a3c);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.view-btn:focus { outline: none; }
.view-btn:focus-visible { outline: 2px solid rgba(248, 230, 176, 0.9); outline-offset: 2px; }

@media (hover: hover) {
  .view-btn[aria-pressed="false"]:hover { color: var(--text); }
}

/* ---------- Text ---------- */

.hint {
  margin: 0;
  min-height: 1.4em;
  font-size: clamp(0.9rem, 2.6vw, 1.05rem);
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .hub[data-state="idle"]::after { animation: none; }
  .hub-text { transition: opacity 0.2s ease; }
}
