:root {
  --ink: #4a1238;
  --gold: #ffd56a;
  --cream: #fff6e4;
  --pink: #ff4f93;
  --reel-h: clamp(72px, 18dvh, 148px);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  max-width: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 214, 102, 0.7), transparent 36%),
    radial-gradient(circle at 92% 8%, rgba(46, 224, 196, 0.55), transparent 32%),
    radial-gradient(circle at 80% 100%, rgba(255, 79, 147, 0.4), transparent 42%),
    linear-gradient(165deg, #ff9ec4 0%, #ffd0a4 48%, #7ee0d2 100%);
}

.garland {
  position: fixed;
  z-index: 2;
  top: calc(4px + env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.garland span {
  width: 12px;
  height: 16px;
  border-radius: 50% 50% 45% 45%;
  box-shadow: 0 8px 10px rgba(120, 20, 40, 0.18);
  animation: bulb 1.4s ease-in-out infinite alternate;
}

.garland span:nth-child(3n + 1) { background: #ff4f93; }
.garland span:nth-child(3n + 2) { background: #ffd56a; animation-delay: -0.4s; }
.garland span:nth-child(3n) { background: #2ec9b8; animation-delay: -0.8s; }

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.confetti i {
  position: absolute;
  top: -12%;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.9;
  animation: fall linear infinite;
}

.confetti i:nth-child(1) { left: 6%; background: #ff4f93; animation-duration: 7.5s; animation-delay: -1s; }
.confetti i:nth-child(2) { left: 16%; background: #ffd56a; animation-duration: 8.5s; animation-delay: -3s; }
.confetti i:nth-child(3) { left: 28%; background: #2ec9b8; animation-duration: 6.8s; animation-delay: -2s; }
.confetti i:nth-child(4) { left: 40%; background: #fff; animation-duration: 9s; animation-delay: -5s; }
.confetti i:nth-child(5) { left: 52%; background: #ff8a3d; animation-duration: 7.2s; animation-delay: -4s; }
.confetti i:nth-child(6) { left: 63%; background: #c084fc; animation-duration: 8s; animation-delay: -1.5s; }
.confetti i:nth-child(7) { left: 74%; background: #ff4f93; animation-duration: 6.4s; animation-delay: -6s; }
.confetti i:nth-child(8) { left: 84%; background: #ffd56a; animation-duration: 9.4s; animation-delay: -2.5s; }
.confetti i:nth-child(9) { left: 92%; background: #2ec9b8; animation-duration: 7.8s; animation-delay: -3.5s; }
.confetti i:nth-child(10) { left: 22%; background: #fff; width: 6px; height: 10px; animation-duration: 10s; animation-delay: -7s; }
.confetti i:nth-child(11) { left: 48%; background: #ff4f93; animation-duration: 8.8s; animation-delay: -0.5s; }
.confetti i:nth-child(12) { left: 70%; background: #ffd56a; animation-duration: 6.2s; animation-delay: -4.5s; }

.screen {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  height: 100vh;
  height: 100dvh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: clamp(8px, 1.4dvh, 14px);
  padding:
    calc(26px + env(safe-area-inset-top))
    calc(14px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom))
    calc(14px + env(safe-area-inset-left));
  overflow: hidden;
}

h1,
.plaque,
.message,
.result,
.counter {
  margin: 0;
  text-align: center;
}

h1 {
  font-size: clamp(22px, 4.2dvh, 40px);
  line-height: 1.15;
  color: #fff;
  text-shadow: 0 2px 0 #d23b78, 0 0 8px rgba(255, 236, 170, 0.9);
}

.message {
  color: var(--ink);
  background: rgba(255, 246, 228, 0.92);
  border-radius: 16px;
  padding: 8px 12px;
  font-size: clamp(15px, 2.15dvh, 18px);
  line-height: 1.35;
}

.message.birthday {
  background: transparent;
  color: #6b123f;
  font-size: clamp(26px, 5.2dvh, 48px);
  font-weight: 800;
  line-height: 1.05;
  padding: 0;
  text-shadow: 0 1px 0 #ffe9a8;
}

.result {
  font-size: clamp(26px, 5.5dvh, 52px);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
  color: var(--cream);
  text-shadow: 0 2px 0 #c43b6e, 0 0 8px rgba(255, 210, 80, 0.85);
}

.counter {
  font-size: clamp(15px, 2.2dvh, 18px);
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 246, 228, 0.88);
  border-radius: 999px;
  padding: 4px 12px;
  align-self: center;
}

.machine {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 213, 106, 0.4), transparent 55%),
    linear-gradient(180deg, #8a2a62 0%, #4c1a78 100%);
  border-radius: 28px;
  padding: clamp(8px, 1.6dvh, 16px);
  box-shadow:
    0 0 0 4px var(--gold),
    0 0 0 8px var(--pink),
    0 16px 36px rgba(80, 10, 40, 0.35);
}

.plaque {
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: clamp(14px, 2.4dvh, 22px);
  margin-bottom: 6px;
  text-shadow: 0 0 10px rgba(255, 213, 106, 0.85);
}

.reels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 1.5vw, 12px);
  background: #2a0c22;
  border-radius: 16px;
  padding: 8px;
  box-shadow:
    inset 0 0 0 3px var(--gold),
    0 0 22px rgba(255, 213, 106, 0.45);
}

.reel-window {
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--reel-h);
  min-height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  appearance: none;
  overflow: hidden;
  position: relative;
  border-radius: 12px;
  background: linear-gradient(#fffaf0, #ffe08a);
  box-shadow:
    inset 0 0 0 3px #f0c14a,
    inset 0 0 18px rgba(255, 170, 40, 0.55);
  font: inherit;
  color: inherit;
  cursor: default;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.reel-window.can-stop {
  cursor: pointer;
}

.reel-window.is-armed {
  box-shadow:
    inset 0 0 0 3px #fff6d0,
    inset 0 0 18px rgba(255, 210, 80, 0.95);
}

.reel-window:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.reel-window::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 42%, transparent 62%, rgba(80, 20, 40, 0.12));
  pointer-events: none;
}

.reel-strip {
  display: flex;
  flex-direction: column;
  will-change: transform;
}

.digit {
  height: var(--reel-h);
  flex: 0 0 var(--reel-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--reel-h) * 0.68);
  font-weight: 800;
  line-height: 1;
  color: #4a1460;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.reel-window.is-spinning .digit {
  filter: blur(1.5px);
}

.reel-window.landed {
  animation: land 0.35s ease-out;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.actions button {
  min-height: 48px;
  min-width: 48px;
  padding: 12px 28px;
  border: 3px solid #fff4cc;
  border-radius: 999px;
  font: inherit;
  font-size: clamp(18px, 2.8dvh, 26px);
  font-weight: 800;
  color: var(--ink);
  touch-action: manipulation;
  cursor: pointer;
}

#spin {
  background: radial-gradient(circle at 50% 28%, #ffe9a0 0%, #ffb703 30%, #ff6b2c 64%, #e11d6a 100%);
  box-shadow:
    0 4px 0 #9a1b4a,
    0 8px 18px rgba(120, 20, 50, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.75);
}

#restart {
  background: radial-gradient(circle at 50% 28%, #f3fffb 0%, #7eecd8 38%, #14a898 100%);
  box-shadow:
    0 4px 0 #0e6f68,
    0 8px 18px rgba(12, 80, 70, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.75);
}

.actions button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #9a1b4a, inset 0 2px 0 rgba(255, 255, 255, 0.75);
}

#restart:active:not(:disabled) {
  box-shadow: 0 2px 0 #0e6f68, inset 0 2px 0 rgba(255, 255, 255, 0.75);
}

.actions button:disabled {
  filter: brightness(0.82);
  cursor: default;
}

.actions button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

@media (max-height: 560px) and (max-width: 520px) {
  :root { --reel-h: clamp(56px, 22dvh, 96px); }
  .plaque { display: none; }
  .message { font-size: 14px; line-height: 1.25; padding: 6px 8px; }
  .screen { gap: 4px; }
  h1 { font-size: 20px; }
}

@media (max-height: 520px) and (min-width: 560px) {
  .garland { display: none; }
  .screen {
    width: min(960px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    grid-template-areas:
      "title machine"
      "message machine"
      "result machine"
      "counter machine"
      "actions actions";
    align-items: center;
    column-gap: 16px;
    row-gap: 6px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  h1 { grid-area: title; }
  .message { grid-area: message; }
  .result { grid-area: result; }
  .machine { grid-area: machine; }
  .counter { grid-area: counter; justify-self: center; }
  .actions { grid-area: actions; }
  :root { --reel-h: clamp(64px, 36dvh, 120px); }
}

@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .garland span,
  .reel-window.landed { animation: none; }
}

@keyframes bulb {
  from { transform: translateY(0) scale(1); filter: brightness(0.85); }
  to { transform: translateY(2px) scale(1.08); filter: brightness(1.35); }
}

@keyframes fall {
  to { transform: translateY(110dvh) rotate(220deg); }
}

@keyframes land {
  from { transform: scale(1.04); }
  to { transform: scale(1); }
}
