:root {
  /* Solarized (Ethan Schoonover) – dunkel */
  --bg: #002b36;          /* base03 */
  --surface: #073642;     /* base02 */
  --line: #0d4654;
  --text: #93a1a1;        /* base1 */
  --text-2: #839496;      /* base0 */
  --muted: #657b83;       /* base00 */
  --accent: #268bd2;      /* blue */
  --on-accent: #fdf6e3;
  --mark: rgba(181, 137, 0, .35);
  --yellow: #b58900;
  --orange: #cb4b16;
  --red: #dc322f;
  --magenta: #d33682;
  --violet: #6c71c4;
  --cyan: #2aa198;
  --green: #859900;
  --warn: #b58900;
  --todo-bg: rgba(203, 75, 22, .14);
  --ready: #a9c41c;       /* helleres Grün für „bereit“ (Balken, ✦) */
  --err-bg: rgba(220, 50, 47, .16);
  --tap: 48px;
  color-scheme: dark;
}
/* Solarized – hell (System-Einstellung oder manuell in „Settings → Darstellung“) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fdf6e3; --surface: #eee8d5; --line: #e2dbc6;
    --text: #586e75; --text-2: #657b83; --muted: #93a1a1;
    --mark: rgba(181, 137, 0, .25); --todo-bg: rgba(203, 75, 22, .10); --err-bg: rgba(220, 50, 47, .10);
    --ready: #86a800;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #fdf6e3; --surface: #eee8d5; --line: #e2dbc6;
  --text: #586e75; --text-2: #657b83; --muted: #93a1a1;
  --mark: rgba(181, 137, 0, .25); --todo-bg: rgba(203, 75, 22, .10); --err-bg: rgba(220, 50, 47, .10);
  --ready: #86a800;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.view {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.view.center { justify-content: center; align-items: stretch; gap: 16px; }

/* Start */
.btn {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  width: 100%;
}
.btn.small { width: auto; min-height: 40px; padding: 0 14px; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.hint { color: var(--muted); font-size: .9rem; text-align: center; }
.notice { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--warn); color: var(--warn); }
.notice p { margin: 6px 0 0; }

/* Suche */
.search { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 20px 0 8px; }
#app .q {
  width: 100%;
  min-height: 52px;
  padding: 0 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  outline: none;
}
#app .q:focus { border-bottom-color: var(--accent); }
#app .q::placeholder { color: var(--muted); }
#app input[type=search]::-webkit-search-cancel-button { filter: invert(1) brightness(.6); }

.hits { list-style: none; margin: 0; padding: 0; flex: 1; }
.hit {
  display: block;
  width: 100%;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  min-height: var(--tap);
}
.hit:active { background: var(--surface); }
.hit .name { font-weight: 600; overflow-wrap: anywhere; }
.hit .dir { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.hit .snip {
  color: var(--text-2); font-size: .9rem; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
mark { background: var(--mark); color: inherit; border-radius: 3px; }
.empty { color: var(--muted); padding: 16px 4px; }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  color: var(--muted); font-size: .8rem; padding-top: 16px;
}
.status .status-text { flex: 1; min-width: 50%; }
.link {
  border: 0; background: transparent; color: var(--muted); text-decoration: underline;
  min-height: 40px; padding: 0;
}
.link.accent { color: var(--accent); }

/* App-Rahmen mit Tabs */
#app { --tabs-h: calc(56px + env(safe-area-inset-bottom)); }
.panel {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(var(--tabs-h) + 16px);
  display: flex;
  flex-direction: column;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  height: var(--tabs-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  border: 0; background: transparent;
  color: var(--muted); font-weight: 600; font-size: .95rem;
  border-top: 2px solid transparent;
}
.tab.active { color: var(--text); border-top-color: var(--accent); }

/* Taggen */
.tag-head { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 16px 0 8px; border-bottom: 1px solid var(--line); }
.filter {
  width: 100%; min-height: 44px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  background: transparent; color: var(--text); font: inherit; font-size: 1.05rem; outline: none;
}
.filter:focus { border-bottom-color: var(--accent); }
.tag-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--muted); font-size: .85rem; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.tils { list-style: none; margin: 0; padding: 0; }
.til {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 44%);
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.til-main { min-width: 0; cursor: pointer; }
.til-title { font-weight: 600; overflow-wrap: anywhere; }
.til-meta { color: var(--muted); font-size: .78rem; margin-top: 2px; overflow-wrap: anywhere; }
.til-preview {
  color: var(--text-2); font-size: .85rem; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.til-full { color: var(--text-2); font-size: .85rem; margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
.picks { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; }
.chip {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.chip.have { opacity: .45; text-decoration: line-through; cursor: default; }
.chip.plus { color: var(--muted); border-style: dashed; }
.tag-box { width: 100%; }
.tag-input {
  width: 100%; min-height: 36px; padding: 0 10px;
  border-radius: 18px; border: 1px solid var(--accent);
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; outline: none;
}
.suggest { display: flex; flex-direction: column; margin-top: 4px; }
.sugg {
  min-height: 40px; padding: 0 10px; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font-size: .9rem;
  overflow-wrap: anywhere;
}
.sentinel { height: 1px; }
.confirm-bar {
  position: fixed; left: 0; right: 0; bottom: var(--tabs-h); z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: .9rem;
}
.panel:has(.confirm-bar:not([hidden])) { padding-bottom: calc(var(--tabs-h) + 80px); }
.review-view { display: flex; flex-direction: column; gap: 12px; }
.review { list-style: none; margin: 0; padding: 0; }
.review-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.review-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.hint.left { text-align: left; }
.notice ul { margin: 6px 0 0; padding-left: 18px; overflow-wrap: anywhere; }

/* Sync */
.kv { display: flex; flex-direction: column; margin: 12px 0; }
.kv-row { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.kv-label { color: var(--muted); flex: 0 0 42%; }
.kv-row > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.section { font-size: 1rem; margin: 20px 0 4px; }
.log { list-style: none; margin: 0; padding: 0; font-size: .8rem; }
.log li { display: flex; flex-wrap: wrap; gap: 2px 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.log-time { color: var(--muted); }
.log-op { color: var(--accent); }
.log-path { flex-basis: 100%; overflow-wrap: anywhere; }

/* Review */
.decks { list-style: none; margin: 8px 0 16px; padding: 0; }
.deck {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 64px; padding: 10px 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left;
}
.deck:active:not(:disabled) { background: var(--surface); }
.deck.done { cursor: default; }
.deck.done .deck-title { color: var(--muted); }
.deck-main { flex: 1; min-width: 0; }
.deck-title { font-weight: 600; overflow-wrap: anywhere; }
.deck-sub { color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.deck-counts { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: .85rem; white-space: nowrap; }
.deck-counts .due { color: var(--orange); font-weight: 600; }
.deck-counts .new { color: var(--accent); }
.muted { color: var(--muted); }
.review-overview, .review-session { display: flex; flex-direction: column; gap: 12px; }
.review-overview .link { align-self: flex-start; }
.bar .count { color: var(--muted); font-size: .85rem; padding-right: 4px; white-space: nowrap; }
.card-badge { color: var(--muted); font-size: .85rem; text-align: center; margin-top: 8px; }
.card-front {
  display: block; width: 100%; border: 0; background: transparent; padding: 8px 0 0;
  font-size: 1.5rem; font-weight: 600; text-align: center; line-height: 1.3; overflow-wrap: anywhere;
}
.card-path { color: var(--muted); font-size: .75rem; text-align: center; overflow-wrap: anywhere; margin-top: -8px; }
.review-session > .link.accent { align-self: center; }
.btn.reveal { margin-top: 8px; }
.card-back { border-top: 1px solid var(--line); padding-top: 4px; }
.answers { border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.answers summary { min-height: 44px; display: flex; align-items: center; color: var(--muted); cursor: pointer; }
.answers[open] { padding-bottom: 8px; }
.answer-box { display: flex; flex-direction: column; gap: 8px; }
.answer-input {
  width: 100%; padding: 10px; border-radius: 12px; border: 1px solid var(--accent);
  background: var(--surface); color: var(--text); font: inherit; resize: vertical; outline: none;
}
.answer-box .btn-row { justify-content: flex-end; }
.answer-box .btn-row .btn { flex: 0 0 auto; }
.ratings { display: flex; gap: 8px; position: sticky; bottom: calc(var(--tabs-h) + 8px); padding-top: 8px; background: var(--bg); }
.rate {
  flex: 1; min-height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.rate small { font-weight: 400; font-size: .75rem; color: var(--muted); }
.rate.hard { border-color: var(--red); color: var(--red); }
.rate.good { border-color: var(--accent); color: var(--accent); }
.rate.easy { border-color: var(--green); color: var(--green); }
.card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; padding-top: 4px; }
.card-done { display: flex; flex-direction: column; gap: 12px; padding-top: 24px; }

/* Markdown (Review-Rückseite) */
.md { overflow-wrap: anywhere; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md .table-wrap { margin: 10px 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 18px 0 6px; font-size: 1.05rem; }
.md h3 { font-size: 1.2rem; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md li.task { list-style: none; margin-left: -20px; }
.md li.task input { accent-color: var(--accent); vertical-align: middle; }
.md code { font: .9em ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.md pre { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; }
.md pre code { border: 0; padding: 0; background: none; white-space: pre; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; margin-left: 0; color: var(--text-2); }
.md blockquote.callout { border-left-color: var(--accent); }
.md .callout-title { font-weight: 600; color: var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md a { color: var(--accent); }
.md .md-tag { color: var(--muted); }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: .9rem; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.md .md-img { display: inline-block; vertical-align: top; height: auto; border-radius: 8px; margin: 4px 6px 4px 0; }
.md .md-img-ph { color: var(--muted); font-size: .85rem; }

/* Editor */
.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; font-size: 1.1rem; margin: 0; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  border: 0; background: transparent; border-radius: 12px;
  font-size: 1.4rem; line-height: 1;
}
.path { color: var(--muted); font-size: .8rem; margin: 8px 0; }
#editor { flex: 1; min-height: 60vh; padding: 4px 0; }

/* Markdown-Editor (CodeMirror) mit Live-Vorschau */
.md-editor .cm-editor { height: auto; background: transparent; color: var(--text-2); }
.md-editor .cm-editor.cm-focused { outline: none; }
.md-editor .cm-scroller { overflow: visible; font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.md-editor .cm-content { padding: 8px 0 40vh; caret-color: var(--text); min-height: 50vh; }
.md-editor .cm-line { padding: 0 4px; }
.md-editor .cm-placeholder { color: var(--muted); }
.md-editor .cm-selectionBackground, .md-editor ::selection { background: rgba(38, 139, 210, .3) !important; }
.md-editor .cm-h { color: var(--text); font-weight: 600; }
.md-editor .cm-h1 { font-size: 1.5em; }
.md-editor .cm-h2 { font-size: 1.3em; }
.md-editor .cm-h3 { font-size: 1.15em; }
.md-editor .cm-strong { font-weight: 700; color: var(--text); }
.md-editor .cm-em { font-style: italic; }
.md-editor .cm-strike { text-decoration: line-through; color: var(--muted); }
.md-editor .cm-icode, .md-editor .cm-codeblock {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; color: var(--cyan);
}
.md-editor .cm-icode { background: var(--surface); border-radius: 4px; padding: 0 2px; }
.md-editor .cm-codeblock { background: var(--surface); }
.md-editor .cm-fence { color: var(--muted); }
.md-editor .cm-quote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--text-2); font-style: italic; }
.md-editor .cm-bullet, .md-editor .cm-listmark { color: var(--muted); }
.md-editor .cm-bullet { display: inline-block; min-width: .7em; }
.md-editor .cm-task { width: 1em; height: 1em; margin: 0 .3em 0 0; vertical-align: -0.12em; accent-color: var(--accent); }
.md-editor .cm-link, .md-editor .cm-wikilink { color: var(--violet); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.md-editor .cm-wikilink-src { color: var(--violet); }
.md-editor .cm-tag { color: var(--cyan); }
.md-editor .cm-hr { display: inline-block; width: 100%; border-top: 1px solid var(--line); vertical-align: middle; }
.md-editor .cm-img { display: inline-block; vertical-align: top; border-radius: 8px; margin: 4px 6px 4px 0; }
.md-editor .cm-img-missing { color: var(--muted); font-size: .9em; }
/* Study: Fragen, Todos, Antwort-Daten, Fehler/Warnungen */
.md-editor .cm-q { color: var(--accent); font-weight: 600; }
.md-editor .cm-todo { color: var(--orange); background: var(--todo-bg); border-radius: 3px; }
.md-editor .cm-date { color: var(--magenta); }
.md-editor .cm-err { background: var(--err-bg); text-decoration: underline wavy var(--red); }
.md-editor .cm-warn { text-decoration: underline wavy var(--yellow); }

/* Study */
.study-list, .study-edit { display: flex; flex-direction: column; gap: 12px; }
.study-list > .btn { margin-top: 4px; }
.todo-badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  background: var(--todo-bg); color: var(--orange); font-weight: 600; font-size: .8rem;
}
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; min-height: var(--tap); padding: 8px 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left;
}
.todo-item:active { background: var(--surface); }
.todo-text { color: var(--orange); overflow-wrap: anywhere; }
.todo-where { color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.study-edit .path { margin: 0; overflow-wrap: anywhere; }
.notice.err { border-color: var(--red); color: var(--red); }
.notice .link { color: inherit; min-height: 0; }
body.study-editing .tabs { display: none; }
body.study-editing .panel { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  z-index: 10;
}
.md-editor .cm-frontmatter { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85em; color: var(--muted); }

/* Korrekturvorschläge (Desktop) */
.cm-tooltip.cm-tooltip { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
.cm-suggest { display: flex; gap: 2px; padding: 3px; font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.cm-suggest button { border: 0; background: transparent; color: var(--text); padding: 4px 8px; border-radius: 6px; }
.cm-suggest button:first-child { color: var(--accent); font-weight: 600; }
.cm-suggest button:hover { background: var(--bg); }
.cm-suggest-none { color: var(--muted); padding: 4px 8px; }

/* Bildgrößen (![[bild.png|small]] / normal (Standard) / big / 100 / 100x145) und Großansicht */
img.img-sized { max-width: 100%; cursor: zoom-in; }
img.img-small { max-width: 30%; max-height: 80px; width: auto; }
img.img-normal { max-width: min(100%, 480px); max-height: 320px; }
img.img-big { max-width: 100%; }
.lightbox {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .9);
  display: flex; align-items: center; justify-content: center; overflow: auto; cursor: zoom-out;
}
.lightbox-img { max-width: 100vw; max-height: 100vh; max-height: 100dvh; object-fit: contain; cursor: zoom-in; }
.lightbox.zoomed { align-items: flex-start; justify-content: flex-start; }
.lightbox.zoomed .lightbox-img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-close {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 8px;
  width: 48px; height: 48px; border: 0; border-radius: 24px;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 2rem; line-height: 1;
}
.lightbox-nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 48px; height: 72px; border: 0; border-radius: 12px;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 2.4rem; line-height: 1;
}
.lightbox-nav.prev { left: 8px; }
.lightbox-nav.next { right: 8px; }
.lightbox-nav.off { opacity: .25; cursor: default; }
.lightbox-count {
  position: fixed; bottom: calc(12px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  padding: 4px 12px; border-radius: 12px; background: rgba(0, 0, 0, .5); color: #fff; font-size: .9rem;
}

/* Settings */
.settings-name { margin: 4px 0; }

/* Export einer VL: Druckansicht im Stil eines LaTeX-Dokuments (wie latex.css), nur beim Drucken sichtbar */
@font-face { font-family: "LM Roman"; src: url(vendor/fonts/lmroman10-regular.woff2) format("woff2"); font-weight: normal; font-style: normal; }
@font-face { font-family: "LM Roman"; src: url(vendor/fonts/lmroman10-bold.woff2) format("woff2"); font-weight: bold; font-style: normal; }
@font-face { font-family: "LM Roman"; src: url(vendor/fonts/lmroman10-italic.woff2) format("woff2"); font-weight: normal; font-style: italic; }
@font-face { font-family: "LM Roman"; src: url(vendor/fonts/lmroman10-bolditalic.woff2) format("woff2"); font-weight: bold; font-style: italic; }
@font-face { font-family: "LM Mono"; src: url(vendor/fonts/lmmono10-regular.woff2) format("woff2"); }

.print-doc { display: none; }
@page {
  size: A4;
  margin: 25mm 25mm 22mm;
  @bottom-center { content: counter(page); font: 10pt "LM Roman", serif; color: #000; }
}
@media print {
  body.printing { background: #fff; }
  body.printing > :not(.print-doc) { display: none !important; }
  body.printing .print-doc { display: block; }
}
.print-doc {
  color: #000; background: #fff;
  font: 11pt/1.45 "LM Roman", "Latin Modern Roman", "Computer Modern Serif", Georgia, serif;
  text-align: justify; hyphens: auto; -webkit-hyphens: auto;
  counter-reset: q;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.print-title { text-align: center; margin: 0 0 2.2em; }
.print-title h1 { font-size: 20pt; font-weight: normal; line-height: 1.2; margin: 0 0 .7em; }
.print-author, .print-date { font-size: 12pt; margin: .3em 0; }
.print-q { counter-increment: q; }
.print-q h2 { font-size: 13pt; font-weight: bold; text-align: left; margin: 1.6em 0 .4em; break-after: avoid; page-break-after: avoid; }
.print-q h2::before { content: counter(q); display: inline-block; min-width: 1.8em; }
.print-doc .md { overflow-wrap: normal; }
.print-doc .md p, .print-doc .md ul, .print-doc .md ol, .print-doc .md pre, .print-doc .md blockquote, .print-doc .md .table-wrap { margin: .45em 0; }
.print-doc .md ul, .print-doc .md ol { padding-left: 1.6em; }
.print-doc .md li { margin: .1em 0; }
.print-doc .md h3, .print-doc .md h4, .print-doc .md h5, .print-doc .md h6 { font-size: 11pt; margin: 1em 0 .3em; break-after: avoid; }
.print-doc .md code, .print-doc .md pre { font-family: "LM Mono", "Latin Modern Mono", ui-monospace, monospace; font-size: 10pt; background: none; border: 0; padding: 0; color: #000; }
.print-doc .md pre { padding: .2em 0 .2em 1.6em; white-space: pre-wrap; break-inside: avoid; }
.print-doc .md pre code { white-space: pre-wrap; }
.print-doc .md blockquote { border-left: 0; margin: .45em 2em; padding: 0; color: #000; font-style: italic; }
.print-doc .md blockquote.callout { border: .5pt solid #000; padding: .3em .7em; font-style: normal; }
.print-doc .md .callout-title { color: #000; }
.print-doc .md hr { border-top: .5pt solid #000; }
.print-doc .md a, .print-doc .md .wikilink { color: #000; text-decoration: none; }
.print-doc .md .md-tag { color: #555; }
.print-doc .md mark { background: #e8e8e8; color: inherit; }
.print-doc .md table { border-collapse: collapse; font-size: 10pt; margin: 0 auto; border-top: 1pt solid #000; border-bottom: 1pt solid #000; }
.print-doc .md th { border: 0; border-bottom: .5pt solid #000; padding: .2em .6em; }
.print-doc .md td { border: 0; padding: .2em .6em; }
.print-doc .md li.task input { accent-color: #000; }
.print-answer-date { font-style: italic; margin-top: .8em !important; }
/* Bilder groß genug für Papier: small = drei pro Zeile, normal ≈ ¾ Seitenbreite, big = volle Breite */
.print-doc .md .md-img { border-radius: 0; margin: .2em .4em .2em 0; break-inside: avoid; }
.print-doc img.img-sized { max-width: 100%; cursor: default; }
.print-doc img.img-small { width: 31.5%; max-width: 31.5%; max-height: none; height: auto; }
.print-doc img.img-normal { max-width: 75%; max-height: 11cm; }
.print-doc img.img-big { width: 100%; max-height: 22cm; object-fit: contain; }
.print-doc .md-img-ph { display: none; }

/* Wort-Menü per Doppelklick (Desktop): Wörterbuch-Vorschläge, darunter KI-Vorschläge */
.cm-wordmenu { display: flex; flex-direction: column; min-width: 160px; max-width: 320px; padding: 4px; font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.cm-wordmenu-item { border: 0; background: transparent; color: var(--text); padding: 5px 10px; border-radius: 6px; text-align: left; }
.cm-wordmenu-item:first-child { color: var(--accent); font-weight: 600; }
.cm-wordmenu-item:hover { background: var(--bg); }
.cm-wordmenu-sep { border-top: 1px solid var(--line); margin: 4px 6px; }
.cm-wordmenu-note { color: var(--muted); padding: 5px 10px; }
.cm-wordmenu-note.loading::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: cm-spin .8s linear infinite;
}
@keyframes cm-spin { to { transform: rotate(360deg); } }
.settings-key { display: flex; gap: 10px; align-items: center; }
.settings-key .filter { flex: 1; }
.settings-model { display: flex; align-items: center; gap: 12px; }
.settings-model .filter { flex: 1; min-width: 0; }

/* Prompt auf markierten Text (Desktop) */
.cm-ask { width: min(420px, 80vw); padding: 6px; font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.cm-ask-input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; outline: none;
}
.cm-ask-input:focus { border-color: var(--accent); }
.cm-ask-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.cm-ask-chips:not(:empty) { margin-top: 6px; }
.cm-ask-chip { border: 1px solid var(--line); background: transparent; color: var(--text-2); padding: 2px 8px; border-radius: 10px; font-size: 13px; }
.cm-ask-chip:hover { border-color: var(--accent); color: var(--accent); }
.ai-dialog {
  position: fixed; z-index: 15; left: 50%; top: 12vh; transform: translateX(-50%);
  width: min(600px, calc(100vw - 32px)); max-height: 70vh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
.ai-dialog-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line); }
.ai-dialog-label { flex: 1; color: var(--accent); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-dialog-body { padding: 4px 16px; overflow-y: auto; min-height: 60px; }
.ai-dialog-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.ai-dialog-status { flex: 1; color: var(--muted); font-size: .85rem; }
.ai-dialog-note { display: block; padding: 14px 0; color: var(--muted); }
.ai-dialog-note.err { color: var(--red); }
.ai-dialog-note.loading::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: cm-spin .8s linear infinite;
}

/* Review-Status der Fragen (Study): Punkt vor der Frage, leichte Hintergrundfarbe, Balken in den Listen */
.md-editor .cm-dot-wrap { display: inline-block; vertical-align: middle; margin-right: 6px; }
.md-editor .cm-dot {
  display: block; width: 11px; height: 11px; border-radius: 50%; cursor: pointer; position: relative;
  border: 1.5px solid var(--muted); background: transparent;
}
.md-editor .cm-dot::before { content: ""; position: absolute; inset: -9px; } /* größere Tippfläche */
.md-editor .cm-dot.ready { border-color: var(--green); background: var(--green); }
.md-editor .cm-dot.skip { border-color: var(--muted); background: var(--muted); }
.md-editor .cm-q-ready { background: rgba(133, 153, 0, .13); }
.md-editor .cm-q-skip { background: rgba(147, 161, 161, .16); }
.md-editor .cm-q-skip .cm-q { color: var(--muted); }
.state-info { display: inline-flex; align-items: center; gap: 6px; }
.state-open-count { color: var(--yellow); font-weight: 600; font-size: .8rem; }
.state-bar { display: inline-flex; width: 72px; height: 7px; border-radius: 4px; overflow: hidden; background: var(--line); }
.state-seg.ready { background: var(--ready); }
.state-seg.open { background: var(--yellow); }
.state-seg.skip { background: var(--muted); }

/* Stapel/VL ohne offene Fragen: leicht grüner Hintergrund, ✦ als kleine Fee mit Sternenstaub */
.deck.all-set { background: linear-gradient(90deg, color-mix(in srgb, var(--ready) 10%, transparent), transparent 75%); }
.fairy { position: relative; display: inline-block; width: 14px; height: 14px; line-height: 14px; text-align: center; }
.fairy-star {
  display: inline-block; color: var(--ready); font-size: .9rem;
  text-shadow: 0 0 6px color-mix(in srgb, var(--ready) 70%, transparent);
  animation: fairy-fly 4.7s ease-in-out infinite;
}
.fairy-dust {
  position: absolute; left: 6px; top: 6px; width: 2px; height: 2px; border-radius: 50%;
  background: var(--ready); box-shadow: 0 0 3px var(--ready); opacity: 0;
  animation: fairy-dust 2.3s ease-out infinite;
}
.fairy-dust:nth-child(2) { animation-duration: 1.9s; }
.fairy-dust:nth-child(3) { animation-duration: 2.8s; }
@keyframes fairy-fly {
  0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  12% { transform: translate(-2px, -4px) rotate(-12deg) scale(.95); }
  25% { transform: translate(1px, -1px) rotate(4deg) scale(1); }
  37% { transform: translate(3px, -5px) rotate(16deg) scale(1.12); }
  50% { transform: translate(0, 0) rotate(0deg) scale(.92); }
  62% { transform: translate(-3px, -2px) rotate(-8deg) scale(1.05); }
  75% { transform: translate(2px, -7px) rotate(22deg) scale(1.15); }
  87% { transform: translate(0, -1px) rotate(-4deg) scale(.97); }
}
@keyframes fairy-dust {
  0% { opacity: 0; transform: translate(0, 0) scale(.6); }
  20% { opacity: .9; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}
@media (prefers-reduced-motion: reduce) {
  .fairy-star, .fairy-dust { animation: none; }
}
