/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  height: 100svh;   /* small viewport height — excludes browser chrome */
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1a0533 0%, #0a0118 70%);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  overflow: hidden;
}

/* ── Stars backdrop ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 70%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 10%, rgba(255,255,255,.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 50%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 85%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 20% 90%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 35%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 92% 15%, rgba(255,255,255,.6) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* gaps and padding shrink on short viewports */
  gap: clamp(8px, 1.6vh, 24px);
  padding: clamp(8px, 1.4vh, 28px) 16px;
}

/* ── Title ── */
.title {
  font-size: clamp(1.4rem, 3.5vh, 2.4rem);
  font-weight: 900;
  letter-spacing: .04em;
  text-shadow: 0 0 24px rgba(255, 200, 50, .7), 0 2px 4px rgba(0,0,0,.6);
  color: #ffd84d;
  flex-shrink: 0;
}

/* ── Wheel container ── */
.wheel-container {
  position: relative;
  /*
   * The canvas internal resolution is always 520×520 (set in HTML).
   * CSS width/height control the *display* size — the browser scales it.
   * 250px budget for title + power bar + spin btn + gaps + padding + pointer.
   */
  width:  min(520px, calc(100svh - 250px));
  height: min(520px, calc(100svh - 250px));
  flex-shrink: 0;
}

#wheelCanvas {
  /* Fill the container — canvas scales visually, JS coords unchanged */
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow:
    0 0 0 6px #1a0533,
    0 0 0 12px #ffd84d,
    0 0 40px rgba(255, 216, 77, .5),
    0 8px 40px rgba(0,0,0,.7);
  display: block;
}

/* ── Pointer (arrow at top) ── */
.pointer {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 46px solid #ff3b3b;
  filter: drop-shadow(0 2px 6px rgba(255,59,59,.7));
  z-index: 10;
}
.pointer::after {
  content: '';
  position: absolute;
  top: -50px;
  left: -10px;
  width: 20px;
  height: 20px;
  background: #ff3b3b;
  border-radius: 50%;
}

/* Center cap */
.center-cap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: radial-gradient(circle at 35% 35%, #fff 0%, #ffd84d 40%, #c8950a 100%);
  border-radius: 50%;
  border: 4px solid #1a0533;
  box-shadow: 0 0 12px rgba(255,216,77,.8), 0 2px 6px rgba(0,0,0,.6);
  z-index: 5;
}

/* ── Power bar ── */
.power-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(420px, 90vw);
  flex-shrink: 0;
}

.power-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: #ffd84d;
  width: 52px;
  flex-shrink: 0;
}

.power-track {
  flex: 1;
  height: 18px;
  background: rgba(255,255,255,.08);
  border-radius: 9px;
  border: 1px solid rgba(255,216,77,.3);
  overflow: hidden;
}

.power-fill {
  height: 100%;
  width: 0%;
  border-radius: 9px;
  background: linear-gradient(90deg, #22c55e 0%, #facc15 60%, #ef4444 100%);
  transition: width 40ms linear;
  box-shadow: 0 0 10px rgba(250,204,21,.4);
}

.power-pct {
  font-size: .75rem;
  font-weight: 700;
  color: #ffd84d;
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Spin button ── */
.spin-btn {
  padding: clamp(10px, 1.6vh, 16px) 52px;
  font-size: clamp(.9rem, 1.8vh, 1.1rem);
  flex-shrink: 0;
  font-weight: 900;
  letter-spacing: .12em;
  color: #1a0533;
  background: linear-gradient(135deg, #ffd84d 0%, #ff9800 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow:
    0 4px 0 #b36a00,
    0 8px 20px rgba(255, 152, 0, .4);
  transition: transform .08s, box-shadow .08s;
  user-select: none;
  -webkit-user-select: none;
}

.spin-btn:hover {
  background: linear-gradient(135deg, #ffe566 0%, #ffaa22 100%);
}

.spin-btn:active,
.spin-btn.holding {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b36a00, 0 4px 10px rgba(255,152,0,.3);
}

.spin-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Result overlay & popup ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .25s ease;
}

.overlay[hidden] { display: none; }

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

.popup {
  background: linear-gradient(145deg, #1e0540 0%, #2d0b6b 100%);
  border: 2px solid #ffd84d;
  border-radius: 24px;
  padding: 48px 56px;
  text-align: center;
  box-shadow: 0 0 0 6px rgba(255,216,77,.15), 0 24px 60px rgba(0,0,0,.7);
  animation: popIn .35s cubic-bezier(.34,1.56,.64,1);
  max-width: 90vw;
}

@keyframes popIn {
  from { transform: scale(.6); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.popup-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: #ffd84d;
  margin-bottom: 16px;
  text-transform: uppercase;
}

.popup-result {
  font-size: 2.4rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px rgba(255,216,77,.6);
  margin-bottom: 32px;
  word-break: break-word;
}

.popup-close {
  padding: 12px 40px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #1a0533;
  background: linear-gradient(135deg, #ffd84d 0%, #ff9800 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b36a00, 0 6px 16px rgba(255,152,0,.4);
  transition: transform .08s;
}

.popup-close:hover  { background: linear-gradient(135deg, #ffe566 0%, #ffaa22 100%); }
.popup-close:active { transform: translateY(2px); box-shadow: 0 2px 0 #b36a00; }

/* ── Edit button (sits just above Reset) ── */
.edit-btn {
  position: fixed;
  bottom: 64px;
  right: 16px;
  padding: 11px 22px;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #ffd84d;
  background: rgba(255, 216, 77, 0.08);
  border: 2px solid rgba(255, 216, 77, 0.45);
  border-radius: 50px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .15s, border-color .15s, transform .08s, color .15s;
  z-index: 50;
}

.edit-btn:hover {
  background: rgba(255, 216, 77, 0.18);
  border-color: #ffd84d;
  color: #fff;
}

.edit-btn:active {
  transform: scale(.95);
}

/* ── Edit popup ── */
.edit-popup {
  width: min(440px, 92vw);
  padding: 32px 32px 28px;
  text-align: left;
}

.edit-sub {
  font-size: .72rem;
  color: rgba(255, 255, 255, .55);
  margin-bottom: 14px;
  word-break: break-all;
}
.edit-sub span { color: #ffd84d; }

.edit-textarea {
  width: 100%;
  height: 220px;
  resize: vertical;
  padding: 12px 14px;
  font-family: 'Consolas', 'Segoe UI', monospace;
  font-size: .95rem;
  line-height: 1.5;
  color: #fff;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 216, 77, .35);
  border-radius: 12px;
  outline: none;
}
.edit-textarea:focus {
  border-color: #ffd84d;
  box-shadow: 0 0 0 3px rgba(255, 216, 77, .15);
}

.edit-status {
  min-height: 1.2em;
  margin-top: 10px;
  font-size: .8rem;
  color: #ff8a8a;
}

.edit-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 14px;
}

.edit-save, .edit-cancel {
  padding: 10px 28px;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .06em;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.edit-save {
  color: #1a0533;
  background: linear-gradient(135deg, #ffd84d 0%, #ff9800 100%);
  box-shadow: 0 4px 0 #b36a00, 0 6px 16px rgba(255, 152, 0, .4);
}
.edit-save:hover  { background: linear-gradient(135deg, #ffe566 0%, #ffaa22 100%); }
.edit-save:active { transform: translateY(2px); box-shadow: 0 2px 0 #b36a00; }
.edit-cancel {
  color: #fff;
  background: rgba(255, 255, 255, .1);
}
.edit-cancel:hover  { background: rgba(255, 255, 255, .18); }
.edit-cancel:active { transform: scale(.96); }

/* ── Reset button ── */
.reset-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  padding: 11px 22px;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #ffd84d;
  background: rgba(255, 216, 77, 0.08);
  border: 2px solid rgba(255, 216, 77, 0.45);
  border-radius: 50px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .15s, border-color .15s, transform .08s, color .15s;
  z-index: 50;
}

.reset-btn:hover {
  background: rgba(255, 216, 77, 0.18);
  border-color: #ffd84d;
  color: #fff;
}

.reset-btn:active {
  transform: scale(.95);
}

/* ── Confetti particles (JS-injected) ── */
.confetti {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 1;
  pointer-events: none;
  z-index: 200;
  animation: fall linear forwards;
}

@keyframes fall {
  0%   { transform: translateY(0) rotate(0deg);   opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
