/* =========================================================
   Lernwelt FISI – style.css
   Farbwelt: Blau / Hellblau / Grau / Weiß – hell & dunkel
   v3: Downloads & Tools (Tabs, Terminal, Suche),
       globale Suche, Lernfeld-Verknüpfung
   ========================================================= */

/* ---------- 1. Design-Variablen ---------- */
:root {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-2: #eaf1f9;
  --text: #1f2a3a;
  --muted: #5c6b7f;
  --border: #d5e0ec;
  --border-strong: #b6c6da;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --focus: #1d4ed8;
  --shadow: 0 2px 10px rgba(30, 58, 138, 0.08);
  --ok-bg: #dcfce7;  --ok-border: #86efac;  --ok-text: #14532d;
  --bad-bg: #fee2e2; --bad-border: #fca5a5; --bad-text: #7f1d1d;
  --warn-bg: #fef9c3; --warn-border: #eab308; --warn-text: #713f12;
  --hint-bg: #eff6ff;
  --sol-bg: #f0fdf4;
}
[data-theme="dark"] {
  --bg: #0d1524;
  --surface: #16213a;
  --surface-2: #1d2a45;
  --text: #e3eaf5;
  --muted: #97a6bd;
  --border: #2a3a58;
  --border-strong: #3d5078;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: #22375c;
  --focus: #8ab6fb;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  --ok-bg: #173427;  --ok-border: #2c5c40;  --ok-text: #b9f0c9;
  --bad-bg: #3a1d24; --bad-border: #7f3b46; --bad-text: #f3c1c8;
  --warn-bg: #34290f; --warn-border: #7a6420; --warn-text: #ecdf9f;
  --hint-bg: #17263c;
  --sol-bg: #14291d;
}

/* ---------- 2. Basis ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }

/* ---------- 3. Skip-Link ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff;
  padding: .5rem .9rem; border-radius: 0 0 10px 0; z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---------- 4. Kopfzeile & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto;
  display: flex; align-items: center; gap: .75rem;
  min-height: 58px; padding: .4rem 1rem;
}
.brand { font-weight: 700; white-space: nowrap; font-size: 1.05rem; }
.brand span { color: var(--accent); }

.main-nav { flex: 1; min-width: 0; }
#nav-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; gap: .25rem;
  overflow-x: auto; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
#nav-list::-webkit-scrollbar { height: 6px; }
#nav-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.nav-item { flex-shrink: 0; }

.nav-btn {
  font: inherit; font-size: .9rem; white-space: nowrap;
  padding: .4rem .75rem; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--text);
  border: 1px solid transparent;
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 4a. Unternavigations-Leiste ---------- */
.subnav-bar {
  display: flex; gap: .45rem; align-items: center;
  padding: .5rem .75rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.subnav-bar::-webkit-scrollbar { height: 6px; }
.subnav-bar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.subnav-chip {
  flex-shrink: 0;
  font: inherit; font-size: .85rem; white-space: nowrap;
  padding: .35rem .85rem; border-radius: 999px; cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.subnav-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.subnav-chip.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent); font-weight: 600;
}

.theme-toggle, .menu-toggle {
  font: inherit; font-size: .88rem; cursor: pointer;
  padding: .4rem .75rem; border-radius: 9px;
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent);
  white-space: nowrap;
}
.theme-toggle:hover, .menu-toggle:hover { background: var(--accent-soft); }
.menu-toggle { display: none; }

/* ---------- 4b. Globale Suche (NEU) ---------- */
.search-toggle {
  font: inherit; font-size: .95rem; cursor: pointer;
  padding: .4rem .7rem; border-radius: 9px;
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent);
  white-space: nowrap;
}
.search-toggle:hover { background: var(--accent-soft); }

.search-bar {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: .6rem .75rem .7rem;
}
.search-inner {
  max-width: 1240px; margin: 0 auto;
  display: flex; gap: .5rem;
}
.global-search {
  flex: 1; font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  padding: .55rem .75rem;
}
.global-search:focus { border-color: var(--accent); }
.search-close {
  flex-shrink: 0; font: inherit; cursor: pointer;
  padding: .4rem .8rem; border-radius: 10px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border-strong);
}
.search-close:hover { color: var(--text); border-color: var(--accent); }

.search-results {
  max-width: 1240px; margin: .6rem auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 55vh; overflow-y: auto;
}
.search-result {
  display: flex; align-items: flex-start; gap: .6rem;
  width: 100%; text-align: left;
  padding: .55rem .8rem;
  background: transparent; border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer; font: inherit; color: var(--text);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:focus { background: var(--accent-soft); }
.search-type {
  flex-shrink: 0; margin-top: .1rem;
  font-size: .72rem; font-weight: 700;
  padding: .1rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.search-label { font-weight: 600; line-height: 1.4; }
.search-sub {
  display: block;
  font-size: .82rem; color: var(--muted); line-height: 1.4;
}
.search-nohit { padding: .7rem .9rem; margin: 0; color: var(--muted); }
.search-hint {
  max-width: 1240px; margin: .45rem auto 0;
  font-size: .78rem; color: var(--muted); padding: 0 .2rem;
}

/* ---------- 5. Hauptbereich ---------- */
.content {
  width: 100%; max-width: 980px; margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}
.content:focus { outline: none; }
.page-title { font-size: 1.55rem; line-height: 1.3; margin: .2rem 0 .8rem; }
.block-heading { font-size: 1.22rem; margin: 1.4rem 0 .6rem; }
.block-text p { margin: .35rem 0 .8rem; }

/* ---------- 6. Karten & Bausteine ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.35rem;
  margin: 0 0 1.2rem;
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; font-size: 1.15rem; }
.card ul { padding-left: 1.25rem; }
.placeholder { border-style: dashed; }

.note   { border-left: 4px solid var(--accent); background: var(--hint-bg); }
.example{ border-left: 4px solid var(--border-strong); background: var(--surface-2); }
.summary{ border-top: 4px solid var(--accent); }

.terms-list dt { font-weight: 700; color: var(--accent); margin-top: .55rem; }
.terms-list dd { margin: 0 0 .3rem 0; }

/* Tabellen */
.table-wrap { overflow-x: auto; margin: 0 0 1.2rem; box-shadow: var(--shadow); border-radius: 12px; }
.data-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface); font-size: .93rem;
}
.data-table caption { caption-side: top; text-align: left; font-weight: 600; padding: .35rem .2rem; }
.data-table th, .data-table td { padding: .55rem .8rem; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.data-table thead th { background: var(--accent); color: #fff; }
.data-table tbody tr:nth-child(even) { background: var(--surface-2); }

/* Diagramme (inline SVG) */
.diagram { margin: 0 0 1.2rem; }
.diagram-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: .8rem; overflow-x: auto;
}
.diagram figcaption { text-align: center; color: var(--muted); font-size: .85rem; margin-top: .4rem; }

/* ---------- 7. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font: inherit; font-size: .92rem; cursor: pointer;
  padding: .5rem .95rem; border-radius: 10px;
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { font-size: .8rem; padding: .22rem .65rem; border-radius: 8px; }
.btn-back { margin-bottom: 1rem; }
.quick-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* Themen-Übersicht */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.topic-card { display: flex; flex-direction: column; gap: .5rem; }
.topic-card h2 { font-size: 1.05rem; }
.topic-card .btn { align-self: flex-start; margin-top: auto; }

/* ---------- 8. Aufgaben ---------- */
.task {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
  padding: 1rem; margin: .8rem 0;
}
.task-head { display: flex; align-items: center; gap: .55rem; margin-bottom: .35rem; }
.task-num { font-weight: 700; color: var(--accent); }
.task-q p { margin: .3rem 0; }
.task-answer-label { display: block; font-size: .88rem; color: var(--muted); margin-top: .55rem; }
.task-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; }

.task-answer, select.quiz-match-select, input.glossary-search {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  padding: .55rem .7rem;
}
.task-answer { resize: vertical; min-height: 90px; margin-top: .25rem; }
.task-answer:focus, select.quiz-match-select:focus, input.glossary-search:focus { border-color: var(--accent); }

.task-extra { margin-top: .6rem; padding: .7rem .95rem; border-radius: 10px; font-size: .95rem; }
.task-hint { background: var(--hint-bg); border: 1px dashed var(--accent); }
.task-solution { background: var(--sol-bg); border: 1px solid var(--ok-border); }
.task-extra p { margin: .3rem 0; }

/* Schwierigkeits-Badges */
.badge { font-size: .74rem; font-weight: 600; padding: .12rem .6rem; border-radius: 999px; white-space: nowrap; }
.badge-easy   { background: #dcfce7; color: #166534; }
.badge-medium { background: #dbeafe; color: #1e40af; }
.badge-hard   { background: #fee2e2; color: #991b1b; }

/* ---------- 9. Quiz ---------- */
.quiz-q {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
  padding: 1rem; margin: .8rem 0;
}
.quiz-q.is-ok  { border-color: var(--ok-border); }
.quiz-q.is-bad { border-color: var(--bad-border); }
.quiz-q-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.quiz-q-head h3 { margin: 0 0 .55rem; font-size: 1rem; }

fieldset.quiz-options { border: none; margin: 0; padding: 0; min-inline-size: 0; }
fieldset.quiz-options[disabled] .quiz-option { opacity: .6; }
.quiz-option {
  display: flex; align-items: flex-start; gap: .55rem;
  padding: .45rem .65rem; margin: .3rem 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.quiz-option:hover { border-color: var(--accent); }
.quiz-option input { accent-color: var(--accent); margin-top: .3rem; }
.quiz-multi-hint { font-size: .84rem; color: var(--muted); margin: .45rem 0 .2rem; }
.quiz-check { margin-top: .65rem; }

.quiz-match-row { display: flex; align-items: center; gap: .75rem; margin: .45rem 0; }
.quiz-match-left { flex: 1; font-weight: 600; }

.quiz-feedback { border-radius: 10px; padding: .7rem .95rem; margin-top: .65rem; }
.fb-ok   { background: var(--ok-bg);   border: 1px solid var(--ok-border);   color: var(--ok-text); }
.fb-bad  { background: var(--bad-bg);  border: 1px solid var(--bad-border);  color: var(--bad-text); }
.fb-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }
.fb-verdict { margin: 0 0 .3rem; font-weight: 700; }
.quiz-feedback p { margin: .25rem 0; }

.quiz-result {
  margin-top: .9rem; padding: 1rem 1.1rem;
  background: var(--accent-soft);
  border: 1px solid var(--border-strong); border-radius: 12px;
}
.quiz-result h3 { margin: 0 0 .4rem; }

/* ---------- 9a. Glossar ---------- */
.glossary-count { font-size: .85rem; margin: .5rem 0 .2rem; }
.glossary-letter {
  font-size: 1rem; font-weight: 700; color: var(--accent);
  border-bottom: 2px solid var(--accent-soft);
  margin: 1.1rem 0 .3rem; padding-bottom: .15rem;
}
.glossary-entry { padding: .55rem 0 .65rem; border-bottom: 1px dashed var(--border); }
.glossary-entry:last-child { border-bottom: none; }
.glossary-term { font-weight: 700; color: var(--accent); }
.glossary-desc { margin: .1rem 0 .3rem; }
.glossary-meta { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.glossary-src { font-size: .78rem; color: var(--muted); font-style: italic; }

/* ---------- 9b. Downloads & Tools (NEU) ---------- */
.dl-os-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1.1rem; }
.dl-os-tab {
  font: inherit; font-size: .95rem; cursor: pointer;
  padding: .5rem 1.1rem; border-radius: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
}
.dl-os-tab:hover { border-color: var(--accent); background: var(--accent-soft); }
.dl-os-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .9rem; }

.dl-card {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .9rem 1rem;
  box-shadow: var(--shadow);
}
.dl-name { margin: 0 0 .25rem; font-size: 1rem; }
.dl-name a { color: var(--accent); text-decoration: none; }
.dl-name a:hover { text-decoration: underline; }
.dl-card p { margin: 0 0 .55rem; font-size: .9rem; }
.dl-card .term-box { margin-top: auto; }

.dl-batch { margin: 0 0 1rem; }
.dl-batch-label { font-weight: 600; font-size: .9rem; margin: 0 0 .3rem; }

.dl-intro { margin: 0 0 1rem; }

/* Terminal-Fenster mit Kopieren-Button */
.term-box {
  display: flex; align-items: stretch;
  background: #0d1424;
  border: 1px solid #2a3a58;
  border-radius: 10px; overflow: hidden;
}
[data-theme="dark"] .term-box { border-color: var(--border-strong); }
.term-box pre {
  flex: 1; min-width: 0; margin: 0;
  padding: .5rem .7rem; overflow-x: auto;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: .84rem; line-height: 1.5; color: #dbe7ff;
  white-space: pre;
}
.term-prompt { color: #6ee7a0; font-weight: 700; user-select: none; }
.term-copy {
  flex-shrink: 0; border: none; cursor: pointer;
  font: inherit; font-size: .78rem; font-weight: 600;
  padding: .45rem .7rem;
  background: rgba(255, 255, 255, .07);
  color: #dbe7ff;
  border-left: 1px solid rgba(255, 255, 255, .14);
}
.term-copy:hover { background: rgba(255, 255, 255, .16); }
.term-copy.done { background: #14532d; color: #bbf7d0; }
.term-copy:focus-visible { outline: 3px solid #8ab6fb; outline-offset: -3px; }

/* ---------- 9c. Downloads: Suche & Lernfeld-Verknüpfung (NEU) ---------- */
.dl-toolbar { margin: 0 0 1.2rem; }
.dl-search {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  padding: .55rem .75rem;
}
.dl-search:focus { border-color: var(--accent); }
.dl-count { font-size: .85rem; margin: .4rem 0 0; }
.dl-empty {
  margin: .5rem 0 0; font-size: .9rem; padding: .55rem .85rem;
  border-radius: 10px; background: var(--bad-bg);
  border: 1px solid var(--bad-border); color: var(--bad-text);
}
.dl-hidden { display: none !important; }

/* Blinken beim Direktsprung aus einem Lernfeld */
.dl-card.dl-flash, .dl-batch.dl-flash { animation: dl-flash 1.3s ease-out 2; }
@keyframes dl-flash {
  0%, 55% { box-shadow: 0 0 0 4px var(--accent); }
  100%    { box-shadow: var(--shadow); }
}

/* Tool-Chips in der Lernfeld-Übersicht */
.lf-tools { display: flex; flex-wrap: wrap; gap: .5rem; }
.lf-tool-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  font: inherit; font-size: .87rem; cursor: pointer;
  padding: .4rem .85rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong);
}
.lf-tool-chip:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Lernfeld-Chips innerhalb der Tool-Karten */
.dl-lf-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.dl-lf-chip {
  font: inherit; font-size: .74rem; cursor: pointer;
  padding: .16rem .6rem; border-radius: 999px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.dl-lf-chip:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- 10. Scroll-to-top & Footer ---------- */
.scroll-top {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 40;
  width: 46px; height: 46px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.25rem;
  box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
.scroll-top.visible { opacity: 1; visibility: visible; transform: none; }
.scroll-top:hover { background: var(--accent-strong); }

.footer {
  margin-top: auto; padding: 1.1rem;
  text-align: center; color: var(--muted); font-size: .85rem;
  border-top: 1px solid var(--border); background: var(--surface);
}

/* ---------- 11. Mobil ---------- */
@media (max-width: 920px) {
  .menu-toggle { display: inline-flex; }
  .main-nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-height: 65vh;
    overflow-y: auto;
    padding: .5rem 0;
  }
  .main-nav.open { display: block; }
  #nav-list { flex-direction: column; overflow: visible; padding: 0 .6rem; }
  .page-title { font-size: 1.3rem; }
  .card { padding: 1rem; }
  .subnav-chip { font-size: .82rem; }
  .brand { font-size: .95rem; }
  .search-toggle { padding: .4rem .55rem; }
}
