/* =====================================================================
   Blattspiel-Trainer · app.css
   Kommt NACH design/site.css und nutzt nur Tokens. Neue Farben stehen als
   Tokens in allen drei Blöcken (hell, dunkel per System, dunkel erzwungen).
   ===================================================================== */

/* ================================================================ Tokens */
:root {
  /* Notenpapier bleibt immer hell */
  --paper: #ffffff; --paper-ink: #000000; --paper-edge: #d9d6cf; --paper-shadow: 0 1px 3px rgba(0,0,0,.12);
  /* Taktmarkierung auf dem Papier */
  --measure-hl: rgba(0,136,204,.10); --measure-hl-edge: rgba(0,136,204,.45);
  /* Übungsansicht */
  --practice-bg: #ebebeb; --practice-bar: #f5f5f5;
  /* Diagramme (mit dem dataviz-Validator gegen die Well-Fläche geprüft) */
  --chart-bar: #0088cc; --chart-good: #1b7f5c; --chart-mid: #eda100; --chart-bad: #c2352b;
  --chart-grid: #e3e3e3; --chart-goal: #555555; --meter-track: #e3e3e3; --tip-bg: #333333; --tip-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #ffffff; --paper-ink: #000000; --paper-edge: #000000; --paper-shadow: 0 1px 6px rgba(0,0,0,.6);
    --measure-hl: rgba(0,136,204,.12); --measure-hl-edge: rgba(0,136,204,.5);
    --practice-bg: #141414; --practice-bar: #1f1f1f;
    --chart-bar: #3fa9e8; --chart-good: #2fa37a; --chart-mid: #bb8700; --chart-bad: #d9486e;
    --chart-grid: #333333; --chart-goal: #b5b5b5; --meter-track: #333333; --tip-bg: #e6e6e6; --tip-text: #1a1a1a;
  }
}
:root[data-theme="dark"] {
  --paper: #ffffff; --paper-ink: #000000; --paper-edge: #000000; --paper-shadow: 0 1px 6px rgba(0,0,0,.6);
  --measure-hl: rgba(0,136,204,.12); --measure-hl-edge: rgba(0,136,204,.5);
  --practice-bg: #141414; --practice-bar: #1f1f1f;
  --chart-bar: #3fa9e8; --chart-good: #2fa37a; --chart-mid: #bb8700; --chart-bad: #d9486e;
  --chart-grid: #333333; --chart-goal: #b5b5b5; --meter-track: #333333; --tip-bg: #e6e6e6; --tip-text: #1a1a1a;
}

/* ======================================================== Navbar schmal */
/* Marke, Umschalter und Menü-Knopf bleiben immer in einer Zeile */
@media (max-width: 939px) {
  .navbar .btn-group .txt { display: none; }     /* nur Symbole */
}
@media (max-width: 767px) {
  .brand { margin-right: 10px; }
  .nav a { display: flex; align-items: center; min-height: 44px; }
}
@media (max-width: 479px) {
  .brand b { display: none; }                    /* „sheetmusic“ ohne Domain-Zusatz */
}
@media (max-width: 359px) {
  .brand { font-size: 18px; margin-right: 6px; }  /* 320-px-Geräte (iPhone SE 1. Gen.) */
  .nav-end > * + * { margin-left: 4px; }
}
/* Touch: Knöpfe der Navbar mind. 44 × 44 px Trefferfläche (18 px + 2 × 13 px), ohne die Optik zu ändern */
@media (pointer: coarse) {
  .navbar .btn-group .btn, .navbar .nav-toggle { position: relative; min-width: 44px; }
  .navbar .btn-group .btn::after, .navbar .nav-toggle::after {
    content: ""; position: absolute; left: 0; right: 0; top: -13px; bottom: -13px;
  }
}

/* ============================================================ Allgemein */
/* Tastatur-Hinweise nur, wo es (wahrscheinlich) eine Tastatur gibt */
@media (hover: none) and (pointer: coarse) { .kbd-hint { display: none; } }
.btn-touch { min-height: 44px; min-width: 44px; }
.btn-large.btn-touch { min-height: 52px; }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.meta-line { color: var(--ink-muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; font-weight: bold; }

/* ======================================================== Übungsansicht */
/* Während des Übens: Navbar und Footer weg, volle Fläche für die Noten */
body.is-practice { background: var(--practice-bg); }
body.is-practice .navbar,
body.is-practice .site-footer { display: none; }
body.is-practice main.container { max-width: none; padding: 0; }

.practice {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.pbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--practice-bar); border-bottom: 1px solid var(--nav-border);
}
.pbar .pinfo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: 15px; }
.pbar .pinfo b { color: var(--ink); }
.pbar .btn-group { margin-left: auto; }
.pbar .btn-group .btn { min-width: 44px; min-height: 44px; }

.score-scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px 24px; scroll-behavior: smooth;
}
.paper {
  background: var(--paper); color: var(--paper-ink);
  border: 1px solid var(--paper-edge); border-radius: 3px; box-shadow: var(--paper-shadow);
  padding: 10px 6px; min-height: 120px;
}
.paper svg { display: block; max-width: 100%; }
.paper .abcjs-container { display: block; }
/* abcjs zeichnet mit currentColor – Papier-Tinte erzwingen */
.paper svg path, .paper svg text { fill: var(--paper-ink); }
.paper svg [stroke]:not([stroke="none"]) { stroke: var(--paper-ink); }

/* Takt-Zustände (Schritt 2: Markieren, Ausblenden, Vorschaufenster) */
.paper .measure-hidden { opacity: 0; transition: opacity .25s ease-out; }

.pfoot {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--practice-bar);
  border-top: 1px solid var(--nav-border);
}

@media (max-width: 520px) {
  .pbar { padding: 4px 6px; gap: 6px; }
  .pbar .pinfo { font-size: 13px; }
  .score-scroll { padding: 8px 6px 16px; }
  .paper { padding: 6px 2px; }
}

/* ============================================================ Ablauf */
.pstate { flex: none; padding: 4px 7px; font-size: 12px; line-height: 16px; }
.pstate-preview { background: #3a87ad; }
.pstate-countin { background: #f89406; }
.pstate-play { background: #468847; }
.pstate-rate, .pstate-review { background: #0088cc; }
.pstate-aborted { background: #b94a48; }

/* Schlag-Anzeige (sichtbares Metronom) */
.beats { flex: none; display: flex; align-items: center; gap: 6px; padding: 0 4px; }
.beat { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-border); transition: background .05s; }
.beat-accent { width: 14px; height: 14px; }
.beat.on { background: var(--link); }
.beat-accent.on { background: var(--ok-text); }

/* Merkzettel in der Vorschau */
.cheat { margin: 0 0 10px; padding: 8px 14px; background: var(--info-bg); border: 1px solid var(--info-border); border-radius: var(--radius); color: var(--info-text); }
.cheat-list { display: flex; flex-wrap: wrap; gap: 6px 26px; margin: 0; }
.cheat-list div { display: flex; align-items: baseline; gap: 8px; }
.cheat-list dt { font-size: 11px; font-weight: bold; text-transform: uppercase; letter-spacing: .06em; }
.cheat-list dd { margin: 0; font-size: 17.5px; font-weight: bold; }
.cheat-list small { font-weight: normal; font-size: 13px; }

/* Takt-Markierung im SVG */
.paper .measure-hl { fill: var(--measure-hl); stroke: var(--measure-hl-edge); stroke-width: 1; }

/* Fußleiste je Zustand */
.foot-hint { color: var(--ink-muted); font-size: 13px; flex: 1 1 220px; }
.play-msg { font-size: 21px; font-weight: bold; color: var(--ink); min-width: 190px; }
.practice[data-state="countin"] .pfoot, .practice[data-state="play"] .pfoot { justify-content: flex-start; min-height: 72px; }
.btn-start .countdown { font-variant-numeric: tabular-nums; opacity: .85; }

.rate-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; max-width: 900px; }
.btn-rate { white-space: normal; min-height: 64px; line-height: 1.25; text-align: center; }
.btn-rate[aria-disabled="true"] { opacity: .55; }

.review { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips-label { color: var(--ink-muted); font-size: 13px; margin-right: 4px; flex-basis: 100%; }
.chip-btn { border-radius: 22px; padding: 4px 12px; }
.chip-btn[aria-pressed="true"] { color: #fff; text-shadow: 0 -1px 0 rgba(0,0,0,.25); background: linear-gradient(#f0ad4e, #f89406); border-color: #f89406 #f89406 #ad6704; }
.tips { margin: 0 0 10px; padding: 8px 14px; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius); color: var(--warn-text); }
.tips p { margin: 4px 0; }
.review-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; }
.dlg:focus { outline: none; }

/* ✕ gedrückt halten: Fortschritt als Füllung */
.btn-hold { position: relative; overflow: hidden; }
.btn-hold::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: var(--danger-ring);
}
.btn-hold.is-holding::before { width: 100%; transition: width .8s linear; }
.btn-hold svg { position: relative; }

/* Dialog */
.dlg {
  max-width: min(520px, calc(100vw - 32px)); padding: 20px; color: var(--ink);
  background: var(--page); border: 1px solid var(--surface-border); border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.dlg::backdrop { background: rgba(0,0,0,.5); }
.dlg-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* Einstellungen */
.settings .well > .btn { margin-top: 12px; }
.settings .well h4 { margin-bottom: 14px; }

@media (max-width: 767px) {
  .pbar .pinfo { display: none; }
  .beats { flex: 1; justify-content: center; }
  .rate-grid { grid-template-columns: 1fr; gap: 8px; }
  .btn-rate { min-height: 52px; }
  .play-msg { font-size: 17.5px; min-width: 0; }
  .review { grid-template-columns: 1fr; }
  .chips-label { flex-basis: auto; }
  .review-actions .btn { flex: 1; }
  .foot-hint { flex-basis: 100%; }
}
@media (min-width: 768px) {
  .pbar .pinfo { display: block; }
}

/* Touch: Trefferflächen der Formular-Bausteine (Optik bleibt wie im Design) */
@media (pointer: coarse) {
  .stepper .step { position: relative; }
  .stepper .step::after { content: ""; position: absolute; left: -5px; right: -5px; top: -5px; bottom: -5px; }
  .check { min-height: 44px; }
  .check input { width: 22px; height: 22px; }
}

/* Daten & Sicherung */
.storage-status { margin-bottom: 14px; }
.data-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.file-btn { cursor: pointer; }
.file-btn:focus-within { box-shadow: 0 0 0 3px var(--ring); }

/* Hinweise auf der Startseite */
.notice { margin: 0 0 20px; }
.notice-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.notice-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============================================================ Startseite */
.level-title { font-size: 17.5px; font-weight: bold; margin: 0 0 14px; }
.meter { height: 10px; background: var(--meter-track); border-radius: 5px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.1); }
.meter-fill { height: 100%; background: var(--chart-bar); border-radius: 5px; transition: width .3s ease-out; }
.meter-done .meter-fill { background: var(--chart-good); }
.today-line { margin: 12px 0 0; }
.level-pick { margin-top: 14px; }
.level-pick summary { cursor: pointer; color: var(--link); min-height: 32px; display: flex; align-items: center; }
.level-pick .form-group { margin-top: 8px; }
.pnotice { margin: 0 0 10px; }

/* ============================================================ Statistik */
.stats-page { position: relative; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin-bottom: 10px; }
.kpi .big { margin-top: 4px; }
.kpi .big b { font-size: 44px; }
.chart-box { margin: 0; padding: 14px 16px; }
.chart-title { margin: 0 0 8px; font-size: 13px; font-weight: bold; color: var(--ink-soft); }
.chart-wrap { width: 100%; min-height: 60px; }
.chart { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-base { stroke: var(--ink-muted); stroke-width: 1; }
.chart-axis { fill: var(--ink-muted); font-family: var(--font); }
.chart-bar { fill: var(--chart-bar); }
.chart-line { fill: none; stroke: var(--chart-bar); stroke-width: 2; stroke-linejoin: round; }
.chart-dot { fill: var(--chart-bar); stroke: var(--well); stroke-width: 2; }
.chart-goal { stroke: var(--chart-goal); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-goal-label { fill: var(--ink-soft); font-family: var(--font); }
.chart-hit { fill: transparent; cursor: default; }
.chart-hit.is-hover { fill: var(--nav-active); }
.chart-clean, .swatch.chart-clean { fill: var(--chart-good); background: var(--chart-good); }
.chart-errors, .swatch.chart-errors { fill: var(--chart-mid); background: var(--chart-mid); }
.chart-stuck, .swatch.chart-stuck { fill: var(--chart-bad); background: var(--chart-bad); }
.chart-seg.is-hover { opacity: .8; }
.chart-empty { fill: var(--meter-track); }
.dist + .dist { margin-top: 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 260px; padding: 5px 9px;
  font-size: 13px; line-height: 18px; color: var(--tip-text); background: var(--tip-bg); border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.table-view { margin-top: 12px; }
.table-view summary { cursor: pointer; color: var(--link); min-height: 32px; display: flex; align-items: center; }
.weak-table .is-weak td:first-child { font-weight: bold; }
.rate { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rate-bar { display: inline-block; width: 80px; height: 8px; background: var(--meter-track); border-radius: 4px; overflow: hidden; }
.rate-bar span { display: block; height: 100%; background: var(--chart-bar); }
.is-weak .rate-bar span { background: var(--chart-bad); }
@media (max-width: 767px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi .big b { font-size: 36px; }
  .rate-bar { width: 48px; }
  .weak-table .col-last { display: none; }
}

/* Update-Hinweis (Service Worker) */
.update-bar {
  position: fixed; z-index: 30; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; margin: 0; max-width: calc(100vw - 32px);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
