* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #fcf7e6 0%, #f5e6c0 100%);
  touch-action: manipulation;
  user-select: none;
}

#root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------- Top bar ---------------- */

.top-bar {
  display: flex;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 20px 10px;
  gap: 12px;
}

.spacer { flex: 1; }

.mode-toggle {
  display: flex;
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 3px;
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 8px 20px;
  font-size: 15px;
  font-weight: 600;
  color: #7a6a52;
  border-radius: 8px;
  cursor: pointer;
}

.mode-btn.active {
  background: #fff;
  color: #4a3a20;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.restart-btn {
  border: none;
  background: transparent;
  color: #8a5a2a;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.restart-icon { font-size: 18px; }

.pause-btn {
  border: none;
  background: transparent;
  color: #8a5a2a;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}
.pause-icon { font-size: 13px; letter-spacing: 1px; }
.pause-btn.paused {
  background: #ff8c28;
  color: #fff;
  box-shadow: 0 2px 6px rgba(255,140,40,0.35);
}
.pause-btn.paused .pause-icon { letter-spacing: 0; }

.paused-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 36px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(0,0,0,0.06);
  color: #4a3a20;
  font-weight: 800;
  font-size: clamp(28px, 6vw, 52px);
  letter-spacing: 0.02em;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 30;
  pointer-events: none;
  animation: pausedFade 0.2s ease-out both;
}
@keyframes pausedFade {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Clap (microphone) input ---------- */

.clap-calibrate-btn {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
  background: #4a3a20;
  box-shadow: none;
}
.clap-calibrate-btn:hover { background: #3a2d18; }

.clap-calibrate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.clap-calibrate-overlay.open { display: flex; }

.clap-calibrate-panel {
  background: #fff8ec;
  border-radius: 18px;
  padding: 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.clap-calibrate-panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: #4a3a20;
}
.clap-calibrate-panel .hint {
  margin: 0 0 18px;
  color: #8a7a5a;
  font-size: 14px;
  line-height: 1.5;
}

.clap-meter-track {
  position: relative;
  height: 28px;
  border-radius: 14px;
  background: rgba(0,0,0,0.08);
  overflow: hidden;
  margin-bottom: 14px;
}
.clap-meter-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #3fb559, #ffb454, #ff5e5b);
  transition: width 0.05s linear;
  border-radius: 14px;
}
.clap-meter-threshold {
  position: absolute;
  left: 60%;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(0,0,0,0.35);
}

.clap-count-row {
  font-size: 14px;
  font-weight: 600;
  color: #4a3a20;
  margin-bottom: 18px;
}

.clap-cal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.clap-cal-actions .settings-done {
  border: none;
  background: transparent;
  color: #8a7a5a;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  padding: 10px 14px;
}

.clap-live-meter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(70%, 320px);
  height: 10px;
  border-radius: 6px;
  background: rgba(0,0,0,0.08);
  overflow: hidden;
  z-index: 15;
}
.clap-live-meter-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #3fb559, #ffb454);
  transition: width 0.04s linear;
}

.clap-mic-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  color: #8a5a2a;
  font-size: 13px;
  font-weight: 700;
  z-index: 15;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.clap-mic-badge.denied { color: #d94040; }
.clap-mic-badge.pulse-clap { animation: clapBadgePulse 0.25s ease-out; }
@keyframes clapBadgePulse {
  0%   { transform: scale(1); background: rgba(255,255,255,0.9); }
  40%  { transform: scale(1.12); background: #ffe6b8; }
  100% { transform: scale(1); background: rgba(255,255,255,0.9); }
}

/* ---------------- Stage ---------------- */

#stageWrap {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
}

#mascotLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#mascotLayer svg {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

.note-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.note-svg { display: block; overflow: visible; }

.note-head { transition: fill 0.18s ease, stroke 0.18s ease; }
.note-head-filled { fill: #2b2b2b; }
.note-head-open { fill: none; stroke: #2b2b2b; }
.note-stem { fill: #2b2b2b; transition: fill 0.18s ease; }
.note-dot { fill: #2b2b2b; }

.note-slot.highlighted .note-head-filled,
.note-slot.highlighted .note-stem,
.note-slot.highlighted .note-dot { fill: #ff8a2b; }
.note-slot.highlighted .note-head-open { stroke: #ff8a2b; }
.note-slot.highlighted .note-svg { transform-origin: center; animation: pop 0.18s ease; }

.note-slot.completed .note-head-filled,
.note-slot.completed .note-stem,
.note-slot.completed .note-dot { fill: #35b06b; }
.note-slot.completed .note-head-open { stroke: #35b06b; }

@keyframes pop {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

.note-slot.shake .note-svg {
  animation: shakeNote 0.28s ease;
}
@keyframes shakeNote {
  0% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
  100% { transform: translateX(0); }
}

.hint-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pulse-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 55%;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(66, 133, 244, 0.75);
  border-radius: 50%;
  animation: pulseRing 0.7s ease-in-out infinite alternate;
}
@keyframes pulseRing {
  from { transform: translate(-50%, -50%) scale(0.95); opacity: 0.55; }
  to   { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
}

.bounce-arrow {
  position: absolute;
  left: 50%;
  top: -6%;
  transform: translateX(-50%);
  color: #4285f4;
  font-size: 22px;
  animation: bounceArrow 0.45s ease-in-out infinite alternate;
  filter: drop-shadow(0 2px 4px rgba(66,133,244,0.35));
}
@keyframes bounceArrow {
  from { transform: translateX(-50%) translateY(6px); }
  to   { transform: translateX(-50%) translateY(-6px); }
}

/* ---------------- Settings FAB ---------------- */

.settings-fab {
  position: relative;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.7);
  color: rgba(140, 100, 60, 0.85);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  z-index: 5;
}

/* ---------------- Celebration ---------------- */

.celebration {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.celebration.show {
  display: flex;
  opacity: 1;
}

.celebration-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.25);
}

.celebration-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: celebrationIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes celebrationIn {
  from { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.celebration-text {
  font-size: 54px;
  font-weight: 800;
  background: linear-gradient(90deg, #ff8a2b, #ff5fa2, #a259ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 4px rgba(255,255,255,0.5);
}

.sparkle-field {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  animation: sparkleTwinkle 0.6s ease-in-out infinite alternate;
}
@keyframes sparkleTwinkle {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1.2); opacity: 1; }
}

/* ---------------- Settings sheet ---------------- */

.settings-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.settings-sheet.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  background: #fdf9ef;
  width: 100%;
  max-height: 88vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.settings-sheet.open .settings-panel {
  transform: translateY(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.settings-header h2 {
  margin: 0;
  font-size: 19px;
  color: #4a3a20;
}
.settings-done {
  border: none;
  background: transparent;
  color: #ff8a2b;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.settings-body {
  overflow-y: auto;
  padding: 8px 20px 40px;
}

.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.settings-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #a08860;
}
.settings-section.footnote p {
  font-size: 13px;
  color: #8a7a5a;
  line-height: 1.5;
}

.support-section .hint {
  margin: 0 0 12px;
}
.kofi-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: #ff5e5b;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(255, 94, 91, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.kofi-btn:hover,
.kofi-btn:focus-visible {
  background: #ff4b48;
  box-shadow: 0 3px 10px rgba(255, 94, 91, 0.45);
  transform: translateY(-1px);
  outline: none;
}
.kofi-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(255, 94, 91, 0.4);
}
.kofi-cup {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* ---------- Play mode ---------- */

.note-slot.timed-hit .note-head { fill: #3fb559; }
.note-slot.timed-hit .note-head-open { stroke: #3fb559; }
.note-slot.timed-hit .note-stem { fill: #3fb559; }
.note-slot.timed-hit .note-dot { fill: #3fb559; }

.note-slot.timed-miss .note-head { fill: #d94040; }
.note-slot.timed-miss .note-head-open { stroke: #d94040; }
.note-slot.timed-miss .note-stem { fill: #d94040; }
.note-slot.timed-miss .note-dot { fill: #d94040; }

.beat-cursor {
  position: absolute;
  width: 3px;
  background: rgba(255, 140, 40, 0.55);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(255, 140, 40, 0.45);
  pointer-events: none;
  transform: translateX(-1.5px);
  transition: none;
}

.count-in-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(64px, 18vw, 200px);
  font-weight: 800;
  color: #ff8c28;
  text-shadow: 0 6px 18px rgba(255, 140, 40, 0.35);
  pointer-events: none;
  z-index: 20;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.02em;
}
.count-in-overlay.pulse {
  animation: countInPulse 0.35s ease-out both;
}
@keyframes countInPulse {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  40%  { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.0); opacity: 0.9; }
}

.play-score {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(0,0,0,0.06);
  color: #4a3a20;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  z-index: 25;
  animation: scorePop 0.35s ease-out both;
}
@keyframes scorePop {
  0% { transform: translateX(-50%) scale(0.85); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

.segmented-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  font-size: 15px;
  color: #4a3a20;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.row-between label { font-size: 15px; color: #4a3a20; }
.value-pill {
  background: rgba(0,0,0,0.06);
  padding: 2px 10px;
  border-radius: 8px;
  font-weight: 600;
  color: #7a6a52;
}

input[type="range"] { width: 100%; accent-color: #ff8a2b; }

.stepper-input {
  width: 60px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.12);
  text-align: center;
  font-size: 15px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 15px;
  color: #4a3a20;
}
.toggle-row.disabled { color: #b0a48a; }
.toggle-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #ff8a2b;
}

.hint {
  font-size: 12px;
  color: #a08860;
  margin: 6px 0 0;
  line-height: 1.4;
}

/* ---------------- Responsive ---------------- */

@media (min-width: 700px) {
  .settings-sheet { align-items: center; justify-content: center; }
  .settings-panel {
    max-width: 480px;
    border-radius: 20px;
    max-height: 80vh;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
  }
  .settings-sheet.open .settings-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}
