:root {
  --bg: #f3efff;
  --bg-2: #fff7e6;
  --card: #ffffff;
  --ink: #2b2840;
  --ink-soft: #6b6785;
  --line: #e4def7;
  --primary: #7048e8;
  --primary-dark: #5634c9;
  --primary-soft: #ebe4ff;
  --star: #ffc93c;
  --good: #1c8cf0;
  --bad: #ef3e5c;
  --skin: #f7cdb0;
  --skin-edge: #d7997a;
  --radius: 22px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(1200px 600px at 10% -10%, #fff 0%, transparent 60%), linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
input { -webkit-user-select: text; user-select: text; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }

h1 { font-size: clamp(30px, 4.5vw, 46px); margin: 8px 0 4px; font-weight: 900; letter-spacing: -0.5px; }
h2 { font-size: clamp(22px, 3vw, 30px); margin: 0; font-weight: 800; }
.lead { font-size: clamp(18px, 2.4vw, 23px); color: var(--ink-soft); margin: 4px 0 22px; font-weight: 600; }
.hint { color: var(--ink-soft); font-size: 15px; line-height: 1.45; }

/* ---------- Schermen ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 12px);
}
.screen.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.center-card {
  margin: auto; text-align: center; width: min(560px, 100%);
  display: flex; flex-direction: column; align-items: center;
}
.stack { display: flex; flex-direction: column; gap: 14px; width: min(380px, 100%); }
.stack.row { flex-direction: row; justify-content: center; width: auto; flex-wrap: wrap; }
.bar { display: flex; align-items: center; gap: 12px; padding: 4px 0 16px; max-width: 980px; width: 100%; margin: 0 auto; }
.bar h2 { flex: 1; text-align: center; }
.bar-spacer { width: 52px; }
.corner-tr { position: absolute; top: calc(var(--safe-top) + 14px); right: 16px; }

/* ---------- Mascotte ---------- */
.mascot { display: block; }
.mascot.big { width: 132px; height: 132px; }
.mascot.medium { width: 96px; height: 96px; margin: -70px auto 0; filter: drop-shadow(0 8px 14px rgba(112, 72, 232, .25)); }
.bounce { animation: bounce 2.6s ease-in-out infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }

/* ---------- Knoppen ---------- */
.btn {
  font: inherit; font-weight: 800; font-size: 19px;
  border: 0; border-radius: 999px; padding: 15px 26px; min-height: 56px;
  cursor: pointer; color: var(--ink); background: var(--card);
  box-shadow: 0 2px 0 rgba(43, 40, 64, .08), 0 6px 18px rgba(43, 40, 64, .08);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
}
.btn:active { transform: translateY(2px) scale(.98); box-shadow: 0 1px 0 rgba(43, 40, 64, .08); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark), 0 10px 24px rgba(112, 72, 232, .3); }
.btn-primary:active { box-shadow: 0 2px 0 var(--primary-dark); }
.btn-soft { background: var(--primary-soft); color: var(--primary-dark); box-shadow: none; }
.btn-danger { background: #ffe3e8; color: #b4213b; box-shadow: none; }
.btn-link { background: none; box-shadow: none; color: var(--primary-dark); margin-top: 8px; }
.btn-xl { font-size: 23px; padding: 18px 34px; min-height: 68px; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 16px; border: 0; flex: none;
  background: var(--card); color: var(--ink); font: inherit; font-size: 26px; font-weight: 800;
  box-shadow: 0 2px 10px rgba(43, 40, 64, .08); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.95); }

/* ---------- Welkom ---------- */
.name-form { display: flex; flex-direction: column; gap: 16px; width: min(380px, 100%); }
.name-form input, .field input[type=text] {
  font: inherit; font-size: 24px; font-weight: 700; text-align: center;
  padding: 14px 18px; border-radius: 18px; border: 3px solid var(--line); background: #fff; color: var(--ink);
  outline: none;
}
.name-form input:focus, .field input[type=text]:focus { border-color: var(--primary); }
.total-stars { margin-top: 22px; font-weight: 800; color: var(--ink-soft); font-size: 18px; }

/* ---------- Liedjeslijst ---------- */
.song-list { max-width: 980px; width: 100%; margin: 0 auto; padding-bottom: 24px; }
.level-title { font-size: 17px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .6px; margin: 18px 4px 10px; }
.song-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.song-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 18px 16px;
  box-shadow: 0 3px 0 rgba(43, 40, 64, .05), 0 10px 26px rgba(43, 40, 64, .07);
  display: flex; flex-direction: column; gap: 6px;
}
.song-card h3 { margin: 0; font-size: 21px; font-weight: 800; }
.song-card p { margin: 0; color: var(--ink-soft); font-size: 15px; font-weight: 600; }
.song-stars { display: flex; gap: 14px; margin: 6px 0 8px; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.stars { display: inline-flex; gap: 2px; vertical-align: middle; margin-left: 4px; }
.stars svg { width: 18px; height: 18px; fill: #e6e1f5; }
.stars svg.on { fill: var(--star); }
.song-actions { display: flex; gap: 10px; margin-top: auto; }
.song-actions .btn { flex: 1; font-size: 17px; padding: 12px 10px; min-height: 52px; white-space: nowrap; }

/* ---------- Microfoontest ---------- */
.mic-note {
  width: 190px; height: 190px; border-radius: 50%; display: grid; place-items: center;
  font-size: 92px; font-weight: 900; background: #fff; color: var(--primary);
  box-shadow: 0 10px 30px rgba(112, 72, 232, .18); margin: 6px 0 22px;
  transition: transform .12s;
}
.mic-note.pop { transform: scale(1.1); }
.meter { width: min(360px, 90%); height: 14px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), var(--primary)); transition: width .06s linear; }

/* ---------- Spelen ---------- */
.screen.play { padding: calc(var(--safe-top) + 8px) 0 0; gap: 0; background: var(--bg); }
.play-bar { display: flex; align-items: center; gap: 12px; padding: 0 16px 8px; }
.play-title { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; min-width: 0; }
.play-title span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { background: var(--primary-soft); color: var(--primary-dark); border-radius: 99px; padding: 4px 12px; font-size: 14px; white-space: nowrap; }
.mic-dot { width: 14px; height: 14px; border-radius: 50%; background: #2fbf71; box-shadow: 0 0 0 0 rgba(47, 191, 113, .6); animation: pulse 1.6s infinite; flex: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47, 191, 113, .6); } 100% { box-shadow: 0 0 0 12px rgba(47, 191, 113, 0); } }
.progress { height: 6px; background: var(--line); margin: 0 16px; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); border-radius: 99px; }
.staff-wrap { position: relative; flex: 1; min-height: 180px; margin: 10px 16px 0; background: #fff; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
#staff { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 140px; font-weight: 900; color: var(--primary); pointer-events: none;
  text-shadow: 0 6px 0 var(--primary-soft);
}
.countdown.tick { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(1.4); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.feedback {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 22px; font-weight: 900; color: var(--good); opacity: 0; pointer-events: none;
  transition: opacity .2s; white-space: nowrap;
}
.feedback.show { opacity: 1; animation: rise .9s ease-out; }
.feedback.bad { color: var(--bad); }
@keyframes rise { from { transform: translate(-50%, 8px); } to { transform: translate(-50%, 0); } }
.piano-wrap { margin: 0 16px; background: #fff; border-radius: 0 0 var(--radius) var(--radius); padding: 0 0 calc(var(--safe-bottom)); flex: none; overflow: hidden; }
.piano-svg { display: block; width: 100%; height: auto; touch-action: none; }
.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint { display: block; text-align: center; padding: 8px; font-weight: 700; color: var(--ink-soft); font-size: 15px; }
}

/* Toetsen */
.key rect { stroke: #cfc9e3; stroke-width: 2; transition: fill .12s; }
.key.white rect { fill: #fff; }
.key.black rect { fill: #2b2840; stroke: #1b1928; }
.key-label { font-size: 30px; font-weight: 800; fill: #b3acd0; text-anchor: middle; font-family: var(--font); }
.middle-c-dot { fill: var(--star); }
.key.target.white rect { fill: #d9ccff; }
.key.target.black rect { fill: var(--primary); }
.key.down.white rect { fill: #efeaff; }
.key.flash-good.white rect { fill: #bfe2ff; }
.key.flash-good.black rect { fill: var(--good); }
.key.flash-bad.white rect { fill: #ffd0d8; }
.key.flash-bad.black rect { fill: var(--bad); }
.key-badge { opacity: 0; transition: opacity .15s; pointer-events: none; }
.key.target .key-badge { opacity: 1; }
.key-badge circle { fill: var(--primary); }
.key-badge text { fill: #fff; font-size: 32px; font-weight: 900; text-anchor: middle; font-family: var(--font); }
.key.black .key-badge circle { fill: #fff; }
.key.black .key-badge text { fill: var(--primary); font-size: 26px; }

/* Hand */
.hand { pointer-events: none; }
.palm { fill: var(--skin); }
.palm-outline { fill: var(--skin-edge); transform: translateY(0); stroke: var(--skin-edge); stroke-width: 7; }
.finger { stroke: var(--skin); stroke-linecap: round; }
.finger-outline { stroke: var(--skin-edge); stroke-linecap: round; }
.finger.active { stroke: #c9b6ff; }
.finger-outline.active { stroke: var(--primary); }
.nail { fill: #fde6dc; stroke: #e7b8a3; stroke-width: 2; }
.finger-num circle { fill: #fff; stroke: var(--skin-edge); stroke-width: 3; }
.finger-num text { fill: var(--ink-soft); font-size: 24px; font-weight: 900; text-anchor: middle; font-family: var(--font); }
.finger-num.active circle { fill: var(--primary); stroke: #fff; stroke-width: 4; }
.finger-num.active text { fill: #fff; font-size: 30px; }
.hand .finger.active, .hand .finger-outline.active { animation: tap .9s ease-in-out infinite; }
@keyframes tap { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(6px); } }

/* Overlays */
.overlay { position: absolute; inset: 0; background: rgba(43, 40, 64, .35); display: grid; place-items: center; z-index: 10; padding: 16px; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog { background: #fff; border-radius: 28px; padding: 30px 28px 24px; width: min(460px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; box-shadow: 0 20px 60px rgba(43, 40, 64, .25); }
.dialog.result { padding-top: 40px; margin-top: 50px; }
.result-stars { display: flex; gap: 10px; justify-content: center; }
.result-stars svg { width: 64px; height: 64px; fill: #ece8f7; }
.result-stars svg.on { fill: var(--star); animation: starIn .5s cubic-bezier(.3, 1.6, .5, 1) both; filter: drop-shadow(0 4px 6px rgba(233, 164, 0, .35)); }
.result-stars svg.on:nth-child(2) { animation-delay: .25s; }
.result-stars svg.on:nth-child(3) { animation-delay: .5s; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
.dialog .lead { margin-bottom: 12px; }

/* Instellingen */
.settings { max-width: 640px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 30px; }
.field { display: flex; flex-direction: column; gap: 8px; background: #fff; padding: 14px 16px; border-radius: 18px; font-weight: 800; }
.field input[type=text] { text-align: left; font-size: 20px; }
.field input[type=range] { width: 100%; accent-color: var(--primary); }
.toggle { display: flex; align-items: center; gap: 14px; background: #fff; padding: 16px; border-radius: 18px; font-weight: 800; font-size: 18px; }
.toggle small { display: block; font-weight: 600; color: var(--ink-soft); font-size: 14px; }
.toggle input { appearance: none; -webkit-appearance: none; width: 54px; height: 32px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .15s; }
.toggle input:checked { background: var(--primary); }
.toggle input:checked::after { transform: translateX(22px); }
.segmented { display: flex; gap: 6px; background: var(--bg); padding: 5px; border-radius: 16px; flex-wrap: wrap; }
.segmented button { flex: 1; font: inherit; font-weight: 800; font-size: 16px; border: 0; background: transparent; padding: 11px 10px; border-radius: 12px; color: var(--ink-soft); cursor: pointer; min-height: 46px; }
.segmented button.on { background: #fff; color: var(--primary-dark); box-shadow: 0 2px 8px rgba(43, 40, 64, .1); }

/* Eigen liedjes & importvenster */
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.field-hint { margin: 0 0 6px; font-weight: 600; font-size: 14px; }
.own-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.own-list:empty { display: none; }
.own-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--bg); }
.own-list .own-text { flex: 1; min-width: 0; }
.own-list .own-title { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.own-list .own-sub { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.own-list .btn { min-height: 44px; padding: 8px 14px; font-size: 15px; }
.overlay.fixed { position: fixed; }
.import-dialog { text-align: left; align-items: stretch; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; gap: 14px; }
.import-dialog h2 { text-align: center; }
.form-row { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
.form-row input[type=text], .form-row select {
  font: inherit; font-size: 18px; font-weight: 700; padding: 12px 14px; border-radius: 14px;
  border: 3px solid var(--line); background: #fff; color: var(--ink); width: 100%; outline: none;
}
.form-row select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%); background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
.form-row input:focus, .form-row select:focus { border-color: var(--primary); }
.form-row input[type=range] { accent-color: var(--primary); }
.toggle.compact { padding: 0; background: none; font-size: 17px; }
.imp-stats { margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; font-size: 15px; line-height: 1.5; }
.imp-error { margin: 0; padding: 12px 14px; border-radius: 14px; background: #ffe3e8; color: #b4213b; font-weight: 700; }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.dialog-actions .btn { padding: 12px 18px; font-size: 18px; white-space: nowrap; }
.dialog-actions .bar-spacer { flex: 1; width: auto; }
.song-card .own-badge { align-self: flex-start; font-size: 12px; font-weight: 800; color: var(--primary-dark); background: var(--primary-soft); border-radius: 99px; padding: 2px 10px; }
.empty-own { color: var(--ink-soft); font-weight: 600; margin: 0 4px; }

/* Melding */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 20px; border-radius: 16px; font-weight: 700;
  max-width: min(560px, calc(100% - 32px)); z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .bounce, .hand .finger.active, .hand .finger-outline.active, .mic-dot { animation: none; }
}
