:root {
  --bg: #f6f1e9;
  --fg: #2b2620;
  --muted: #8a8174;
  --surface: #ffffff;
  --line: rgba(60, 50, 30, .14);
  --accent: #b5532a;
  --green: #2e9b57;
  --red: #d64545;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f; --fg: #f1ece3; --muted: #9a9183;
    --surface: #26231c; --line: rgba(255, 245, 225, .16);
    --accent: #e08a5c;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body {
  height: 100dvh; display: flex; flex-direction: column;
  padding: 0 var(--sal) 0 var(--sar);
  padding-left: var(--sal); padding-right: var(--sar);
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

/* Header */
#topbar {
  flex: none; display: flex; align-items: center; gap: 12px;
  padding: calc(var(--sat) + 8px) 16px 8px;
  min-height: calc(var(--sat) + 56px);
}
.tb-instrument { font-weight: 700; font-size: 20px; letter-spacing: -.01em; flex: 1; }
.tb-progress { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }
.pg-count { color: var(--fg); font-weight: 600; }
.pg-right, .pg-wrong { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.pg-right { color: var(--green); } .pg-right::before { content: "✓"; }
.pg-wrong { color: var(--red); } .pg-wrong::before { content: "✗"; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; color: var(--fg); margin-right: -8px;
}
.icon-btn:active { background: var(--line); }

/* Stage */
#card-stage {
  flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column;
  padding: 8px 18px calc(var(--sab) + 84px);
}
#card-stage.done-mode { justify-content: center; align-items: center; }

/* Sound button */
#sound-btn {
  position: fixed; right: calc(var(--sar) + 18px); bottom: calc(var(--sab) + 18px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25); z-index: 20;
  transition: transform .15s;
}
#sound-btn[hidden] { display: none; }
#sound-btn:active { transform: scale(.92); }

/* Buttons */
.btn {
  display: block; width: 100%; min-height: 50px; padding: 12px 20px; border: 0; border-radius: 14px;
  font-size: 17px; font-weight: 600; background: var(--surface); color: var(--fg);
  box-shadow: 0 0 0 1px var(--line) inset;
}
.btn:active { opacity: .7; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: none; }
.btn.danger { color: var(--red); }

/* Done screen */
.done { text-align: center; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.done-emoji { font-size: 56px; line-height: 1; }
.done h1 { margin: 0; font-size: 32px; letter-spacing: -.02em; }
.done-sub, .done-hint { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; margin: 8px 0; }
.stats div { background: var(--surface); border-radius: 14px; padding: 12px 4px; box-shadow: 0 0 0 1px var(--line) inset; }
.stats b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.done .btn { margin-top: 6px; }

/* Settings sheet */
.sheet-root { position: fixed; inset: 0; z-index: 100; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0; transition: opacity .28s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(var(--sab) + 18px);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
.sheet-root.open .backdrop { opacity: 1; }
.sheet-root.open .sheet { transform: none; }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-title { margin: 0 0 12px; font-size: 22px; text-align: center; }
.group { margin-bottom: 18px; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 4px 6px; }
.hint { margin: 6px 4px 0; font-size: 13px; color: var(--muted); }
.help { margin: 0; padding: 12px 16px 12px 32px; background: var(--surface); border-radius: 14px; font-size: 15px; box-shadow: 0 0 0 1px var(--line) inset; }
.help li { margin: 3px 0; }

.segmented { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--line); }
.seg-btn { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 16px; font-weight: 500; transition: background .2s, box-shadow .2s; }
.seg-btn.active { background: var(--surface); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }

.card-list { background: var(--surface); border-radius: 14px; box-shadow: 0 0 0 1px var(--line) inset; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 52px; padding: 8px 16px; position: relative; cursor: pointer; }
.row + .row { border-top: 1px solid var(--line); }
.row-label { flex: 1; }
.switch-input { position: absolute; opacity: 0; width: 100%; height: 100%; inset: 0; margin: 0; cursor: pointer; }
.switch { flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--line); position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch-input:checked + .switch { background: var(--green); }
.switch-input:checked + .switch::after { transform: translateX(20px); }
.switch-input:focus-visible + .switch, .seg-btn:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, #sound-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .backdrop, .switch, .switch::after, .seg-btn, #sound-btn { transition: none; }
}

/* Auswertung */
.st-sheet { --st-sicher: var(--green); --st-wackelig: #e0a324; --st-schwach: var(--red); --st-neu: var(--line); }
.st-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.st-sum { background: var(--surface); border-radius: 12px; padding: 10px 4px; text-align: center; box-shadow: 0 0 0 1px var(--line) inset; border-top: 4px solid; }
.st-sum b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.st-sum span { font-size: 11px; color: var(--muted); line-height: 1.2; display: block; }
.st-sicher-b { border-top-color: var(--st-sicher); } .st-wackelig-b { border-top-color: var(--st-wackelig); }
.st-schwach-b { border-top-color: var(--st-schwach); } .st-neu-b { border-top-color: var(--st-neu); }
.st-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); flex: 1; min-width: 60px; }
.st-bar span { display: block; height: 100%; }
.st-sicher { background: var(--st-sicher); } .st-wackelig { background: var(--st-wackelig); }
.st-schwach { background: var(--st-schwach); } .st-neu { background: var(--st-neu); }
.st-octs { padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.st-oct-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.st-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.st-chip { min-width: 38px; padding: 5px 7px; border-radius: 8px; text-align: center; font-size: 14px; font-weight: 600; color: #fff; }
.st-chip.st-neu { color: var(--muted); background: transparent; box-shadow: 0 0 0 1px var(--line) inset; }
.st-chip.st-wackelig { color: #3a2a00; }
.st-legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 4px 0; font-size: 12px; color: var(--muted); }
.st-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.st-legend i.st-neu { box-shadow: 0 0 0 1px var(--muted) inset; }
.st-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 14px; }
.st-row + .st-row { border-top: 1px solid var(--line); }
.st-row-label { flex: 0 0 auto; min-width: 104px; font-weight: 600; }
.st-row-label small { font-weight: 400; color: var(--muted); }
.st-row-num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; margin-left: auto; text-align: right; }
.st-row .st-bar { max-width: 40%; }
.st-days { display: flex; gap: 4px; align-items: flex-end; padding: 12px; height: 120px; }
.st-day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.st-day-bar { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 3px; overflow: hidden; }
.st-day-ok { background: var(--green); display: block; } .st-day-wrong { background: var(--red); opacity: .7; display: block; }
.st-day-lbl { font-size: 10px; color: var(--muted); }
.btn:disabled { opacity: .45; }
.done-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
