:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dfe2e7;
  --text: #1c2230;
  --text-2: #4d5566;
  --muted: #6b7384;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bar: #3a78d6;
  --grid: #e3e6eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141a;
    --surface: #1a1e26;
    --surface-2: #232834;
    --border: #2f3542;
    --text: #e8ebf1;
    --text-2: #b7bdca;
    --muted: #8d95a6;
    --accent: #4f8ff7;
    --accent-ink: #0b1220;
    --good: #57c27a;
    --good-bg: #16301f;
    --bad: #ff7a7a;
    --bad-bg: #3a1c1c;
    --warn: #e0b04a;
    --warn-bg: #352a12;
    --bar: #5b95ef;
    --grid: #2a303c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #11141a; --surface: #1a1e26; --surface-2: #232834; --border: #2f3542;
  --text: #e8ebf1; --text-2: #b7bdca; --muted: #8d95a6; --accent: #4f8ff7; --accent-ink: #0b1220;
  --good: #57c27a; --good-bg: #16301f; --bad: #ff7a7a; --bad-bg: #3a1c1c;
  --warn: #e0b04a; --warn-bg: #352a12; --bar: #5b95ef; --grid: #2a303c; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); margin: 0 0 .8em; font-size: .92rem; }
.error { color: var(--bad); margin: .5em 0 0; font-size: .92rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

/* Buttons & Inputs */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:focus-visible, input:focus-visible, .tab:focus-visible, .seg-btn:focus-visible, .money:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 2px;
}
input[type=text], input[type=password] {
  font: inherit;
  font-size: 1.15rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-height: 46px;
}
.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--text-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.row-btns.end { justify-content: flex-end; }
.btn.grow { flex: 1; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; margin-right: auto; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab {
  border: 0; background: transparent; color: var(--text-2);
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 9px; cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
main { max-width: 820px; margin: 0 auto; padding: 16px; }

/* Optionen */
.level-desc { margin: 10px 0 0; }
.options h2 { margin-bottom: 4px; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-top: 1px solid var(--border); cursor: pointer;
}
.options h2 + .switch { border-top: 0; }
.switch strong { display: block; font-weight: 600; }
.switch small { display: block; color: var(--muted); font-size: .85rem; line-height: 1.35; margin-top: 2px; }
.switch input {
  appearance: none; flex: none; width: 48px; height: 28px; border-radius: 99px;
  background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg-btn { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; padding: 9px; border-radius: 9px; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); }

/* Aufgabe */
.task-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.today { font-size: .85rem; color: var(--muted); }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font: inherit; font-size: .8rem; font-weight: 700; padding: 4px 10px; border-radius: 99px; cursor: pointer;
}
.task-label { font-weight: 600; color: var(--text-2); margin-bottom: 10px; }
.task-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.amount-box { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.amount-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.amount { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.unknown { color: var(--muted); }
.euro { font-size: 1.3rem; font-weight: 700; color: var(--muted); }

.feedback { margin-top: 16px; padding: 14px; border-radius: 12px; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback.warn { background: var(--warn-bg); }
.feedback .headline { font-weight: 800; font-size: 1.1rem; margin-bottom: 6px; }
.feedback.good .headline { color: var(--good); }
.feedback.bad .headline { color: var(--bad); }
.feedback.warn .headline { color: var(--warn); }
.feedback p { margin: .3em 0; }

.steps { display: grid; gap: 4px; margin: 8px 0 4px; padding: 0; list-style: none; font-variant-numeric: tabular-nums; }
.steps li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.steps .plus { font-weight: 700; }
.steps .arrow { color: var(--muted); }

/* Geld-Darstellung */
.money-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 40px; }
.money-row.small { margin-top: 8px; }
.money {
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; user-select: none; flex: none;
  font-variant-numeric: tabular-nums;
  border: 0; padding: 0; font-family: inherit;
}
button.money { cursor: pointer; transition: transform .08s; }
button.money:active { transform: scale(.94); }

.bill {
  width: 76px; height: 42px; border-radius: 5px;
  color: #fff; font-size: 1rem;
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25), 0 1px 2px rgba(0,0,0,.25);
  position: relative; overflow: hidden;
}
.bill::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 16px; border-radius: 50%; background: rgba(255,255,255,.22); }
.b500   { background: linear-gradient(135deg, #8c8f94, #a9acb1); }
.b1000  { background: linear-gradient(135deg, #c24a44, #dc6b5e); }
.b2000  { background: linear-gradient(135deg, #3a64ad, #5b86cc); }
.b5000  { background: linear-gradient(135deg, #d97a1c, #eb9b44); }
.b10000 { background: linear-gradient(135deg, #3f8a4d, #5ea96b); }
.b20000 { background: linear-gradient(135deg, #b38a26, #cfa845); }

.coin {
  border-radius: 50%; font-size: .72rem; color: #3a2a10;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.3);
}
.coin.copper { background: radial-gradient(circle at 35% 30%, #e7a77a, #b36a3c 70%); color: #3b1d0b; }
.coin.gold   { background: radial-gradient(circle at 35% 30%, #f2dc86, #c9a63d 70%); }
.c1   { width: 30px; height: 30px; font-size: .62rem; }
.c2   { width: 34px; height: 34px; font-size: .64rem; }
.c5   { width: 38px; height: 38px; }
.c10  { width: 36px; height: 36px; }
.c20  { width: 40px; height: 40px; }
.c50  { width: 44px; height: 44px; }
.c100 { width: 42px; height: 42px; background: radial-gradient(circle, #d9dde2 0 52%, #d8b54c 54% 100%); }
.c200 { width: 47px; height: 47px; background: radial-gradient(circle, #e0bf57 0 52%, #c9ced5 54% 100%); }
.money-row.small .bill { width: 60px; height: 34px; font-size: .85rem; }
.money-row.small .bill::before { width: 12px; }
.money-row.small .coin { transform: scale(.85); margin: -2px; }

/* Herausgeben */
.coin-step { margin-top: 18px; }
.tray { background: var(--surface-2); border-radius: 12px; padding: 12px; display: grid; gap: 12px; }
.tray-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
#tray-coins .coin { margin: 0 3px; }
.hand { margin-top: 12px; border: 2px dashed var(--border); border-radius: 12px; padding: 10px 12px; min-height: 80px; }
.hand-head { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.hand-sum { color: var(--text); font-variant-numeric: tabular-nums; }

/* Rechner */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc-grid label { font-weight: 600; font-size: .92rem; display: grid; gap: 4px; }
.input-euro { display: flex; align-items: center; gap: 6px; }
.input-euro span { font-weight: 700; color: var(--muted); }
.calc-result { margin-top: 16px; }
.calc-result .big { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Statistik */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .8rem; color: var(--muted); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--bar); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.15); }
.chart .empty-dot { fill: var(--grid); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 3;
  background: var(--text); color: var(--surface);
  padding: 6px 10px; border-radius: 8px; font-size: .82rem; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.wrong { color: var(--bad); font-weight: 700; }
.right { color: var(--good); font-weight: 700; }
.file-btn { position: relative; }

/* Modus, Tagesziel, Zeitdruck */
.muted-inline { color: var(--muted); font-weight: 400; font-size: .85em; }
.mode-seg { margin-bottom: 12px; }
.goal { flex: 1; min-width: 0; }
.goal-text { font-size: .85rem; color: var(--text-2); margin-bottom: 4px; }
.goal-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; max-width: 260px; }
.goal-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s; }
.goal.done .goal-bar span { background: var(--good); }
.rush-bar { margin-bottom: 10px; }
.rush-info { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.rush-time { font-size: 1.3rem; }
.rush-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.rush-track span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s linear; }
.rush-bar.hurry .rush-track span { background: var(--bad); }
.rush-bar.hurry .rush-time { color: var(--bad); }
.panel { text-align: center; padding: 8px 4px; }
.panel p { margin: .4em 0; }
.panel .row-btns { margin-top: 14px; }
.panel > .btn { margin-top: 14px; width: 100%; }
.panel table { text-align: left; margin-top: 10px; }
.panel-icon, .tut-icon { font-size: 44px; line-height: 1.1; margin-bottom: 6px; }
.big-score { font-size: 3rem; font-weight: 800; line-height: 1.1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.big-score small { display: block; font-size: .9rem; font-weight: 600; color: var(--muted); }
.warn-tag { background: var(--warn-bg); color: var(--warn); }
.money.empty { opacity: .28; filter: grayscale(1); cursor: not-allowed; }
button.money:disabled:active { transform: none; }

/* Aufwärmen */
.warm-q { font-size: 1.1rem; text-align: center; margin: 6px 0 10px; }
.warm-q strong { white-space: nowrap; }
.warm-display {
  font-size: 2.2rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border-radius: 12px; padding: 8px; margin: 0 auto 12px; max-width: 360px;
}
.warm-display.placeholder { color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 360px; margin: 0 auto; }
.keypad button {
  font: inherit; font-size: 1.4rem; font-weight: 700; min-height: 54px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.keypad button:active { transform: scale(.96); }
#warmup .row-btns, #warmup .feedback { max-width: 360px; margin-left: auto; margin-right: auto; }

/* Optionen: Auswahl-Blöcke */
.opt-block { padding: 12px 0; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.options h2 + .opt-block { border-top: 0; }
.opt-block strong { display: block; font-weight: 600; }
.opt-block small { display: block; color: var(--muted); font-size: .85rem; }
.small-seg { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 1fr; }
.switch em { font-style: normal; color: var(--warn); }

/* Stärken & Schwächen */
.weak-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(60px, 1fr) auto; gap: 10px; align-items: center; padding: 6px 0; font-size: .92rem; }
.weak-bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.weak-bar span { display: block; height: 100%; border-radius: 99px; background: var(--muted); }
.weak-bar span.low { background: var(--bad); }
.weak-bar span.mid { background: var(--warn); }
.weak-bar span.high { background: var(--good); }
.weak-val { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.weak-val small { color: var(--muted); font-weight: 400; }

/* Abzeichen */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.badge { border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; background: var(--surface-2); }
.badge-icon { font-size: 30px; line-height: 1.2; }
.badge-name { font-weight: 700; font-size: .88rem; margin-top: 2px; }
.badge-desc { font-size: .75rem; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.badge-date { font-size: .7rem; color: var(--good); margin-top: 4px; font-weight: 600; }
.badge.locked { opacity: .55; }
.badge.locked .badge-icon { filter: grayscale(1); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 8px; animation: toast-in .18s ease-out;
}
.toast.good { background: var(--good); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.badge { background: linear-gradient(135deg, #b8860b, #e0b04a); color: #1c1400; }
.toast-icon { font-size: 1.5rem; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* Anleitung */
.tutorial {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100% - 24px)); max-height: calc(100% - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.tutorial::backdrop { background: rgba(10, 14, 22, .55); }
.tutorial[open] { display: flex; flex-direction: column; }
.tut-body { padding: 22px 20px 8px; overflow-y: auto; text-align: center; }
.tut-body p { margin: .5em 0; }
.tut-body .steps { text-align: left; display: inline-grid; margin: 8px auto; }
.tut-close { position: absolute; top: 8px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 1.1rem; width: 40px; height: 40px; cursor: pointer; border-radius: 50%; }
.tut-foot { padding: 8px 20px 18px; }
.tut-dots { display: flex; justify-content: center; gap: 6px; }
.tut-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.tut-dots span.on { background: var(--accent); }
.tut-counter { font-size: 1.6rem; font-weight: 800; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.tut-counter .muted-inline { display: block; font-size: .8rem; font-weight: 600; }
.tut-hint { min-height: 2.6em; font-size: .92rem; color: var(--text-2); }
.tut-hint.good { color: var(--good); font-weight: 600; }
.tut-hint.bad { color: var(--bad); }
.tut-tray { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.tut-hand { justify-content: center; margin-top: 8px; min-height: 48px; }
.tut-list { text-align: left; padding-left: 1.1em; margin: 8px 0; display: grid; gap: 6px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 560px) {
  body { font-size: 15px; }
  main { padding: 10px; }
  .topbar { padding: 6px 8px; }
  .brand { display: none; }
  .tabs { width: 100%; }
  .tab { flex: 1; padding: 8px 2px; font-size: .88rem; }
  .card { padding: 12px; margin-bottom: 10px; }
  .task-label { margin-bottom: 8px; }
  .task-grid { gap: 8px; }
  .amount-box { padding: 8px 10px; }
  .amount-title { font-size: .68rem; }
  .amount { font-size: 1.35rem; }
  .money-row.small .bill { width: 48px; height: 28px; font-size: .75rem; }
  .money-row.small .bill::before { display: none; }
  .money-row.small .coin { transform: scale(.75); margin: -5px; }
  .coin-step { margin-top: 12px; }
  .coin-step h3 { font-size: 1rem; margin-bottom: 2px; }
  .hint { font-size: .82rem; margin-bottom: 8px; }
  .tray { padding: 10px 6px; gap: 10px; }
  .tray-row { gap: 8px; }
  .tray .bill { width: 68px; height: 38px; }
  #tray-coins .coin { margin: 0 4px; }
  .hand { min-height: 70px; padding: 8px 10px; }
  .hand .money-row { gap: 4px; }
  .hand .bill { width: 60px; height: 34px; font-size: .88rem; }
  .row-btns { margin-top: 10px; }
  .feedback { margin-top: 10px; padding: 12px; }
  .calc-grid { gap: 8px; }
  .tiles { gap: 8px; }
  .scroll-x { overflow-x: auto; }
  .mode-seg { margin-bottom: 8px; }
  .mode-seg .seg-btn { padding: 7px 4px; font-size: .88rem; }
  .goal-text { font-size: .8rem; margin-bottom: 3px; }
  .warm-display { font-size: 1.9rem; }
  .keypad button { min-height: 50px; }
  .badges { grid-template-columns: repeat(2, 1fr); }
  .weak-row { grid-template-columns: 1fr auto; row-gap: 4px; }
  .weak-bar { grid-column: 1 / -1; }
  .tut-body { padding: 20px 16px 6px; }
  .toast { bottom: 14px; }
}
