/* Tedzi Mathe-Trainer — main styles. Theme variables come from themes.css.
   themes.css carries the cross-Tedzi vars (--bg, --primary, --text, etc).
   The aliases below add the few mathe-specific ones that don't exist in
   the shared themes file, derived via color-mix() from the canonical vars. */
:root {
  --pad: 16px;
  --transition: .15s ease;
  --card-bg: var(--bg-card);
  --muted: var(--text-mute);
  --primary-soft: color-mix(in srgb, var(--primary) 15%, transparent);
  --err: var(--bad);
  --err-soft: color-mix(in srgb, var(--bad) 15%, transparent);
  --ok-soft: color-mix(in srgb, var(--ok) 15%, transparent);
  --info: var(--accent);
  --info-bg: color-mix(in srgb, var(--accent) 15%, transparent);
  --mastery-empty: color-mix(in srgb, var(--text) 15%, transparent);
  --mastery-fill: var(--primary);
  --input-bg: var(--bg-elev);
  --input-border: var(--border);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body { display: flex; flex-direction: column; min-height: 100dvh; }

/* ============== HEADER ============== */
#topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--topbar-bg);
  color: var(--topbar-text);
  box-shadow: var(--shadow);
}
#page-title {
  flex: 1; font-size: 18px; font-weight: 600; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: transparent; border: 0; color: inherit;
  font-size: 24px; width: 40px; height: 40px;
  border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  transition: background var(--transition);
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }
.icon-btn[hidden] { display: none; }

#ui-lang-switch {
  background: rgba(255,255,255,0.12); border: 0; color: inherit;
  font-size: 13px; padding: 6px 8px; border-radius: 6px;
  cursor: pointer; appearance: none;
}
#ui-lang-switch:hover { background: rgba(255,255,255,0.2); }
#ui-lang-switch option { color: #111; background: #fff; }

/* ============== MAIN ============== */
#main {
  flex: 1; width: 100%; max-width: 720px;
  margin: 0 auto; padding: 20px var(--pad) 100px;
}
.view { display: none; }
.view.active { display: block; }

/* ============== HOME / SKILL LIST ============== */
.welcome { text-align: center; margin-bottom: 24px; }
.welcome h2 { margin: 0 0 8px; font-size: 24px; }
.welcome .hint { margin: 0; color: var(--muted); font-size: 14px; }

.grade-tabs {
  display: flex; gap: 8px; margin-bottom: 20px;
  overflow-x: auto; padding-bottom: 4px;
}
.grade-tab {
  flex: 1; min-width: 80px;
  padding: 8px 12px; border-radius: 8px;
  background: var(--card-bg); color: var(--text);
  border: 2px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.grade-tab.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.skill-tile {
  background: var(--card-bg);
  border: 0; border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform var(--transition);
  position: relative;
}
.skill-tile:hover { transform: translateY(-2px); }
.skill-tile .skill-icon { font-size: 32px; }
.skill-tile .skill-name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.skill-tile .skill-meta { font-size: 11px; color: var(--muted); }
.mastery-dots {
  display: flex; gap: 3px; margin-top: 4px;
}
.mastery-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--mastery-empty);
}
.mastery-dots span.filled { background: var(--mastery-fill); }

/* ============== TRAINER ============== */
#view-trainer { display: none; }
#view-trainer.active { display: flex; flex-direction: column; align-items: center; }

.trainer-progress {
  display: flex; align-items: center; gap: 12px;
  width: 100%; margin-bottom: 16px;
  font-size: 14px; color: var(--muted);
}
.trainer-progress .pbar {
  flex: 1; height: 8px; border-radius: 4px;
  background: var(--mastery-empty); overflow: hidden;
}
.trainer-progress .pbar > span {
  display: block; height: 100%; background: var(--primary);
  transition: width .3s;
}

.task-card {
  width: 100%; max-width: 480px;
  background: var(--card-bg); border-radius: var(--radius);
  padding: 32px 24px; margin: 12px 0;
  box-shadow: var(--shadow);
  text-align: center;
}
.task-prompt {
  font-size: 56px; font-weight: 700; margin: 8px 0 24px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}
.task-prompt-small { font-size: 36px; }
.task-input {
  width: 200px; max-width: 100%;
  font-size: 36px; font-weight: 700; text-align: center;
  padding: 12px; border-radius: 10px;
  border: 3px solid var(--input-border);
  background: var(--input-bg); color: var(--text);
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--transition);
}
.task-input:focus { border-color: var(--primary); }
.task-input.correct { border-color: var(--ok); background: var(--ok-soft); }
.task-input.wrong { border-color: var(--err); background: var(--err-soft); animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.choice-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 12px; max-width: 360px; margin: 0 auto;
}
.choice-btn {
  padding: 18px; border-radius: 10px;
  border: 2px solid var(--input-border);
  background: var(--card-bg); color: var(--text);
  font-size: 28px; font-weight: 700; cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: all var(--transition);
}
.choice-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.choice-btn.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice-btn.wrong { border-color: var(--err); background: var(--err-soft); }
.choice-btn:disabled { cursor: default; }

.task-actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
  margin-top: 16px;
}
.task-feedback {
  margin-top: 16px; min-height: 24px; font-size: 16px; font-weight: 600;
}
.task-feedback.ok { color: var(--ok); }
.task-feedback.err { color: var(--err); }

/* Strategy card */
.strategy-card {
  margin-top: 16px; padding: 16px;
  background: var(--info-bg); border-left: 4px solid var(--info);
  border-radius: 8px; text-align: left;
}
.strategy-card .strategy-title {
  font-weight: 700; color: var(--info); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
  justify-content: space-between;
}
.strategy-card .strategy-body { font-size: 15px; line-height: 1.5; }

/* Speak (vorlesen) button — appears next to task prompts and strategy cards */
.speak-btn {
  background: var(--primary-soft);
  border: 0; border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 20px; cursor: pointer;
  display: inline-grid; place-items: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.speak-btn:hover {
  background: var(--primary);
  transform: scale(1.05);
}
.speak-row {
  display: flex; justify-content: center;
  margin: -8px 0 16px;
}

/* ============== EQUATION STEPPER ============== */
.eq-stepper { width: 100%; }
.eq-history {
  text-align: left;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--bg-elev);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.eq-line {
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 6px 0;
  color: var(--text);
}
.eq-op {
  font-size: 13px;
  color: var(--muted);
  padding-left: 12px;
  font-style: italic;
}
.eq-solved {
  text-align: center;
  font-size: 20px;
  margin: 16px 0;
  padding: 12px;
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 8px;
  font-weight: 600;
}
.eq-op-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-elev);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.eq-op-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
  text-align: center;
}
.eq-ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.eq-op-btn {
  flex: 1 1 56px;
  min-width: 56px;
  font-size: 22px;
  font-weight: 700;
  padding: 12px 8px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.eq-op-btn:hover { border-color: var(--primary); }
.eq-op-btn.picked {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.eq-op-btn.eq-op-x .x {
  font-style: italic;
  margin-left: 1px;
}
.eq-op-btn.eq-op-x { font-size: 18px; }

/* Input-Row gestapelt: Anwenden-Button immer auf eigener Zeile.
   Auf großen Screens würde flexbox sie nebeneinander setzen, aber
   bei kleinen Touch-Geräten (Telefon) ist die gestapelte Form
   tippsicherer und der Button ist groß genug. */
.eq-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.eq-input-row .task-input {
  width: 100%;
  font-size: 24px;
}
.eq-input-row .eq-apply {
  width: 100%;
  white-space: nowrap;
}
.eq-feedback {
  margin-top: 8px;
  font-size: 14px;
  min-height: 20px;
}
.eq-feedback.err { color: var(--err); }

/* ============== ANALOG CLOCK (SVG) ============== */
.clock-wrap {
  display: flex; justify-content: center;
  margin: 8px 0 12px;
}
.clock-svg {
  max-width: 220px;
  width: 100%; height: auto;
}
.clock-face {
  fill: var(--bg-elev);
  stroke: var(--text);
  stroke-width: 3;
}
.clock-tick {
  stroke: var(--text);
  stroke-width: 1.5;
  stroke-linecap: round;
}
.clock-tick-hour {
  stroke-width: 3;
}
.clock-number {
  fill: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-anchor: middle;
  font-family: system-ui, -apple-system, sans-serif;
}
.clock-hand {
  stroke-linecap: round;
}
.clock-hand-hour {
  stroke: var(--text);
  stroke-width: 6;
}
.clock-hand-minute {
  stroke: var(--primary);
  stroke-width: 4;
}
.clock-center {
  fill: var(--primary);
}

/* Iconic representations: Zehnerfeld, Zahlenstrahl */
.tenframe {
  display: inline-grid; grid-template-columns: repeat(5, 32px);
  gap: 6px; padding: 12px; border: 2px solid var(--text);
  border-radius: 8px;
}
.tenframe .cell {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--mastery-empty);
}
.tenframe .cell.filled { background: var(--primary); }

.numberline {
  position: relative; height: 60px; margin: 16px auto;
  width: 100%; max-width: 400px;
}
.numberline-track {
  position: absolute; top: 30px; left: 10px; right: 10px;
  height: 3px; background: var(--text); border-radius: 2px;
}
.numberline-tick {
  position: absolute; top: 24px; width: 2px; height: 14px;
  background: var(--text); transform: translateX(-1px);
}
.numberline-label {
  position: absolute; top: 42px; font-size: 11px;
  transform: translateX(-50%); color: var(--muted);
}
.numberline-marker {
  position: absolute; top: 8px; font-size: 22px;
  transform: translateX(-50%); transition: left .3s;
}

/* ============== RESULT VIEW ============== */
.result-card { text-align: center; padding: 32px; }
.result-emoji { font-size: 72px; margin-bottom: 16px; }
.result-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; margin: 24px 0;
}
.result-stat {
  background: var(--card-bg); padding: 12px; border-radius: 8px;
  box-shadow: var(--shadow);
}
.result-stat .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.result-stat .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
.result-hint {
  margin: 0 0 20px;
  padding: 12px 16px;
  background: var(--info-bg);
  border-left: 4px solid var(--info);
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
}

/* ============== BUTTONS ============== */
.btn {
  background: var(--card-bg); color: var(--text);
  border: 0; border-radius: 8px;
  padding: 12px 20px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
  box-shadow: var(--shadow);
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { background: var(--err); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ============== SETTINGS ============== */
#view-settings .section {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
#view-settings .section h3 { margin: 0 0 12px; font-size: 16px; }
.theme-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.theme-tile {
  padding: 12px 8px; border-radius: 8px; cursor: pointer;
  border: 3px solid transparent;
  font-size: 13px; font-weight: 600; color: #fff;
  transition: transform var(--transition);
}
.theme-tile.active { border-color: var(--primary); transform: scale(1.05); }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; gap: 12px;
}

/* ============== INSTALL CTA ============== */
.install-cta {
  margin-top: 24px;
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.install-card { display: flex; align-items: center; gap: 12px; }
.install-icon { font-size: 32px; }
.install-text { flex: 1; }
.install-text strong { display: block; font-size: 15px; }
.install-text small { color: var(--muted); font-size: 13px; }

/* ============== FOOTER ============== */
footer {
  text-align: center; padding: 24px 16px;
  color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--card-bg);
}
footer a { color: var(--muted); }

/* ============== TOAST ============== */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 24px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 200;
}

/* ============== UTILITIES ============== */
[hidden] { display: none !important; }
.action-row {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px;
}
