/* ===== 1×1-Trainer – eigenes Design: frisches Grün + sonniges Gelb ===== */
:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --yellow: #facc15;
  --yellow-dark: #eab308;
  --yellow-light: #fef9c3;

  --bg: #f3faf5;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-border: #d6efdd;
  --text: #14321f;
  --text-soft: #4b6657;
  --muted: #6b8576;

  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;

  --shadow: 0 6px 20px rgba(16, 110, 60, 0.12);
  --shadow-sm: 0 2px 8px rgba(16, 110, 60, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
  --focus: 0 0 0 3px rgba(250, 204, 21, 0.85);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-light: #14361f;
  --yellow: #facc15;
  --yellow-dark: #eab308;
  --yellow-light: #3a3411;

  --bg: #0c1711;
  --bg-soft: #122019;
  --card: #15241b;
  --card-border: #234433;
  --text: #e7f6ec;
  --text-soft: #b3ccbd;
  --muted: #88a795;

  --ok: #34d399;
  --ok-bg: #143626;
  --bad: #f87171;
  --bad-bg: #3a1717;

  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.4);
  --focus: 0 0 0 3px rgba(250, 204, 21, 0.9);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  padding: calc(var(--safe-top)) 0 calc(var(--safe-bottom));
}

button { font-family: inherit; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: 8px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  background: linear-gradient(120deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { border-radius: 9px; display: block; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  max-width: 48vw;
}
.chip:hover { background: rgba(255,255,255,0.28); }
.chip-avatar { font-size: 1.15rem; line-height: 1; }
#profileNameLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.3); }

/* ===== Layout / Views ===== */
#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}
.view { display: none; animation: fade .22s ease; }
.view.is-active { display: block; }
.view[hidden] { display: none !important; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-title {
  font-size: 1.6rem;
  margin: 6px 0 4px;
  letter-spacing: -0.02em;
}
.lead { color: var(--text-soft); margin: 4px 0 16px; line-height: 1.45; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hint { color: var(--bad); font-weight: 600; min-height: 1.2em; margin: 8px 0 0; }

.view-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.view-head .icon-btn { border-color: var(--card-border); background: var(--card); color: var(--text); }
.view-head .screen-title { margin: 0; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 16px;
  box-shadow: var(--shadow-sm);
}
.card-title { margin: 0 0 12px; font-size: 1.1rem; }

/* ===== Reihen-Auswahl ===== */
.row-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.row-btn {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.row-btn:hover { transform: translateY(-2px); }
.row-btn[aria-pressed="true"] {
  background: var(--green);
  border-color: var(--green-dark);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.row-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* ===== Felder ===== */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--card-border);
}
.field-row:last-child { border-bottom: 0; }
.switch-row { cursor: pointer; }

.select, .text-input {
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 1rem;
  font-weight: 600;
}
.text-input { width: 100%; }

/* Switch */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.slider {
  position: absolute; inset: 0;
  background: var(--card-border);
  border-radius: 999px;
  transition: background .15s ease;
}
.slider::before {
  content: "";
  position: absolute;
  width: 22px; height: 22px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.switch input:focus-visible + .slider { box-shadow: var(--focus); }

/* ===== Buttons ===== */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(120deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-ghost {
  background: var(--bg-soft);
  color: var(--text);
  border: 2px solid var(--card-border);
}
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-xl { width: 100%; padding: 16px; font-size: 1.2rem; margin-top: 4px; }

.home-nav { display: flex; gap: 10px; margin-top: 18px; }
.home-nav .btn { flex: 1; }

/* ===== Quiz ===== */
.quiz-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.quiz-head .icon-btn { border-color: var(--card-border); background: var(--card); color: var(--text); }
.progress {
  flex: 1;
  height: 12px;
  background: var(--card-border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--yellow), var(--green));
  border-radius: 999px;
  transition: width .3s ease;
}
.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  background: var(--yellow-light);
  color: var(--yellow-dark);
  border: 1px solid var(--yellow);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.95rem;
}
.quiz-meta {
  display: flex; justify-content: space-between;
  color: var(--text-soft); font-weight: 600; font-size: 0.95rem;
  margin-bottom: 10px;
}
.quiz-stars { color: var(--yellow-dark); }

.task-card {
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: var(--radius);
  padding: 26px 16px 18px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 14px;
}
.task-card.correct { border-color: var(--ok); background: var(--ok-bg); }
.task-card.wrong { border-color: var(--bad); background: var(--bad-bg); }

.task {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: clamp(2.2rem, 11vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.task-op { color: var(--green); }
.task-answer {
  min-width: 1.6em;
  color: var(--yellow-dark);
  border-bottom: 4px dashed var(--yellow);
  padding: 0 6px;
}
.task-answer.filled { color: var(--text); border-bottom-style: solid; border-color: var(--green); }

.feedback { min-height: 1.5em; margin-top: 12px; font-weight: 800; font-size: 1.05rem; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.answer-input {
  width: 100%;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

/* Keypad */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.key {
  padding: 18px 0;
  font-size: 1.5rem;
  font-weight: 800;
  border-radius: 14px;
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  transition: transform .08s ease, background .12s ease;
}
.key:hover { background: var(--green-light); }
.key:active { transform: scale(0.95); }
.key-ok { background: var(--green); color: #fff; border-color: var(--green-dark); }
.key-ok:hover { background: var(--green-dark); }
.key-wide { background: var(--yellow-light); border-color: var(--yellow); color: var(--yellow-dark); }
.keypad[hidden] { display: none; }

/* ===== Ergebnis ===== */
.result-card { text-align: center; }
.result-big { font-size: 2.6rem; margin-bottom: 8px; }
.result-stars { letter-spacing: 4px; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0;
}
.stats-top { margin: 0 0 16px; }
.stat-box {
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num { font-size: 1.4rem; font-weight: 800; color: var(--green); }
.stat-lbl { font-size: 0.78rem; color: var(--muted); }
.result-msg { font-weight: 700; color: var(--text-soft); margin: 8px 0 4px; }
.result-mistakes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 6px; }
.mistake-tag {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 8px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 0.9rem;
}
.result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== Statistik ===== */
.row-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.row-stat {
  border-radius: 12px;
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  padding: 10px 4px;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform .12s ease;
}
.row-stat:hover { transform: translateY(-2px); }
.row-stat .rs-num { font-size: 1.2rem; font-weight: 800; }
.row-stat .rs-pct { font-size: 0.78rem; color: var(--muted); }
.row-stat.lvl-good { border-color: var(--green); background: var(--green-light); }
.row-stat.lvl-mid { border-color: var(--yellow); background: var(--yellow-light); }
.row-stat.lvl-bad { border-color: var(--bad); background: var(--bad-bg); }
.row-stat.lvl-none { opacity: 0.7; }

.hard-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 8px 12px;
}
.hard-list .hl-task { font-weight: 800; }
.hard-list .hl-info { color: var(--muted); font-size: 0.85rem; }

/* ===== Profile ===== */
.profile-list, .profile-quick-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.profile-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 14px;
  padding: 12px;
}
.profile-item.active { border-color: var(--green); background: var(--green-light); }
.profile-item .pi-avatar { font-size: 1.8rem; }
.profile-item .pi-main { flex: 1; min-width: 0; }
.profile-item .pi-name { font-weight: 800; }
.profile-item .pi-sub { font-size: 0.82rem; color: var(--muted); }
.profile-item .pi-actions { display: flex; gap: 6px; }
.mini-btn {
  border: 1px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 9px;
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.85rem;
}
.mini-btn.danger { color: var(--bad); border-color: var(--bad); }
.mini-btn.go { background: var(--green); color: #fff; border-color: var(--green-dark); }

.avatar-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.avatar-opt {
  font-size: 1.5rem;
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 2px solid var(--card-border);
  background: var(--bg-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-opt[aria-pressed="true"] { border-color: var(--green); background: var(--green-light); }
.new-profile-row { display: flex; gap: 10px; }
.new-profile-row .text-input { flex: 1; }

.profile-quick-list .profile-item { cursor: pointer; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 24, 15, 0.55);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  padding: 18px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  max-height: 85dvh;
  overflow: auto;
}
.modal-card h2 { margin: 0 0 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* In-App-Dialoge (wiConfirm/wiPrompt) – ersetzen native confirm/prompt */
.wi-modal-msg {
  display: block;
  margin: 0 0 14px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}
.wi-modal-input { margin-bottom: 16px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--green-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 90vw;
}
.toast[hidden] { display: none; }

/* ===== Konfetti ===== */
.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  height: 0;
}
.confetti span {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: fall 1.6s ease-in forwards;
}
@keyframes fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* Pop bei richtig */
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.task-card.pop { animation: pop .35s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.task-card.shake { animation: shake .3s ease; }

/* ===== Responsive ===== */
@media (min-width: 520px) {
  .keypad { max-width: 380px; margin: 0 auto; }
  .answer-input { max-width: 380px; margin-left: auto; margin-right: auto; display: block; }
}
@media (max-width: 360px) {
  .row-grid { gap: 7px; }
  .row-btn { font-size: 1.1rem; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .confetti span { display: none; }
}
