:root {
  --bg: #fff5f8;
  --bg-dot: #ffe6ef;
  --card: #ffffff;
  --ink: #3d2f4a;
  --muted: #8a7a99;
  --pink: #ffb3c9;
  --pink-deep: #f27aa0;
  --lilac: #d9c8ff;
  --mint: #bff0d8;
  --yellow: #fff1b0;
  --right: #3fb57a;
  --right-soft: #dcf7e9;
  --wrong: #ef4c6a;
  --wrong-soft: #ffe0e6;
  --black-key: #4a3b58;
  --shadow: 0 6px 0 rgba(242, 122, 160, 0.18), 0 12px 30px rgba(61, 47, 74, 0.08);
  --radius: 28px;
  font-family: 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  color: var(--ink);
}

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

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 2.5px, transparent 2.5px);
  background-size: 28px 28px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

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

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 0;
  min-height: 60px;
}

.profile-pick select {
  font: inherit;
  font-weight: 800;
  font-size: 20px;
  color: var(--ink);
  background: var(--card);
  border: 3px solid var(--pink);
  border-radius: 999px;
  padding: 4px 34px 4px 16px;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--pink-deep) 50%), linear-gradient(135deg, var(--pink-deep) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

.score { display: flex; gap: 8px; flex: 1; justify-content: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 19px;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(242, 122, 160, 0.18);
}
.pill[hidden] { display: none; }

.top-right { display: flex; align-items: center; gap: 10px; }

.mic-pill { border: 0; font: inherit; font-size: 17px; font-weight: 700; color: var(--ink); cursor: pointer; background: var(--yellow); }
.mic-pill.live { background: var(--mint); }

.sync { width: 12px; height: 12px; border-radius: 50%; background: #ddd; }
.sync[data-status='saved'] { background: var(--right); }
.sync[data-status='saving'] { background: #f5c04a; }
.sync[data-status='offline'] { background: var(--wrong); }

.icon-btn {
  border: 0;
  background: var(--card);
  color: var(--muted);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 rgba(242, 122, 160, 0.18);
  cursor: pointer;
}

/* ---------- staff card + mascot ---------- */

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 12px 16px;
}

.card {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 5px solid transparent;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 10px;
  transition: background-color 0.25s, border-color 0.25s;
}
.card.is-wrong { border-color: var(--wrong); background: var(--wrong-soft); animation: shake 0.45s; }
.card.is-right { border-color: var(--right); background: var(--right-soft); }

.staff { flex: 1; min-height: 0; display: flex; }
.staff svg { width: 100%; height: 100%; }

.feedback {
  min-height: 40px;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  line-height: 40px;
}
.feedback.wrong { color: var(--wrong); }
.feedback.right { color: var(--right); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(4px); }
}

.mascot {
  width: clamp(110px, 16vw, 170px);
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: flex-end;
  padding-bottom: 8px;
}
.mascot-svg { width: 100%; overflow: visible; }
.mascot .m-head { fill: var(--pink); stroke: var(--pink-deep); stroke-width: 3; }
.mascot .m-stem, .mascot .m-flag { fill: var(--lilac); stroke: #b49bf0; stroke-width: 3; }
.mascot .m-shine { fill: #fff; opacity: 0.7; }
.mascot .m-blush { fill: #ff8fb0; opacity: 0.55; }
.mascot .m-eye { fill: var(--ink); }
.mascot .m-glint { fill: #fff; }
.mascot .m-mouth { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.mascot .m-mouth-fill { fill: var(--ink); }
.mascot .m-tear { fill: #8fd3ff; }
.mascot .m-sparkles { fill: #ffc94a; }
.mascot .face { display: none; }
.mascot.idle .face.idle, .mascot.happy .face.happy, .mascot.sad .face.sad, .mascot.hint .face.hint { display: inline; }

.mascot.idle .mascot-svg { animation: bob 2.4s ease-in-out infinite; }
.mascot.happy .mascot-svg { animation: hop 0.5s ease-out 2; }
.mascot.sad .mascot-svg { animation: wobble 0.5s ease-in-out 2; }
.mascot.hint .mascot-svg { animation: lean 1s ease-in-out infinite alternate; }

@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes hop { 40% { transform: translateY(-26px) scale(1.04, 0.96); } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes lean { to { transform: translateY(6px) rotate(-6deg); } }

.bubble {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border-radius: 18px;
  padding: 4px 12px;
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.bubble[hidden] { display: none; }
.mascot.sad .bubble, .mascot.hint .bubble { color: var(--wrong); }
.mascot.happy .bubble { color: var(--right); }

/* ---------- keyboard ---------- */

.keyboard-wrap {
  height: clamp(150px, 34vh, 290px);
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
}

.keyboard {
  position: relative;
  height: 100%;
  background: var(--pink);
  border-radius: 22px 22px 18px 18px;
  padding: 10px 6px 6px;
  box-shadow: var(--shadow);
  touch-action: none;
}
.keyboard .key {
  position: absolute;
  top: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  touch-action: none;
}
.keyboard .key.white {
  height: 100%;
  background: #fff;
  border-radius: 0 0 14px 14px;
  box-shadow: inset -2px 0 0 #f1e3ea, inset 0 -6px 0 #f6e9ef;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 12px;
}
.keyboard .key.black {
  height: 60%;
  background: var(--black-key);
  border-radius: 0 0 10px 10px;
  box-shadow: inset 0 -5px 0 #2f2539;
  z-index: 2;
}
.keyboard .keys { position: relative; height: 100%; }

.keyboard .label { font-weight: 800; font-size: 18px; color: var(--muted); }
.keyboard .middle-c {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--lilac);
  margin-top: 4px;
}

.keyboard .key.white:active { background: #f4eef9; }
.keyboard .key.black:active { background: #6a5880; }

.keyboard .key.right { background: var(--right) !important; box-shadow: none; }
.keyboard .key.right .label { color: #fff; }
.keyboard .key.wrong { background: var(--wrong) !important; box-shadow: none; animation: keyshake 0.35s; }
.keyboard .key.wrong .label { color: #fff; }
.keyboard .key.reveal { animation: glow 0.9s ease-in-out infinite alternate; }
.keyboard .key.white.reveal { background: #c7f3dc; }
.keyboard .key.black.reveal { background: #2f9e67; }

@keyframes glow {
  from { box-shadow: 0 0 0 0 rgba(63, 181, 122, 0.7); }
  to { box-shadow: 0 0 0 8px rgba(63, 181, 122, 0.35); }
}
@keyframes keyshake { 30% { transform: translateX(-3px); } 70% { transform: translateX(3px); } }

/* ---------- settings ---------- */

.settings {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(61, 47, 74, 0.3);
}
.settings::backdrop { background: rgba(61, 47, 74, 0.35); }
.settings-inner { padding: 0 22px 22px; }
.settings-head {
  position: sticky;
  top: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
  z-index: 3;
}
.settings h2 { margin: 0; font-size: 26px; }
.settings h3 { margin: 0 0 8px; font-size: 20px; }

.done-btn, .btn, .chip-btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
}
.done-btn { background: var(--pink-deep); color: #fff; font-size: 20px; padding: 6px 22px; }
.btn { background: var(--lilac); padding: 8px 18px; font-size: 17px; }
.btn:disabled { opacity: 0.5; }
.btn.danger { background: var(--wrong-soft); color: var(--wrong); margin-top: 14px; }

.group { background: var(--card); border-radius: 22px; padding: 16px 18px; margin-top: 14px; }
.hint { color: var(--muted); margin: 0 0 10px; }

.range-label { font-size: 30px; font-weight: 800; display: flex; align-items: baseline; gap: 10px; }
.range-label .arrow { color: var(--pink-deep); }
.range-label small { font-size: 16px; color: var(--muted); margin-left: auto; }

.range-preview { position: relative; height: 54px; margin: 6px 0 2px; }
.range-preview .pk { position: absolute; top: 0; }
.range-preview .pk.w { height: 100%; background: #f3eef5; border: 1px solid #e3d8e8; border-radius: 0 0 5px 5px; }
.range-preview .pk.b { height: 58%; background: #b8aac4; border-radius: 0 0 3px 3px; z-index: 1; }
.range-preview .pk.w.shown { background: #fff; }
.range-preview .pk.w.on { background: var(--pink); border-color: var(--pink-deep); }
.range-preview .pk.b.on { background: var(--pink-deep); }
.range-preview i { position: absolute; bottom: -20px; left: 0; font-size: 12px; font-style: normal; color: var(--muted); white-space: nowrap; }

.dual-range { position: relative; height: 44px; margin-top: 18px; }
.dual-range input {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.dual-range input::-webkit-slider-runnable-track { height: 10px; background: var(--bg-dot); border-radius: 5px; }
.dual-range input:last-child::-webkit-slider-runnable-track { background: transparent; }
.dual-range input::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 40px;
  height: 40px;
  margin-top: -15px;
  border-radius: 50%;
  background: var(--pink-deep);
  border: 5px solid #fff;
  box-shadow: 0 2px 8px rgba(61, 47, 74, 0.25);
  cursor: grab;
}
.dual-range input::-moz-range-thumb {
  pointer-events: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--pink-deep);
  border: 5px solid #fff;
}

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip-btn { background: var(--bg); padding: 6px 14px; font-size: 16px; border: 2px solid var(--bg-dot); }
.chip-btn.active { background: var(--pink); border-color: var(--pink-deep); }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 700; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .sw { width: 54px; height: 32px; border-radius: 999px; background: #e7dcea; position: relative; flex-shrink: 0; transition: background 0.2s; }
.toggle .sw::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.toggle input:checked + .sw { background: var(--right); }
.toggle input:checked + .sw::after { transform: translateX(22px); }

.segmented { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 4px; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: 8px 20px; border-radius: 999px; font-weight: 800; font-size: 18px; cursor: pointer; }
.segmented input:checked + span { background: var(--pink-deep); color: #fff; }

.mic-settings { margin-top: 14px; display: grid; gap: 12px; }
.mic-settings[hidden] { display: none; }
.calib-row, .meter-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.calib-status { color: var(--muted); font-weight: 700; }
.meter { position: relative; flex: 1; min-width: 160px; height: 16px; background: var(--bg-dot); border-radius: 8px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--right)); transition: width 60ms linear; }
.meter-gate { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--pink-deep); }
.heard { font-size: 18px; }
.heard b { display: inline-block; min-width: 40px; }
.slider-row { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.slider-row input { flex: 1; accent-color: var(--pink-deep); }

.progress-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; font-size: 16px; background: #eee; }
.chip .cl { font-size: 20px; line-height: 1; }
.chip small { color: var(--muted); }
.chip.box-1 { background: #f1edf4; }
.chip.box0, .chip.box1 { background: var(--wrong-soft); }
.chip.box2, .chip.box3 { background: var(--yellow); }
.chip.box4, .chip.box5 { background: var(--mint); }
.chip.off { opacity: 0.45; }

/* ---------- smaller / portrait screens ---------- */

@media (max-width: 700px) {
  .score .streak { display: none; }
  .profile-pick select { font-size: 17px; }
  .toggles { grid-template-columns: 1fr; }
  .mascot { width: 90px; }
}
@media (orientation: portrait) and (min-width: 701px) {
  .keyboard-wrap { height: clamp(180px, 28vh, 320px); }
}
