:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #667085;
  --primary: #3b6ef5;
  --primary-text: #ffffff;
  --border: #d9dee8;
  --ok: #1f9d55;
  --ok-bg: #e4f7ec;
  --warn: #b7791f;
  --warn-bg: #fdf3dc;
  --bad: #d64545;
  --bad-bg: #fde8e8;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --card: #1b2130;
    --text: #eef1f7;
    --muted: #98a2b8;
    --primary: #5b8cff;
    --border: #2f3849;
    --ok-bg: #163d29;
    --warn-bg: #3e2f12;
    --bad-bg: #421d1d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-text);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 700; }
.iconbtn { background: transparent; border: 0; font-size: 1.4rem; padding: 4px 8px; cursor: pointer; color: inherit; }

main { max-width: 640px; margin: 0 auto; padding: 14px; padding-bottom: 40px; }
.screen[hidden] { display: none; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 8px; font-size: 1.25rem; }
.card h3 { margin: 18px 0 6px; font-size: 1.05rem; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: .95rem; margin: 4px 0 12px; }

.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: 1rem; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 48px; flex: 1 1 auto;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.big { font-size: 1.1rem; min-height: 56px; flex-basis: 100%; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.link { background: transparent; border: 0; color: var(--muted); font-weight: 500; margin-top: 8px; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; flex: 0 0 auto; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.field { margin: 12px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.field label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; font-size: 1.05rem; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* list overview */
.listitem {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.listitem:last-child { border-bottom: 0; }
.listitem .info { flex: 1; min-width: 0; }
.listitem .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listitem .sub { color: var(--muted); font-size: .85rem; }

/* review rows */
.pairhead, .pairrow {
  display: grid; grid-template-columns: 1fr 1fr 40px; gap: 6px; align-items: center;
}
.pairhead { font-weight: 700; font-size: .9rem; color: var(--muted); margin: 12px 0 4px; }
.pairrow { margin-bottom: 6px; }
.pairrow input { padding: 10px; font-size: 1rem; }
.pairrow input.missing { border-color: var(--bad); background: var(--bad-bg); }
.pairrow .del { border: 0; background: transparent; font-size: 1.2rem; color: var(--bad); cursor: pointer; padding: 6px; }
details { margin-top: 12px; }
details pre { white-space: pre-wrap; font-size: .8rem; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; }

/* scan */
#scanPreview { max-width: 100%; max-height: 45vh; border-radius: 10px; display: block; margin: 0 auto 12px; }
.progress { height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* segmented */
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  flex: 1 1 auto; border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 10px; border-radius: 10px; font-size: .95rem; cursor: pointer; min-height: 44px;
}
.segmented button.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* quiz */
.quizmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.prompt {
  font-size: 2rem; font-weight: 800; text-align: center; margin: 22px 0; word-break: break-word;
}
#quizAnswer { font-size: 1.3rem; text-align: center; padding: 14px; }
.feedback { margin-top: 14px; padding: 14px; border-radius: 12px; font-size: 1.1rem; }
.feedback.ok { background: var(--ok-bg); border: 2px solid var(--ok); }
.feedback.warn { background: var(--warn-bg); border: 2px solid var(--warn); }
.feedback.bad { background: var(--bad-bg); border: 2px solid var(--bad); }
.feedback b { font-size: 1.2rem; }
.feedback .btn { margin-top: 12px; }

.bigemoji { font-size: 4rem; }
.wronglist { text-align: left; margin: 14px 0; padding: 0; list-style: none; }
.wronglist li { padding: 8px 0; border-bottom: 1px solid var(--border); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 20;
  max-width: 90vw; text-align: center;
}

/* Auswahl-Modus */
.choices { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 8px; }
.choices button {
  border: 2px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 14px 12px; font-size: 1.1rem; font-weight: 600; cursor: pointer;
  min-height: 56px; text-align: left; display: flex; gap: 10px; align-items: center;
}
.choices button .num { color: var(--muted); font-size: .9rem; font-weight: 500; flex: 0 0 auto; }
.choices button.correct { background: var(--ok-bg); border-color: var(--ok); }
.choices button.wrong { background: var(--bad-bg); border-color: var(--bad); }
.choices button[disabled] { cursor: default; }
