:root {
  --bg-top: #fff2cf;
  --bg-bottom: #ffd9a0;
  --orange: #ff9f43;
  --orange-dark: #e6752a;
  --green: #3ecf6b;
  --green-dark: #27ae60;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --blue: #29b6f6;
  --blue-dark: #0277bd;
  --purple: #ab47bc;
  --purple-dark: #7b1fa2;
  --pink: #ff6fa5;
  --pink-dark: #d81b60;
  --ink: #3a2e2a;
  --card-bg: #ffffff;
  --card-shadow: 0 7px 0 rgba(0, 0, 0, 0.1);
  --radius: 26px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

h1 {
  font-size: clamp(30px, 4.5vw, 44px);
  margin: 0 0 4px;
}

h2 {
  font-size: clamp(24px, 3.5vw, 30px);
  margin: 0 0 2px;
}

/* ---------------------------------------------------------------- Home */

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 30px;
}

.home-header h1 {
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.6);
}

.group {
  margin-bottom: 40px;
}

.group.group-toene h2 {
  color: var(--blue-dark);
}
.group.group-uebungen h2 {
  color: var(--purple-dark);
}
.group.group-lieder h2 {
  color: var(--pink-dark);
}

.group-subtitle {
  margin: 0 0 18px;
  opacity: 0.75;
  font-weight: 600;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 16px;
}

.lesson-card {
  position: relative;
  background: var(--card-bg);
  border: 4px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 22px 14px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 700;
  transition: transform 0.12s ease;
}

.lesson-card.group-toene {
  border-color: var(--blue);
  background: linear-gradient(165deg, #eaf8ff, #ffffff 65%);
}
.lesson-card.group-uebungen {
  border-color: var(--purple);
  background: linear-gradient(165deg, #f6ebff, #ffffff 65%);
}
.lesson-card.group-lieder {
  border-color: var(--pink);
  background: linear-gradient(165deg, #ffecf3, #ffffff 65%);
}

.lesson-card .card-icon {
  font-size: 46px;
  line-height: 1;
}

.lesson-card .card-title {
  text-align: center;
}

.lesson-card:not(:disabled):active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.lesson-card.locked {
  opacity: 0.5;
  background: #efe9e3;
  border-color: #d8d0c6;
  filter: grayscale(0.4);
}

.lesson-card .lock {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 20px;
}

.card-stars {
  font-size: 17px;
}

.ghost-btn {
  background: transparent;
  border: 3px solid var(--orange);
  color: var(--orange-dark);
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 800;
  font-size: 17px;
}

.ghost-btn:active {
  transform: translateY(3px);
}

/* -------------------------------------------------------------- Lektion */

.lesson-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.back-btn {
  background: var(--card-bg);
  border: 3px solid var(--orange);
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 800;
  font-size: 17px;
  box-shadow: var(--card-shadow);
  color: var(--orange-dark);
}

.back-btn:active {
  transform: translateY(4px);
  box-shadow: none;
}

.sequence-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  margin-bottom: 22px;
}

.note-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 12px 8px;
  border-radius: 18px;
  background: #f4efe9;
  font-weight: 800;
  transition: background 0.15s, transform 0.15s;
  border: 3px solid transparent;
}

.note-chip .chip-note {
  font-size: 26px;
}

.note-chip .chip-lyric {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

.note-chip.current {
  background: var(--yellow);
  border-color: var(--orange-dark);
  transform: scale(1.15);
}

.note-chip.done {
  background: var(--green);
  border-color: var(--green-dark);
  color: white;
}

.note-chip {
  cursor: pointer;
}

.ghost-btn.on {
  background: var(--green);
  border-color: var(--green-dark);
  color: white;
}

.lesson-top .auto-toggle {
  margin-left: auto;
}

.auto-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 14px 22px;
  margin-bottom: 20px;
  background: #e8f9ee;
  border: 4px solid var(--green);
  border-radius: var(--radius);
  font-size: 22px;
  font-weight: 800;
  color: var(--green-dark);
}

.completion-card .auto-countdown {
  font-size: 18px;
  color: var(--green-dark);
}

.note-chip.shown:not(.current):not(.done) {
  border-color: var(--blue);
  background: #eaf8ff;
}

.header-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------- Griffbild */

.fingering-panel {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 20px 24px;
  margin-bottom: 22px;
  background: var(--card-bg);
  border: 4px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}

.fingering-svg {
  flex: 0 0 auto;
  width: 170px;
}

.fingering-svg svg {
  display: block;
  width: 100%;
  height: auto;
}

.fingering-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fingering-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--blue-dark);
}

.fingering-note {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  color: var(--orange-dark);
}

.fingering-closed {
  font-size: 22px;
  font-weight: 800;
}

.fingering-tip {
  font-size: 19px;
  font-weight: 700;
  opacity: 0.85;
}

.fingering-legend {
  display: flex;
  gap: 18px;
  font-weight: 700;
  font-size: 16px;
}

.fingering-legend .dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  vertical-align: -3px;
  margin-right: 4px;
  border: 3px solid #8d6e63;
}

.fingering-legend .dot.closed {
  background: var(--blue);
  border-color: rgba(0, 0, 0, 0.35);
}

.fingering-legend .dot.open {
  background: #fff;
}

.fingering-system {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.55;
}

@media (max-width: 480px) {
  .fingering-panel {
    flex-direction: column;
    text-align: center;
  }
  .fingering-legend {
    justify-content: center;
  }
}

.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.big-btn {
  border: none;
  border-radius: 999px;
  padding: 22px 30px;
  font-size: 23px;
  font-weight: 800;
  box-shadow: var(--card-shadow);
  flex: 1;
  min-width: 170px;
}

.big-btn.primary {
  background: linear-gradient(180deg, #ffb85e, var(--orange));
  color: white;
}

.big-btn.secondary {
  background: var(--card-bg);
  color: var(--ink);
  border: 3px solid var(--orange);
}

.big-btn:active {
  transform: translateY(5px);
  box-shadow: none;
}

.big-btn:disabled {
  opacity: 0.5;
}

/* ----------------------------------------------------------------- Meter */

.meter {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 26px;
  text-align: center;
}

.meter-detected {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 16px;
}

.meter-bar {
  position: relative;
  height: 32px;
  border-radius: 999px;
  background: #f0ece6;
  margin-bottom: 20px;
  overflow: hidden;
  border: 2px solid #e4ddd3;
}

.meter-zone-good {
  position: absolute;
  left: 30%; /* ±40 Cent Toleranz bei ±100 Cent Skala */
  width: 40%;
  height: 100%;
  background: rgba(46, 204, 113, 0.3);
  border-left: 3px dashed var(--green-dark);
  border-right: 3px dashed var(--green-dark);
}

.meter-needle {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 14px;
  margin-left: -7px;
  border-radius: 999px;
  background: #b0a89f;
  transition: left 0.15s ease-out, background 0.15s;
}

.meter-needle.good {
  background: var(--green-dark);
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.3);
}

.meter-needle.okay {
  background: var(--yellow);
}

.meter-needle.bad {
  background: var(--red);
}

.progress-track {
  height: 20px;
  border-radius: 999px;
  background: #f0ece6;
  overflow: hidden;
  margin-bottom: 16px;
  border: 2px solid #e4ddd3;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green-dark), var(--green));
  transition: width 0.08s linear;
}

.hint {
  font-size: 20px;
  font-weight: 800;
  min-height: 26px;
  margin: 0 0 16px;
}

.mic-error {
  margin-top: 18px;
  padding: 16px 20px;
  background: #ffe9e9;
  border: 3px solid var(--red);
  border-radius: 16px;
  font-weight: 700;
  font-size: 17px;
}

/* ------------------------------------------------------------- Completion */

.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.completion-card {
  background: var(--card-bg);
  border-radius: 32px;
  padding: 40px 30px;
  text-align: center;
  max-width: 380px;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.15);
  border: 5px solid var(--yellow);
}

.stars-big {
  font-size: 56px;
  margin-bottom: 12px;
}

.completion-card p {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 24px;
}

.completion-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ----------------------------------------------------------- Mikrofon-Check */

.mic-check {
  text-align: center;
}

.mic-check h1::before {
  content: '';
}

.mic-check p {
  max-width: 500px;
  margin: 14px auto 26px;
  font-size: 18px;
  font-weight: 600;
}

.big-note {
  font-size: 72px;
  font-weight: 800;
  color: var(--blue-dark);
}

.big-freq {
  font-size: 22px;
  opacity: 0.75;
  margin-bottom: 22px;
  font-weight: 700;
}

.volume-track {
  max-width: 340px;
  margin: 0 auto;
  height: 22px;
  border-radius: 999px;
  background: #f0ece6;
  overflow: hidden;
  border: 2px solid #e4ddd3;
}

.volume-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--orange-dark), var(--orange));
  transition: width 0.08s linear;
}

@media (max-width: 480px) {
  .controls {
    flex-direction: column;
  }
  .big-btn {
    min-width: 0;
  }
}

/* --------------------------------------------------------- Layout Lektion */

.lesson-body {
  display: flex;
  flex-direction: column;
}

.lesson-main {
  display: contents;
}

.lesson-main .sequence-strip { order: 0; }
.fingering-panel { order: 1; }
.lesson-main .controls { order: 2; }
.lesson-main .meter { order: 3; }
.lesson-main .mic-error { order: 4; }

.completion-card {
  max-height: 100vh;
  overflow-y: auto;
}

/* Querformat: Noten/Steuerung links, Griffbild rechts, alles ohne Scrollen */
@media (orientation: landscape) and (min-width: 700px) {
  #app {
    max-width: 1400px;
    padding: 12px 24px 16px;
  }

  .lesson-top {
    margin-bottom: 10px;
    gap: 12px;
  }

  .lesson-top h1 {
    font-size: clamp(24px, 3.5vh, 34px);
    margin: 0;
  }

  .back-btn,
  .lesson-top .ghost-btn {
    padding: 8px 16px;
    font-size: 16px;
  }

  .auto-banner {
    padding: 8px 18px;
    margin-bottom: 10px;
    font-size: 19px;
  }

  .lesson-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 40%);
    gap: 18px;
    align-items: start;
  }

  .lesson-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .lesson-main .sequence-strip,
  .lesson-main .controls,
  .lesson-main .meter,
  .lesson-main .mic-error,
  .fingering-panel {
    order: 0;
  }

  .sequence-strip {
    gap: 8px;
    padding: 12px;
    margin-bottom: 14px;
  }

  .note-chip {
    min-width: 50px;
    padding: 6px 6px;
    border-radius: 14px;
  }

  .note-chip .chip-note {
    font-size: 22px;
  }

  .note-chip .chip-lyric {
    font-size: 11px;
  }

  .controls {
    margin-bottom: 14px;
    gap: 12px;
  }

  .big-btn {
    padding: 14px 20px;
    font-size: 20px;
  }

  .meter {
    padding: 14px 18px;
  }

  .meter-detected {
    font-size: 24px;
    margin-bottom: 8px;
  }

  .meter-bar {
    height: 24px;
    margin-bottom: 12px;
  }

  .progress-track {
    height: 16px;
    margin-bottom: 10px;
  }

  .hint {
    font-size: 17px;
    min-height: 0;
    margin-bottom: 10px;
  }

  .fingering-panel {
    margin-bottom: 0;
    padding: 12px 16px;
    gap: 14px;
    position: sticky;
    top: 12px;
  }

  .fingering-svg {
    width: min(150px, calc((100vh - 130px) * 0.54));
  }

  .fingering-note {
    font-size: 48px;
  }

  .fingering-closed {
    font-size: 18px;
  }

  .fingering-tip {
    font-size: 16px;
  }

  .fingering-legend {
    font-size: 14px;
  }

  .stars-big {
    font-size: 44px;
    margin-bottom: 6px;
  }

  .completion-card {
    padding: 20px 26px;
  }

  .completion-card p {
    font-size: 19px;
    margin-bottom: 12px;
  }

  .completion-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .completion-actions .big-btn {
    min-width: 0;
    padding: 12px 18px;
    font-size: 18px;
  }

  .completion-card {
    max-width: 640px;
  }

  /* Startseite: Titel kompakter */
  .home-header {
    margin-bottom: 18px;
  }

  .group {
    margin-bottom: 26px;
  }
}

@media (orientation: landscape) and (min-width: 700px) and (max-height: 640px) {
  .sequence-strip {
    gap: 6px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }
  .note-chip {
    min-width: 40px;
    padding: 3px 4px;
  }
  .note-chip .chip-note {
    font-size: 18px;
  }
  .note-chip.current {
    transform: scale(1.08);
  }
  .controls {
    margin-bottom: 10px;
  }
  .big-btn {
    padding: 10px 16px;
    font-size: 18px;
  }
  .meter {
    padding: 10px 16px;
  }
  .meter-detected {
    font-size: 20px;
    margin-bottom: 6px;
  }
  .meter-bar {
    height: 20px;
    margin-bottom: 8px;
  }
  .hint {
    margin-bottom: 6px;
  }
  .meter .ghost-btn {
    padding: 6px 16px;
    font-size: 15px;
  }
}

/* ------------------------------------------------- Fehleranzeige Griffbild */

.fingering-mistake {
  padding: 8px 12px;
  background: #ffe9e9;
  border: 3px solid #e53935;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 800;
  color: #b71c1c;
}

.fingering-legend .dot.wrong {
  background: #fff;
  border-color: #e53935;
}

.wrong-ring {
  animation: wrong-pulse 0.9s ease-in-out infinite;
}

@keyframes wrong-pulse {
  50% {
    opacity: 0.3;
  }
}

.mc-fingering {
  width: 150px;
  margin: 20px auto 0;
}

.mc-fingering svg {
  display: block;
  width: 100%;
  height: auto;
}

@media (orientation: landscape) and (min-width: 700px) and (max-height: 640px) {
  .fingering-mistake {
    font-size: 15px;
    padding: 5px 10px;
  }
}

.fingering-legend {
  flex-wrap: wrap;
  gap: 6px 14px;
}

.fingering-legend span {
  white-space: nowrap;
}
