/* Darstellung & Barrierefreiheit – ergänzt style.css.
   prefs.js setzt am <html>-Element:
     data-bg       light | warm | cool | dark | dim | black  (aufgelöst, auch bei „Automatisch“)
     data-scheme   light | dark
     data-contrast, data-underline, data-readable, data-motion, data-focus, data-tts, data-zoomed
     data-cards    compact | normal | large
   Die Akzentfarbe (--accent, --accent-text) setzt prefs.js direkt, weil sie je nach
   Hintergrund auf ausreichenden Kontrast nachgedunkelt bzw. aufgehellt wird. */

/* --- Hintergründe ------------------------------------------------------------- */

:root[data-bg="light"], [data-bg-preview="light"] {
  --bg: #f6f7f8; --surface: #ffffff; --text: #1c2026; --muted: #5f6873; --border: #dde1e6;
}
:root[data-bg="warm"], [data-bg-preview="warm"] {
  --bg: #f3ecdc; --surface: #fffaf0; --text: #2b2418; --muted: #675c48; --border: #e0d5bd;
}
:root[data-bg="cool"], [data-bg-preview="cool"] {
  --bg: #e8eef5; --surface: #f8fafc; --text: #172033; --muted: #526072; --border: #cbd5e2;
}
:root[data-bg="dark"], [data-bg-preview="dark"] {
  --bg: #12151a; --surface: #1b2027; --text: #e8ebef; --muted: #9aa4b0; --border: #2c333d;
}
:root[data-bg="dim"], [data-bg-preview="dim"] {
  --bg: #262b34; --surface: #30363f; --text: #eef0f3; --muted: #b0b8c3; --border: #454d59;
}
:root[data-bg="black"], [data-bg-preview="black"] {
  --bg: #000000; --surface: #0e0e10; --text: #f2f2f2; --muted: #a8a8a8; --border: #2b2b30;
}

:root[data-scheme="light"] {
  --eu-bg: #e8eefc; --eu-text: #1d3f8f;
  --deal-bg: #fff4d6; --deal-text: #7a4b00;
  --best-bg: #15803d; --best-text: #ffffff;
  color-scheme: light;
}
:root[data-scheme="dark"] {
  --eu-bg: #1c2b4d; --eu-text: #a9c2ff;
  --deal-bg: #4a3505; --deal-text: #ffd98a;
  --best-bg: #22c55e; --best-text: #05290f;
  color-scheme: dark;
}

/* Abzeichen und Hover-Flächen folgen der gewählten Akzentfarbe */
:root[data-bg] {
  --badge-bg: color-mix(in srgb, var(--accent) 14%, var(--surface));
  --badge-text: color-mix(in srgb, var(--accent) 70%, var(--text));
}

/* --- Hoher Kontrast ------------------------------------------------------------ */

:root[data-contrast][data-scheme="light"] {
  --bg: #ffffff; --surface: #ffffff; --text: #000000; --muted: #1f1f1f; --border: #000000;
}
:root[data-contrast][data-scheme="dark"] {
  --bg: #000000; --surface: #000000; --text: #ffffff; --muted: #e6e6e6; --border: #ffffff;
}
:root[data-contrast] :is(.card, .news, .info-list li, .criteria, .chip, .btn, .search input, .filters select) {
  border-width: 2px;
}
:root[data-contrast] .tab[aria-selected="true"] { text-decoration: underline; text-underline-offset: 0.3em; }

/* --- Links unterstreichen ------------------------------------------------------- */

:root:is([data-underline], [data-contrast]) a:not(.btn) { text-decoration: underline; text-underline-offset: 0.15em; }
:root:is([data-underline], [data-contrast]) :is(.card, .video__body, .news, .logo) a { text-decoration: none; }
:root:is([data-underline], [data-contrast]) :is(.card, .video__body, .news) h3 { text-decoration: underline; text-underline-offset: 0.15em; }

/* --- Lesefreundliche Schrift und Abstände (vgl. WCAG 1.4.12) ---------------------- */

:root[data-readable] body {
  font-family: Verdana, Tahoma, "Segoe UI", system-ui, sans-serif;
  line-height: 1.7;
  letter-spacing: 0.03em;
  word-spacing: 0.12em;
}
:root[data-readable] :is(p, li) { margin-bottom: 0.6em; }
:root[data-readable] .card h3 { font-weight: 600; }

/* --- Bewegung reduzieren -------------------------------------------------------- */

:root[data-motion] *, :root[data-motion] *::before, :root[data-motion] *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

/* --- Deutlicher Fokusrahmen ----------------------------------------------------- */

:root:is([data-focus], [data-contrast]) :focus-visible {
  outline: 3px solid var(--accent) !important;
  outline-offset: 3px !important;
}
/* .card schneidet mit overflow:hidden den Rahmen des Links ab */
:root:is([data-focus], [data-contrast]) .card:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }

/* --- Größe der Produktkacheln --------------------------------------------------- */

:root[data-cards="compact"] .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
:root[data-cards="compact"] .card__body { padding: 8px; }
:root[data-cards="large"] .grid { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 20px; }
:root[data-cards="large"] .card h3 { font-size: 1.05rem; }
:root[data-cards="large"] .price { font-size: 1.15rem; }

/* Mit Zoom bleibt auf schmalen Bildschirmen für zwei Spalten zu wenig Platz */
@media (max-width: 600px) {
  :root[data-zoomed]:not([data-cards="compact"]) .grid,
  :root[data-cards="large"] .grid { grid-template-columns: 1fr; }
}

/* --- Einstellungs-Knopf und -Panel ---------------------------------------------- */

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

.prefs-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
  cursor: pointer;
}
.prefs-toggle:hover { border-color: var(--accent); }
.prefs-toggle svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 600px) {
  .prefs-toggle { padding: 10px; }
  .prefs-toggle span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

.prefs {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, 100%);
  max-width: 100%;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgb(0 0 0 / 0.25);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.prefs::backdrop { background: rgb(0 0 0 / 0.45); }
.prefs__head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.prefs__head h2 { margin: 0; font-size: 1.1rem; }
.prefs__close {
  flex: none;
  width: 40px;
  height: 40px;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text);
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}
.prefs__body { padding: 4px 20px 28px; }
.prefs fieldset { margin: 22px 0 0; padding: 0; border: 0; min-width: 0; }
.prefs legend { padding: 0; margin-bottom: 10px; font-weight: 700; }
.prefs .muted { margin: 6px 0 0; }

.prefs-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.prefs-options--accent { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.prefs-options--cards { grid-template-columns: repeat(3, 1fr); }
.prefs-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  font-size: 0.8rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.prefs-option input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.prefs-option:hover { border-color: var(--muted); }
.prefs-option:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 700; }
/* Haken zusätzlich zur Farbe, damit die Auswahl nicht nur über Farbe erkennbar ist */
.prefs-option:has(input:checked)::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 6px;
  font-weight: 700;
  color: var(--accent);
}
.prefs-option:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

.bg-preview {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 40px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.bg-preview span { flex: 1; height: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 3px; }
.bg-preview--auto { padding: 0; gap: 0; }
.bg-preview--auto > div { flex: 1; height: 100%; padding: 6px; background: var(--bg); display: flex; align-items: flex-end; }

.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgb(127 127 127 / 0.35); }
.swatch--custom { background: conic-gradient(#ef4444, #f59e0b, #22c55e, #06b6d4, #6366f1, #d946ef, #ef4444); }
.prefs-custom { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 0.9rem; }
.prefs-custom input { width: 48px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; cursor: pointer; }

.prefs-row { display: flex; align-items: center; gap: 8px; }
.prefs-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.prefs-row output { min-width: 4.5ch; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.prefs-step {
  flex: none;
  width: 36px;
  height: 36px;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.prefs-label { display: block; margin: 14px 0 6px; font-size: 0.9rem; font-weight: 600; }

.prefs-check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.prefs-check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }
.prefs-check small { display: block; color: var(--muted); font-size: 0.8rem; }
.prefs select {
  width: 100%;
  padding: 8px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.prefs-tts-extra[hidden] { display: none; }
.prefs__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }

/* --- Vorleseleiste ------------------------------------------------------------ */

:root[data-tts] body { padding-bottom: 88px; }
.reader {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 32px);
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  transform: translateX(-50%);
}
.reader[hidden] { display: none; }
.reader .btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 999px; white-space: nowrap; }
.reader svg { width: 1em; height: 1em; fill: currentColor; }
.reader__status { padding: 0 10px; color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader__status:empty { display: none; }
@media (max-width: 480px) {
  .reader { left: 16px; right: 16px; justify-content: center; transform: none; }
  .reader__status { display: none; }
}

.is-reading { outline: 3px solid var(--accent) !important; outline-offset: 4px; border-radius: 6px; scroll-margin: 96px; }
