/* Anadolu Piano - rustig, groot en leesbaar naast een piano. */

:root {
  --bg: #0d1016;
  --bg-glow: #15202b;
  --panel: #161c24;
  --panel-2: #1d242e;
  --line: #2a323d;
  --text: #eef2f6;
  --muted: #9aa8b6;
  --accent: #e8a33d; /* koper/amber: de toets die je moet spelen */
  --accent-ink: #2a1c05;
  --ok: #4ec9a0;
  --wrong: #ef6f6c;
  --white-key: #f5f1e9;
  --white-key-ink: #1b222b;
  --black-key: #1b222b;
  --radius: 14px;
  --tap: 48px;
  color-scheme: dark light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f4f1ec;
    --bg-glow: #ffffff;
    --panel: #ffffff;
    --panel-2: #f0ece4;
    --line: #ddd6ca;
    --text: #1b222b;
    --muted: #5e6a76;
    --accent: #b06d10;
    --accent-ink: #fff8ec;
    --ok: #0f7f5e;
    --wrong: #b4322e;
    --black-key: #2b333d;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% -10%, var(--bg-glow), var(--bg) 60%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  font-size: clamp(15px, 1.1vw + 12px, 18px);
  line-height: 1.45;
  padding: 0 16px env(safe-area-inset-bottom, 12px);
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 1100px;
  margin: 0 auto;
}

/* --- kop ---------------------------------------------------------------- */

.topbar {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 10px;
}

.brand {
  flex: 1;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  letter-spacing: 0.02em;
  font-weight: 650;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.lang-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 12px;
  min-height: 36px;
  cursor: pointer;
}

.lang-switch button[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* --- knoppen ------------------------------------------------------------ */

button {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 18px;
  min-height: var(--tap);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

button.ghost {
  background: transparent;
}

button.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 500;
}

button.icon {
  padding: 0;
  width: var(--tap);
  font-size: 1.2rem;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

/* --- bibliotheek -------------------------------------------------------- */

h2 {
  font-size: clamp(1.15rem, 2.5vw, 1.6rem);
  margin: 10px 0 4px;
}

.rights-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 18px;
  max-width: 70ch;
}

.library-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}

.song-card.is-local {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}

.song-card .card-buttons {
  margin-top: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.song-list {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  padding-bottom: 28px;
}

.song-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.song-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.song-card .sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.song-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.chip.level-1 {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

.chip.level-2 {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.chip.level-3 {
  color: var(--wrong);
  border-color: color-mix(in srgb, var(--wrong) 45%, transparent);
}

.song-progress {
  font-size: 0.8rem;
  color: var(--muted);
}

.song-card button {
  margin-top: auto;
  align-self: flex-start;
}

/* --- oefenscherm ------------------------------------------------------- */

.practice-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: space-between;
}

.practice-title h2 {
  margin: 0;
}

.practice-title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.mic-pill {
  cursor: pointer;
  min-height: 0;
  font: inherit;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.mic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.mic-pill[data-state='listening'] .mic-dot {
  background: var(--ok);
  animation: pulse 1.6s infinite;
}

.mic-pill[data-state='error'] .mic-dot {
  background: var(--wrong);
}

.mic-pill[data-state='muted'] .mic-dot,
.mic-pill[data-state='paused'] .mic-dot {
  background: var(--accent);
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.mic-meter {
  display: inline-block;
  width: 56px;
  height: 7px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  flex: none;
}

.mic-meter.wide {
  width: 160px;
  height: 10px;
}

.mic-meter i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ok);
  transition: width 0.08s linear;
}

.mic-note {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 3.5ch;
  text-align: right;
}

.banner {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--wrong) 16%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--wrong) 45%, transparent);
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.stage {
  display: flex;
  gap: 18px;
  align-items: stretch;
  margin: 16px 0 6px;
  flex-wrap: wrap;
}

.note-now {
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 10px 26px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 190px;
  flex: 0 0 auto;
}

.note-now.is-ok {
  border-color: var(--ok);
}

.note-now.is-wrong {
  border-color: var(--wrong);
}

.now-label,
.next-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.now-solfege {
  font-size: clamp(2.6rem, 8vw, 4.4rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.now-octave {
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.note-next {
  flex: 1 1 220px;
  min-width: 0;
}

.now-finger {
  margin-top: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 0.82rem;
  font-weight: 700;
}

.next-finger {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.75;
  text-align: center;
  margin-top: 2px;
}

.note-next ol {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 6px 0 0;
  padding: 0;
  overflow: hidden;
}

.note-next li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: clamp(1rem, 2.2vw, 1.4rem);
  font-weight: 600;
  color: var(--muted);
}

.note-next li:first-child {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.feedback {
  min-height: 1.6em;
  margin: 4px 0 10px;
  font-size: 0.98rem;
  font-weight: 600;
}

.feedback.is-ok {
  color: var(--ok);
}

.feedback.is-wrong {
  color: var(--wrong);
}

.feedback.is-neutral {
  color: var(--muted);
  font-weight: 500;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--ok)));
  transition: width 0.2s ease;
}

.progress-text {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* --- klavier ----------------------------------------------------------- */

/* Notenregen en klavier horen bij elkaar: beide even breed, zodat een
   vallende noot precies boven zijn eigen toets uitkomt. */
.pianoroll {
  margin-top: 34px; /* ruimte voor het vingerrondje boven de doeltoets */
}

.waterfall {
  display: block;
  width: 100%;
  height: clamp(120px, 26vh, 260px);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--accent) 7%, transparent));
  border-radius: 12px 12px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.keyboard {
  position: relative;
  height: clamp(110px, 20vh, 170px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Geen scrollen of inzoomen terwijl je op het klavier speelt. */
  touch-action: none;
}

/* Wijzer boven de toets die je moet spelen. Bij 88 toetsen is een toets smal;
   dit driehoekje maakt hem meteen vindbaar. */
.kb-marker {
  position: absolute;
  top: -28px;
  left: 0;
  transform: translateX(-50%);
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.18s ease;
  z-index: 4;
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}

/* Het pijlpuntje onder het rondje, naar de toets toe. */
.kb-marker::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid var(--accent);
}

/* Zonder vingerzetting blijft het een simpele wijzer. */
.kb-marker:not(.has-finger) {
  min-width: 12px;
  height: 12px;
  padding: 0;
}

.keyboard.kb-roomy {
  height: clamp(150px, 28vh, 240px);
}

.kb-whites {
  display: flex;
  height: 100%;
  gap: 1px;
}

.kb-blacks {
  position: absolute;
  inset: 0 0 38% 0;
  pointer-events: none;
}

.kb-key {
  padding: 0;
  border-radius: 0 0 8px 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  padding-bottom: 8px;
  font-weight: 600;
  transition: background 0.1s ease, box-shadow 0.1s ease;
}

.kb-white {
  flex: 1 1 0;
  min-width: 0;
  background: var(--white-key);
  color: var(--white-key-ink);
  border: 1px solid #c9c2b4;
  border-top: 0;
}

.kb-black {
  position: absolute;
  top: 0;
  height: 100%;
  transform: translateX(-50%);
  background: var(--black-key);
  color: #e9edf2;
  border: 1px solid #000;
  border-top: 0;
  pointer-events: auto;
  z-index: 2;
  font-size: 0.7rem;
  padding-bottom: 5px;
}

/* De letters schalen mee met het aantal toetsen: bij 88 toetsen is een witte
   toets ongeveer 2% breed, dus moet alles een stuk kleiner. */
.kb-label {
  font-size: min(0.8rem, calc(78vw / var(--kb-keys, 15)));
  line-height: 1.1;
  pointer-events: none;
  white-space: nowrap;
}

.kb-black .kb-label {
  font-size: min(0.62rem, calc(54vw / var(--kb-keys, 15)));
  opacity: 0.8;
}

.kb-sub {
  font-size: min(0.6rem, calc(62vw / var(--kb-keys, 15)));
  opacity: 0.45;
  line-height: 1.1;
  pointer-events: none;
}

/* De toets die je moet spelen. Opvallend, ook vanaf een meter afstand. */
.kb-key.is-target {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--accent), 0 0 22px color-mix(in srgb, var(--accent) 60%, transparent);
  z-index: 3;
}

/* De naam op de doeltoets mag buiten de toets uitlopen; de toets zelf is bij
   88 toetsen te smal voor de tekst, en hij ligt bovenop zijn buren. */
.kb-key.is-target .kb-label {
  font-weight: 800;
  font-size: clamp(0.72rem, 1.6vw, 0.95rem);
  overflow: visible;
  text-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 80%, white);
}

.kb-key.is-target .kb-sub {
  opacity: 0.8;
}

.kb-key.is-heard-ok {
  box-shadow: inset 0 0 0 3px var(--ok);
}

.kb-key.is-heard-off {
  box-shadow: inset 0 0 0 3px var(--wrong);
}

.kb-key.is-sounding {
  background: color-mix(in srgb, var(--ok) 55%, var(--white-key));
}

/* Zolang je vinger op de toets staat. */
.kb-key.is-pressed {
  background: color-mix(in srgb, var(--accent) 45%, var(--white-key));
  transform: translateY(1px);
}

.kb-black.is-pressed {
  background: color-mix(in srgb, var(--accent) 55%, var(--black-key));
}

/* --- tempo ------------------------------------------------------------- */

.tempo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type='range'] {
  accent-color: var(--accent);
  width: 130px;
  height: var(--tap);
}

output {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
  min-width: 6ch;
}

/* --- resultaat --------------------------------------------------------- */

.result-song {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.result-message {
  color: var(--muted);
  margin: 4px 0 18px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  max-width: 640px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
}

/* --- dialogen ---------------------------------------------------------- */

dialog.sheet {
  width: min(560px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  max-height: 88dvh;
  overflow: auto;
}

dialog.sheet::backdrop {
  background: rgba(4, 7, 11, 0.72);
}

dialog h3 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

dialog p {
  color: var(--muted);
  margin: 0 0 14px;
  font-size: 0.92rem;
}

.test-rows {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.test-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

.test-detail code {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.test-note {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.test-note.is-live {
  color: var(--ok);
}

.test-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.test-divider::before,
.test-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1.3em;
  margin: 8px 0 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
}

.field.check {
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

.field.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: none;
  margin-top: 2px;
}

.field.check span {
  display: flex;
  flex-direction: column;
}

select {
  font: inherit;
  padding: 10px;
  min-height: var(--tap);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* --- iPhone in liggende stand: alles een maat compacter ---------------- */

@media (orientation: landscape) and (max-height: 520px) {
  body {
    padding-top: 0;
  }
  .topbar {
    padding: 6px 0 2px;
  }
  .tagline,
  .rights-note {
    display: none;
  }
  .stage {
    margin: 8px 0 2px;
    align-items: center;
  }
  .note-now {
    padding: 4px 18px 8px;
    min-width: 150px;
  }
  .now-solfege {
    font-size: 2.4rem;
  }
  .waterfall {
    height: 22dvh;
  }
  .keyboard {
    height: 30dvh;
  }
  .feedback {
    margin: 2px 0 6px;
  }
  .progress-text {
    margin: 4px 0 8px;
  }
  .controls {
    margin-top: 8px;
  }
  button {
    min-height: 42px;
  }
}
