[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 0;
}

.home {
  color: var(--muted);
  text-decoration: none;
  font-size: 1rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-name { font-weight: 600; }

.stars {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stars span[aria-hidden] { color: var(--star); }

/* ---------- Nutzerauswahl ---------- */

.user-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  display: grid;
  gap: 10px;
}

.user-list li {
  display: flex;
  gap: 8px;
}

.user-select {
  flex: 1;
  text-align: left;
  font-size: 1.25rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75em 1em;
}

.user-select:hover { border-color: var(--accent); }

.user-remove {
  background: transparent;
  color: var(--muted);
  border: 2px solid transparent;
  padding: 0 0.8em;
}

.user-remove:hover { color: var(--bad); }

.add-user label {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.row {
  display: flex;
  gap: 8px;
}

.row input {
  flex: 1;
  min-width: 0;
}

/* ---------- Üben ---------- */

#task-card {
  margin-top: 24px;
  padding: 32px 16px 24px;
  text-align: center;
  border-width: 3px;
  transition: border-color 0.2s;
}

/* Rückmeldung bei richtiger Antwort: grün = schnell genug, gelb = zu langsam */
#task-card.correct { --flash: var(--good); animation: correct 0.7s ease-out; }
#task-card.correct.slow { --flash: var(--slow); }
#task-card.wrong { border-color: var(--bad); }

@keyframes correct {
  from {
    border-color: var(--flash);
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--flash) 30%, transparent);
  }
  to { border-color: var(--border); }
}

.task {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.3em;
  font-size: clamp(1.8rem, 9vw, 4rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.task-text { white-space: nowrap; }

.answer {
  width: 2.6em;
  min-width: 0;
  font-size: inherit;
  font-weight: inherit;
  text-align: center;
  padding: 0.05em 0.1em;
  border-width: 3px;
}

.answer:disabled {
  color: var(--bad);
  text-decoration: line-through;
  opacity: 1;
}

.feedback {
  min-height: 2.4em;
  margin: 0.4em 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
}

.notice {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  animation: fade-in 0.4s ease-out;
}

.notice::before {
  content: "★ ";
  color: var(--star);
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 32px;
}

/* ---------- Fortschritt ---------- */

.legend {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--muted);
}

.legend li::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 6px;
  vertical-align: -0.1em;
  border-radius: 4px;
  background: var(--box-color);
}

.grid-wrap { overflow-x: auto; }

.grid {
  border-collapse: separate;
  border-spacing: 3px;
  margin: 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.7rem, 2.8vw, 1rem);
}

.grid th {
  color: var(--muted);
  font-weight: 600;
  width: 2.4em;
}

.grid td {
  width: 2.4em;
  height: 2.4em;
  text-align: center;
  border-radius: 6px;
  background: var(--box-color);
  color: #1d1f27;
}

.grid td.off { opacity: 0.3; }

.grid td.locked {
  background: transparent;
  border: 1px dashed var(--border);
}

.stages {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 14px;
}

.stage-title { display: block; }

.stages .locked { color: var(--muted); }

.stage-hint {
  font-size: 0.9rem;
}

.bar {
  display: flex;
  height: 1.6em;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 4px;
}

.bar span {
  background: var(--box-color);
  color: #1d1f27;
  font-size: 0.85rem;
  line-height: 1.6em;
  text-align: center;
  min-width: 1.6em;
}

/* ---------- Eingabe: Nummern-Pad und Schreibfläche ---------- */

.pad {
  max-width: 520px; /* so groß wie Platz da ist, aber nicht unhandlich breit */
  margin: 8px auto 0;
}

.numpad,
.writer-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2vw, 14px);
}

.pad button {
  padding: 0;
  /* Höhe wächst mit Bildschirmhöhe und -breite, mindestens ca. 56 px */
  height: clamp(3.5rem, min(10vh, 18vw), 6.5rem);
  font-size: clamp(1.6rem, min(4.5vh, 7vw), 2.6rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 14px;
  border-color: var(--border);
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation; /* kein Doppeltipp-Zoom */
  -webkit-user-select: none;
  user-select: none;
}

.pad button:active { transform: scale(0.96); }

.pad .key-back,
.pad [data-key="undo"] { color: var(--muted); }

.pad [data-key="clear"] { font-size: clamp(1.2rem, min(3.5vh, 5.5vw), 1.8rem); }

.pad .key-ok {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-size: clamp(1.3rem, min(3.5vh, 5.5vw), 2rem);
}

.pad.waiting button:not(.key-ok) { opacity: 0.35; }
.pad.waiting canvas { opacity: 0.35; }

@media (hover: hover) {
  .pad button:not(.key-ok):hover { border-color: var(--accent); }
}

.write-area {
  position: relative;
  margin-bottom: clamp(8px, 2vw, 14px);
}

.write-area canvas {
  display: block;
  width: 100%;
  /* etwa so hoch wie drei Tastenreihen */
  height: clamp(11rem, min(32vh, 56vw), 21rem);
  border: 2px dashed var(--border);
  border-radius: 14px;
  background:
    linear-gradient(transparent calc(78% - 1px), var(--border) calc(78% - 1px), var(--border) 78%, transparent 78%),
    var(--bg);
  color: var(--text);
  touch-action: none; /* Schreiben statt Scrollen */
  cursor: crosshair;
}

.write-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 16px;
  text-align: center;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  pointer-events: none;
  visibility: hidden;
}

canvas.empty + .write-hint { visibility: visible; }

.write-hint small {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Umschalter Tippen / Schreiben */
.input-mode {
  display: inline-flex;
  margin-top: 16px;
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.input-mode button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.3em 1.1em;
  font-size: 1rem;
}

.input-mode button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Handschrift-Proben ---------- */

.link-button {
  display: block;
  margin: -0.4em auto 0.4em;
  padding: 0.2em 0.6em;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 1rem;
  text-decoration: underline;
}

.link-button:disabled { color: var(--muted); text-decoration: none; cursor: default; }

.samples {
  margin-top: 32px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 1rem;
}

.samples h2 { color: var(--text); }

.samples-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.samples-note { font-size: 0.9rem; }

/* ---------- Aufgabenauswahl ---------- */

.select-head,
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.select-head .link-button,
.progress-mode .link-button,
.section-actions .link-button {
  display: inline-block;
  margin: 0;
}

.section-actions {
  display: flex;
  gap: 4px;
}

.select-section {
  margin-top: 8px;
}

.select-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Umschaltknöpfe: gewählt = grün mit ✓, nicht gewählt = grau mit ✗,
   teilweise (nur Gruppen) = grüner Rand mit – */
:root {
  --on: #23824a;
  --on-text: #ffffff;
  --off: #e6e4de;
  --off-text: #6b6f80;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --on: #5cc98a;
    --on-text: #10131a;
    --off: #343845;
    --off-text: #a4a8b8;
  }
}

.toggle,
.group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  min-height: 2.75rem;
  padding: 0.35em 1em 0.35em 0.8em;
  border: 2px solid var(--off);
  background: var(--off);
  color: var(--off-text);
  touch-action: manipulation;
}

.toggle[aria-pressed="true"],
.group-toggle[aria-pressed="true"] {
  background: var(--on);
  border-color: var(--on);
  color: var(--on-text);
}

.group-toggle[aria-pressed="mixed"] {
  background: var(--surface);
  border-color: var(--on);
  color: var(--on);
}

.mark {
  flex: none;
  width: 1em;
  text-align: center;
  font-weight: 700;
}

.mark::before { content: "✗"; }
[aria-pressed="true"] > .mark::before { content: "✓"; }
[aria-pressed="mixed"] > .mark::before { content: "–"; }

/* Gruppen der Reihen: Gruppen-Knopf, darunter die Reihen */
.row-groups {
  display: grid;
  gap: 16px;
}

.group-toggle {
  font-weight: 600;
  font-size: 1.05rem;
}

.group-rows {
  font-weight: 400;
  font-size: 0.85rem;
  opacity: 0.85;
}

.row-group .toggles {
  margin: 8px 0 0 1.25rem;
}

/* Feste Leiste unten mit Anzahl und Knöpfen */
.select-footer {
  position: sticky;
  bottom: 0;
  margin: 24px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.select-summary {
  margin: 0;
  flex: 1 1 14rem;
  font-weight: 600;
}

.select-summary.invalid {
  color: var(--bad);
  font-weight: 400;
}

.select-buttons {
  display: flex;
  gap: 10px;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Auswahl aus zwei Möglichkeiten (Automatisch / Manuell) */
.segmented {
  display: inline-flex;
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.4em 1.2em;
  min-height: 2.5rem;
}

.segmented button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.progress-mode {
  color: var(--muted);
  margin-top: 0;
}

.select-head .link-button { padding-left: 0; }

/* ---------- Scores (Mein Fortschritt) ---------- */

.scores {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin: 8px 0 8px;
}

.score {
  padding: 14px 16px;
}

.score h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.score-value {
  margin: 2px 0 0;
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.score-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.score-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.score-note:empty { display: none; }

.skill-bars {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  font-size: 0.9rem;
}

.skill-bar {
  display: grid;
  grid-template-columns: 6.5rem 1fr 3rem;
  align-items: center;
  gap: 8px;
}

.skill-track {
  height: 0.7rem;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.skill-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--good);
}

.skill-percent {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---------- Spracheingabe ---------- */

.speaker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.speaker[hidden] { display: none; }

.pad .mic {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: clamp(7rem, 30vw, 9rem);
  height: clamp(7rem, 30vw, 9rem);
  border-radius: 50%;
  border: 3px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.mic svg {
  width: 2.6rem;
  height: 2.6rem;
  fill: currentColor;
  stroke: currentColor;
}

.speaker.listening .mic {
  border-color: var(--good);
  color: var(--good);
  animation: listening 2s ease-in-out infinite;
}

/* Beim Sprechen: kräftiger Ring */
.speaker.hearing .mic {
  animation: none;
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--good) 35%, transparent);
}

@keyframes listening {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 30%, transparent); }
  50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--good) 10%, transparent); }
}

.speaker.silent .mic {
  animation: none;
  border-color: var(--slow);
  color: var(--slow);
}

.speaker.silent .speech-status { color: var(--text); }

.speech-status {
  margin: 0;
  min-height: 3em;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.speaker-keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 14px);
  width: 100%;
}

/* ---------- Einmaleins-Tafel ---------- */

.grid-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.grid-controls .segmented button { min-height: 2.25rem; padding: 0.3em 1em; }

.grid.big {
  border-spacing: 2px;
  font-size: clamp(0.55rem, 1.6vw, 0.8rem);
}

.grid.big th,
.grid.big td {
  width: 2.6em;
  height: 2.3em;
}

/* Auf schmalen Bildschirmen: bis 20 · 20 nur Farben, Details per Antippen */
@media (max-width: 720px) {
  .grid.big td { font-size: 0; }
  .grid.big th { font-size: 0.55rem; width: auto; }
  .grid.big td { width: auto; height: auto; aspect-ratio: 1; min-width: 0.8rem; border-radius: 3px; }
  .grid.big { width: 100%; table-layout: fixed; border-spacing: 1px; }
}

.grid td { cursor: pointer; }

.grid-detail {
  min-height: 1.5em;
  margin: 8px 0 0;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Ablaufender Balken bis zum automatischen Abschicken */
.speech-countdown {
  display: block;
  width: min(9rem, 40%);
  height: 4px;
  border-radius: 2px;
  background: transparent;
}

.speech-countdown.running {
  background: var(--good);
  transform-origin: left;
  animation: countdown var(--delay, 1s) linear forwards;
}

@keyframes countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.speech-delay {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.pad .speech-delay .segmented button {
  height: auto;
  min-height: 2.25rem;
  padding: 0.2em 0.75em;
  font-size: 0.85rem;
  font-weight: 400;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.pad .speech-delay .segmented button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Hilfe ---------- */

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.help-button {
  padding: 0.25em 0.9em;
  font-size: 1rem;
  font-weight: 600;
  background: transparent;
  color: var(--accent);
}

.help h2 { margin-top: 1.4em; }

.help p,
.help li {
  line-height: 1.55;
}

.help ul {
  padding-left: 1.2em;
}

.help li + li { margin-top: 0.4em; }

.help-colors {
  list-style: none;
  padding-left: 0 !important;
}

.swatch {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  border-radius: 4px;
  vertical-align: -0.1em;
}

.swatch.good { background: var(--good); }
.swatch.slow { background: var(--slow); }
.swatch.bad { background: var(--bad); }

.user-name {
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Vor der ersten Aufgabe: "Bereit?" statt Aufgabe */
.awaiting-start .answer,
.awaiting-start .equals { display: none; }
.awaiting-start .feedback { font-weight: 400; color: var(--muted); font-size: 1.1rem; }

.speech-delay .segmented {
  flex-wrap: wrap;
  justify-content: center;
  border-radius: 18px;
}

.pad .speech-delay .segmented button { white-space: nowrap; min-width: 2.4rem; }
