:root {
  --gold: #f2b705;
  --red: #c1272d;
  --deep-red: #7a1518;
  --cream: #fff6e0;
  --ink: #2a1a0f;
  --panel-bg: #fffaf0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, #ffe9a8 0%, transparent 55%),
    repeating-linear-gradient(
      100deg,
      var(--red) 0px,
      var(--red) 60px,
      var(--cream) 60px,
      var(--cream) 120px
    );
  overflow-x: hidden;
}

.bigtop {
  height: 28px;
  background: repeating-linear-gradient(
    -55deg,
    var(--gold) 0 24px,
    var(--deep-red) 24px 48px
  );
  border-bottom: 4px solid var(--ink);
}

.page-header {
  text-align: center;
  padding: 1.2rem 1rem 0.4rem;
}

.page-header h1 {
  margin: 0;
  font-size: 2.4rem;
  text-shadow: 2px 2px 0 var(--gold);
  letter-spacing: 1px;
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 1.05rem;
  opacity: 0.85;
}

.layout {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  min-height: 78vh;
}

.wheel-stage {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.5rem);
}

.wheel-assembly {
  position: relative;
  width: min(80vw, 74vh, 800px);
  aspect-ratio: 1 / 1;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.35));
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 8px solid var(--ink);
  background: var(--cream);
  will-change: transform;
}

/* Only used when the lever is let go without pulling far enough — spin()
   drives the transform manually frame-by-frame and would fight a CSS
   transition, so this is applied and removed around that one case only. */
#wheelCanvas.snapping {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  transform-origin: 50% 0%;
  width: 0;
  height: 0;
  border-left: 22px solid transparent;
  border-right: 22px solid transparent;
  border-top: 38px solid var(--ink);
  z-index: 3;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4));
}

.pointer::after {
  content: "";
  position: absolute;
  top: -37px;
  left: -17px;
  width: 0;
  height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-top: 30px solid var(--red);
}

.hub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #4a4a4a, #0e0e0e 70%);
  border-radius: 50%;
  border: 4px solid var(--gold);
  z-index: 2;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hub:hover {
  filter: brightness(1.2);
}

.hub-timer-display {
  pointer-events: none;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 700;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.hub-timer-display.icon-mode {
  font-size: 42px;
  line-height: 1;
}

.hub-timer-display.warning {
  color: #ffb347;
}

.hub-timer-display.critical {
  color: #ff4d4d;
}

/* Segment hover controls: positioned via JS (left/top, in px) computed from
   the wedge's current on-screen angle, since the wheel itself is a canvas
   (no per-segment DOM elements to hang real hover/click listeners off of). */
.segment-btn {
  position: absolute;
  top: 0;
  left: 0;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  z-index: 4;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
}

.segment-btn-remove {
  background: var(--red);
  color: var(--cream);
}

.segment-btn-add {
  background: #4fa84f;
  color: var(--cream);
}

.segment-btn:hover {
  filter: brightness(1.12);
}

.segment-input {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  width: 140px;
  margin: -18px 0 0 -70px;
  padding: 0.3rem 0.5rem;
  font: 700 15px "Segoe UI", system-ui, sans-serif;
  text-align: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.lever-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}

.lever-housing {
  position: relative;
  width: 120px;
  height: 320px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.music-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--gold);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.music-btn:hover {
  filter: brightness(1.08);
}

.music-btn[aria-pressed="true"] {
  background: var(--red);
}

.lever-mount {
  position: absolute;
  bottom: 14px;
  left: 50%;
  width: 64px;
  height: 38px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #5a4128, #241a0f);
  border: 3px solid var(--ink);
  border-radius: 16px 16px 8px 8px;
  box-shadow:
    0 8px 14px rgba(0, 0, 0, 0.45),
    inset 0 3px 4px rgba(255, 255, 255, 0.18),
    inset 0 -4px 6px rgba(0, 0, 0, 0.5);
  z-index: 1;
}

/* Widened past its resting visual width so there's room for the top edge to
   flare outward on pull — clip-path carves the actual rod shape out of this
   wider box, tapering to a point at the base (100% = the pivot end, fixed)
   and flaring at the top (0% = the knob end, widens with `pull`). */
.lever-arm {
  position: absolute;
  top: 14px;
  bottom: 34px;
  left: 50%;
  width: 32px;
  transform: translateX(-50%) scaleY(1);
  transform-origin: 50% 100%;
  clip-path: polygon(25% 0%, 75% 0%, 75% 100%, 25% 100%);
  border-radius: 8px;
  background: linear-gradient(90deg, #5a3a1a 0%, #e0aa54 22%, #9a6a34 50%, #e0aa54 78%, #5a3a1a 100%);
  box-shadow: inset 2px 0 3px rgba(0, 0, 0, 0.3), inset -2px 0 3px rgba(255, 255, 255, 0.15);
  z-index: 0;
}

.lever-arm.snapping {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), clip-path 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* .lever is the sliding grip: JS sets its `top` (clamped to the housing's
   actual rendered size), so it can never travel past the fixed arm above.
   The arm shrinks toward its base (transform-origin: bottom) in lockstep,
   as if the rod were foreshortening while pulled out toward the viewer. */
.lever {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 50px;
  height: 50px;
  transform: translateX(-50%);
  cursor: grab;
  touch-action: none;
  z-index: 2;
}

.lever.snapping {
  transition: top 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lever-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ff9d9d 0%, #ff6b6b 35%, var(--red) 68%, var(--deep-red) 100%);
  border: 3px solid var(--ink);
  box-shadow:
    0 6px 10px rgba(0, 0, 0, 0.5),
    inset -5px -5px 9px rgba(0, 0, 0, 0.35),
    inset 4px 4px 6px rgba(255, 255, 255, 0.55);
  transform: scale(1);
}

.lever.snapping .lever-knob {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lever:active .lever-knob,
.lever:focus-visible .lever-knob {
  outline: 3px solid var(--gold);
}

.winner-overlay,
.timer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 5, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 0.25s ease;
}

.winner-overlay[hidden],
.timer-overlay[hidden] {
  display: none;
}

.winner-card,
.timer-card {
  background: var(--cream);
  border: 6px solid var(--gold);
  border-radius: 20px;
  padding: 2.4rem 3rem;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.timer-card {
  position: relative;
  width: min(92vw, 820px);
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1.5rem, 6vw, 4rem);
}

.timer-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  background: none;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.55;
  padding: 0.2rem;
}

.timer-close:hover {
  opacity: 1;
}

.timer-label {
  font-size: clamp(1rem, 2vw, 1.4rem);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.7;
}

.timer-display {
  font-size: clamp(5rem, 14vw, 10rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  margin: 0.5rem 0 2rem;
  transition: color 0.3s ease;
  cursor: pointer;
  border-radius: 12px;
}

.timer-display:hover {
  background: rgba(0, 0, 0, 0.06);
}

.timer-display.warning {
  color: #e8820c;
}

.timer-display.critical {
  color: var(--red);
  text-shadow: 2px 2px 0 var(--gold);
}

.timer-edit {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(0.6rem, 2vw, 1.2rem);
  margin: 0.5rem 0 2rem;
}

.timer-edit[hidden] {
  display: none;
}

.timer-edit-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.timer-edit-label {
  font-size: clamp(0.85rem, 1.8vw, 1.15rem);
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.65;
}

.timer-edit-colon {
  font-size: clamp(3.5rem, 9vw, 6.5rem);
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  opacity: 0.6;
  padding-bottom: clamp(0.4rem, 1vw, 0.8rem);
}

.timer-edit-field {
  width: clamp(5.5rem, 17vw, 10.5rem);
  padding: clamp(0.4rem, 1vw, 0.7rem) 0.3rem;
  font: 800 clamp(3.5rem, 9vw, 6.5rem)/1 "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}

.timer-edit-field:focus {
  outline: 4px solid var(--gold);
  outline-offset: 1px;
}

.timer-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.timer-controls .close-btn {
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  padding: clamp(0.7rem, 1.8vw, 1.1rem) clamp(1.4rem, 3.5vw, 2.4rem);
}

.winner-label {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.7;
}

.winner-name {
  font-size: 3rem;
  font-weight: 800;
  color: var(--red);
  margin: 0.4rem 0 0.6rem;
  text-shadow: 2px 2px 0 var(--gold);
}

.clipboard-status {
  min-height: 1.3em;
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
  color: #6b5a44;
}

.clipboard-status.success {
  color: #2f7a3a;
}

.clipboard-status.error {
  color: var(--red);
}

.winner-actions {
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
}

.close-btn {
  font-size: 1rem;
  padding: 0.6rem 1.6rem;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--red);
  color: var(--cream);
  cursor: pointer;
  font-weight: 600;
}

.close-btn.secondary {
  background: var(--gold);
  color: var(--ink);
}

.close-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 11;
}

/* Sits at the viewport's bottom edge; sliding it down by more than its own
   height when hidden, and only partway back up when visible, means the
   browser's own viewport edge crops it — a real "peeking over the edge"
   look with no clip-path or image needed. */
.nervous-monkey {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 9;
  pointer-events: none;
}

.nervous-monkey.visible {
  transform: translateX(-50%) translateY(24%);
}

.monkey-face {
  display: block;
  font-size: 6rem;
  line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
  animation: monkey-jitter 0.34s infinite alternate;
}

/* The result reveal replaces the nervous jitter with a one-shot pop, so the
   final 🙉 pose reads as a distinct beat rather than more of the same wobble. */
.nervous-monkey.reveal .monkey-face {
  animation: monkey-reveal-pop 0.5s ease forwards;
}

@keyframes monkey-jitter {
  from {
    transform: rotate(-3deg) translateX(-2px);
  }
  to {
    transform: rotate(3deg) translateX(2px);
  }
}

@keyframes monkey-reveal-pop {
  0% {
    transform: scale(0.85) rotate(0deg);
  }
  45% {
    transform: scale(1.25) rotate(-6deg);
  }
  75% {
    transform: scale(0.95) rotate(4deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  opacity: 0.95;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(105vh) rotate(720deg);
    opacity: 0.3;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pop {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 720px) {
  .wheel-stage {
    flex-direction: column-reverse;
    gap: 0.6rem;
  }
  .lever-housing {
    width: 100px;
    height: 220px;
  }
}
