/* ============================================================
   Notiz→Quiz – Lernfrisch-Indigo + Limette, Pruefungs-Look
   ============================================================ */

:root {
  /* Markenpalette */
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --indigo-700: #3730a3;
  --lime: #a3e635;
  --lime-600: #84cc16;
  --lime-ink: #3f6212;

  /* Hellmodus */
  --bg: #f4f4fb;
  --bg-grad-1: #eef0ff;
  --bg-grad-2: #f7fbe9;
  --surface: #ffffff;
  --surface-2: #f6f6fd;
  --border: #e2e2f0;
  --text: #1e1b3a;
  --text-soft: #5a5775;
  --text-mute: #8b88a3;
  --shadow: 0 6px 24px rgba(79, 70, 229, 0.10);
  --shadow-sm: 0 2px 8px rgba(30, 27, 58, 0.07);

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

  --radius: 16px;
  --radius-sm: 10px;
  --gap: 16px;
  --maxw: 720px;
  --tap: 44px;

  --ease: cubic-bezier(.22,.61,.36,1);
}

[data-theme="dark"] {
  --bg: #0f0e1b;
  --bg-grad-1: #14122a;
  --bg-grad-2: #16210f;
  --surface: #1a1830;
  --surface-2: #221f3d;
  --border: #322e52;
  --text: #ececf6;
  --text-soft: #b9b6d4;
  --text-mute: #847fa5;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);

  --ok: #4ade80;
  --ok-bg: #14331f;
  --err: #f87171;
  --err-bg: #3a1414;

  --indigo: #6366f1;
  --indigo-600: #818cf8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 90% -10%, var(--bg-grad-2), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, var(--bg-grad-1), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

h2 { font-size: 1.05rem; margin: 0 0 8px; letter-spacing: -0.01em; }
h3 { margin: 0 0 8px; font-size: 1.1rem; }
p { margin: 0 0 6px; }

code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.85em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--indigo-600);
  word-break: break-word;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--indigo);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 10px 0;
  z-index: 200;
}
.skip-link:focus { left: 0; }

.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(120deg, var(--indigo) 0%, var(--indigo-700) 100%);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255,255,255,0.16);
  color: var(--lime);
  flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.12rem; letter-spacing: -0.02em; }
.brand-text .arrow { color: var(--lime); padding: 0 1px; }
.brand-text small { color: rgba(255,255,255,0.82); font-size: 0.72rem; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  min-height: var(--tap);
  cursor: pointer;
  transition: transform .12s var(--ease), background .15s, box-shadow .15s, border-color .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  line-height: 1.1;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

.btn-primary {
  background: var(--indigo);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79,70,229,0.35);
}
.btn-primary:hover { background: var(--indigo-600); }

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 6px 12px; min-height: 36px; font-size: 0.85rem; }

.btn-icon {
  background: rgba(255,255,255,0.16);
  color: #fff;
  border: none;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border-radius: 12px;
  font-size: 1.25rem;
}
.btn-icon:hover { background: rgba(255,255,255,0.28); }
#installBtn {
  background: var(--lime);
  color: var(--lime-ink);
  border: none;
}
#installBtn:hover { background: var(--lime-600); }

.btn-right { background: var(--ok); color: #fff; flex: 1; }
.btn-right:hover { filter: brightness(1.05); }
.btn-wrong { background: var(--err); color: #fff; flex: 1; }
.btn-wrong:hover { filter: brightness(1.05); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  max-width: var(--maxw);
  margin: 14px auto 0;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 68px;
  z-index: 40;
}
.tab {
  flex: 1;
  font: inherit;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  min-height: 42px;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: linear-gradient(120deg, var(--indigo), var(--indigo-600));
  color: #fff;
  box-shadow: 0 3px 10px rgba(79,70,229,0.3);
}
.tab:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* ---------- Layout ---------- */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px;
  display: block;
}
.view { display: none; flex-direction: column; gap: var(--gap); }
.view.is-active { display: flex; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.hint { color: var(--text-soft); font-size: 0.9rem; }
.hint.small { font-size: 0.82rem; }
.empty-hint {
  color: var(--text-mute);
  font-size: 0.9rem;
  text-align: center;
  padding: 18px 8px;
}

.format-list {
  margin: 8px 0 12px;
  padding-left: 18px;
  color: var(--text-soft);
  font-size: 0.9rem;
}
.format-list li { margin-bottom: 4px; }

.pill {
  background: var(--lime);
  color: var(--lime-ink);
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.85rem;
  min-width: 30px;
  text-align: center;
}

/* ---------- Textarea ---------- */
.notes-input {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.55;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
  min-height: 150px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.notes-input:focus-visible {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.18);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
}

.parse-feedback {
  margin-top: 10px;
  font-size: 0.88rem;
  color: var(--text-soft);
  min-height: 1.2em;
}
.parse-feedback.ok { color: var(--ok); font-weight: 600; }
.parse-feedback.warn { color: var(--err); font-weight: 600; }

/* ---------- Mode toggle ---------- */
.mode-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
}
.mode-label { font-size: 0.88rem; color: var(--text-soft); font-weight: 600; }
.seg {
  position: relative;
  display: inline-flex;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-block;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-2);
  cursor: pointer;
  min-height: 36px;
  line-height: 1.4;
  transition: all .15s;
}
.seg input:checked + span {
  background: var(--indigo);
  color: #fff;
  border-color: var(--indigo);
}
.seg input:focus-visible + span { outline: 3px solid var(--lime); outline-offset: 2px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-soft);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--indigo); }

/* ---------- Card list ---------- */
.card-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--lime-600);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.cl-body { min-width: 0; flex: 1; }
.cl-q { font-weight: 600; word-break: break-word; }
.cl-a { color: var(--text-soft); font-size: 0.88rem; word-break: break-word; }
.cl-del {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-mute);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 8px;
}
.cl-del:hover { background: var(--err-bg); color: var(--err); }
.cl-del:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* ---------- Quiz ---------- */
.quiz-progress { margin-bottom: 14px; }
.progress-track {
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--indigo), var(--lime-600));
  border-radius: 999px;
  transition: width .35s var(--ease);
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-soft);
  gap: 8px;
  flex-wrap: wrap;
}
.quote { font-weight: 700; color: var(--indigo-600); }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.flashcard::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(400px 120px at 50% -20%, rgba(163,230,53,0.16), transparent 70%);
  pointer-events: none;
}
.flashcard-inner { width: 100%; position: relative; z-index: 1; }
.fc-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--indigo-600);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.fc-tag.answer { color: var(--lime-ink); background: rgba(163,230,53,0.18); border-color: var(--lime-600); }
[data-theme="dark"] .fc-tag.answer { color: var(--lime); }
.fc-question { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; word-break: break-word; margin: 0; }
.fc-answer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
  animation: fadeUp .25s var(--ease);
}
.fc-answer p { font-size: 1.1rem; word-break: break-word; margin: 0; color: var(--text); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.reveal-btn {
  margin-top: 18px;
  font: inherit;
  font-weight: 600;
  background: var(--lime);
  color: var(--lime-ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 22px;
  min-height: var(--tap);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(132,204,22,0.4);
  transition: transform .12s var(--ease), filter .15s;
}
.reveal-btn:hover { filter: brightness(1.04); }
.reveal-btn:active { transform: translateY(1px); }
.reveal-btn:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }

.rate-row { margin-top: 16px; text-align: center; }
.rate-prompt { font-weight: 600; color: var(--text-soft); margin-bottom: 10px; }
.rate-buttons { display: flex; gap: 10px; }

.quiz-foot {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.quiz-foot .btn { flex: 1; min-width: 140px; }

/* ---------- Result ---------- */
.result-score {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  margin: 8px 0 18px;
}
.ring {
  --pct: 0;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background:
    radial-gradient(closest-side, var(--surface) 70%, transparent 71% 100%),
    conic-gradient(var(--lime-600) calc(var(--pct) * 1%), var(--border) 0);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text);
}
.result-numbers p { margin: 2px 0; color: var(--text-soft); }
.result-numbers strong { color: var(--text); font-size: 1.05rem; }
.time-line { margin-top: 8px !important; }

/* ---------- Statistik ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.stat-num {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--indigo-600);
  letter-spacing: -0.02em;
}
.stat-lbl { font-size: 0.78rem; color: var(--text-soft); }

.history-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  flex-wrap: wrap;
}
.hist-left { min-width: 0; }
.hist-date { font-size: 0.82rem; color: var(--text-mute); }
.hist-detail { font-size: 0.9rem; color: var(--text-soft); }
.hist-quote {
  font-weight: 800;
  font-size: 1.05rem;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.hist-quote.good { color: var(--ok); border-color: var(--ok); }
.hist-quote.mid { color: var(--indigo-600); }
.hist-quote.low { color: var(--err); border-color: var(--err); }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  font-weight: 600;
  animation: toastIn .25s var(--ease);
}
.toast.success { background: var(--ok); color: #fff; }
.toast.error { background: var(--err); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 14, 27, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 400;
  animation: fadeIn .15s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  padding: 22px;
  width: min(92vw, 420px);
  animation: fadeUp .2s var(--ease);
}
.modal p { color: var(--text-soft); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Footer ---------- */
.appfoot {
  max-width: var(--maxw);
  margin: 8px auto 24px;
  padding: 0 16px;
  text-align: center;
  color: var(--text-mute);
  font-size: 0.78rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .brand-text small { display: none; }
  .quiz-foot .btn { min-width: 0; flex: 1 1 100%; }
  .fc-question { font-size: 1.15rem; }
}

@media (min-width: 560px) {
  .stat-grid { grid-template-columns: repeat(4, 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;
    scroll-behavior: auto !important;
  }
}
