/* ═══════════════════════════════════════════════════════════════
   KI-Briefing — Styles
   Eine responsive PWA: schmal = iPhone-Layout, breit = Mac-Layout.
   Theme folgt dem System, manueller Umschalter via :root[data-theme].
   ═══════════════════════════════════════════════════════════════ */

/* ── Design-Tokens (Hell = Default) ───────────────────────────── */
:root {
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f7f7f3;
  --card: #fdfdfa;
  --ink: #15212e;
  --muted: #5b6572;
  --line: #e1e2da;
  --red: #c33a2c;
  --blue: #2a5ca8;
  --amber-ink: #8a5a10;
  --amber-bg: #f6e9cd;
  --chip: #f0f1ea;
  --reddit: #c05a2e;
  --shadow: 0 18px 50px rgba(23, 34, 47, 0.16);
  --modal-shadow: 0 30px 80px rgba(10, 16, 24, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a121d;
    --card: #101b29;
    --ink: #e9eef4;
    --muted: #8b98a9;
    --line: #223042;
    --red: #f2604f;
    --blue: #74a4e8;
    --amber-ink: #f0b45c;
    --amber-bg: rgba(240, 180, 92, 0.14);
    --chip: #182535;
    --reddit: #e8804d;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    --modal-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  }
}

/* Manueller Umschalter — überschreibt den Media-Query in beide Richtungen. */
:root[data-theme="light"] {
  --bg: #f7f7f3;
  --card: #fdfdfa;
  --ink: #15212e;
  --muted: #5b6572;
  --line: #e1e2da;
  --red: #c33a2c;
  --blue: #2a5ca8;
  --amber-ink: #8a5a10;
  --amber-bg: #f6e9cd;
  --chip: #f0f1ea;
  --reddit: #c05a2e;
  --shadow: 0 18px 50px rgba(23, 34, 47, 0.16);
  --modal-shadow: 0 30px 80px rgba(10, 16, 24, 0.28);
}
:root[data-theme="dark"] {
  --bg: #0a121d;
  --card: #101b29;
  --ink: #e9eef4;
  --muted: #8b98a9;
  --line: #223042;
  --red: #f2604f;
  --blue: #74a4e8;
  --amber-ink: #f0b45c;
  --amber-bg: rgba(240, 180, 92, 0.14);
  --chip: #182535;
  --reddit: #e8804d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --modal-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

/* ── Reset ────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 4px; }

/* ── Gemeinsame Bausteine ─────────────────────────────────────── */
.wordmark {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
}
.wordmark .dot { color: var(--red); }

.a-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.a-label .sq { width: 8px; height: 8px; display: inline-block; flex: none; }
.a-label .count {
  margin-left: auto;
  letter-spacing: 0.03em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2.5px 8px;
  white-space: nowrap;
}
.chip.more { border-style: dashed; }

.community-note { font-family: var(--mono); font-size: 11px; color: var(--blue); }

/* Klickbare Meldungen */
.clickable { cursor: pointer; transition: border-color 0.15s ease, color 0.15s ease; }
.clickable:hover { border-color: var(--red); }
.clickable:hover h3 { color: var(--red); }
.clickable:hover h3::after { content: " ›"; color: var(--red); }

/* ═══ Kopfzeile ═══════════════════════════════════════════════ */
.app-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: calc(env(safe-area-inset-top) + 14px) 20px 12px;
  border-bottom: 2px solid var(--ink);
}
.app-head .wordmark { font-size: 21px; }
.head-date {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.head-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.pill {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
  border: 1px solid transparent;
  order: 3;
  flex-basis: 100%;
}
.pill.fresh {
  color: var(--amber-ink);
  background: var(--amber-bg);
  border-color: color-mix(in srgb, var(--amber-ink) 35%, transparent);
}
.pill.stale {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 12%, transparent);
  border-color: color-mix(in srgb, var(--red) 45%, transparent);
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }

.head-nav { display: none; gap: 4px; }
.nav-btn {
  font-size: 13.5px;
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--muted);
}
.nav-btn.active { background: var(--ink); color: var(--bg); font-weight: 600; }

.status-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
}

/* Weiche Fehlermeldung (bei bereits geladenem Inhalt) */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--red) 12%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  font-size: 13px;
}
.error-banner-msg { flex: 1; }
.error-banner-retry {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 45%, transparent);
  border-radius: 6px;
  padding: 4px 10px;
}
.error-banner-dismiss { color: var(--muted); font-size: 14px; line-height: 1; padding: 2px 6px; }

/* ═══ Filter-Chips (nur schmal) ═══════════════════════════════ */
.filter-chips {
  display: flex;
  gap: 8px;
  padding: 12px 20px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.fchip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  flex: none;
}
.fchip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }

/* ═══ Zustände (Laden / Fehler) ═══════════════════════════════ */
.state-panel {
  max-width: 460px;
  margin: 64px auto;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14.5px;
}
.state-title { font-family: var(--serif); font-size: 20px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.state-msg { margin-bottom: 18px; }
.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  margin-bottom: 14px;
  border: 3px solid var(--line);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.retry-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--bg);
  background: var(--ink);
  border-radius: 8px;
  padding: 10px 20px;
}
.retry-btn:hover { opacity: 0.9; }

/* ═══ Body-Layout ═════════════════════════════════════════════ */
#view-today, #view-archive { padding: 0 20px calc(96px + env(safe-area-inset-bottom)); }

.older-banner {
  margin: 14px 0 0;
  padding: 10px 14px;
  border: 1px dashed color-mix(in srgb, var(--amber-ink) 45%, var(--line));
  border-radius: 8px;
  background: var(--amber-bg);
  color: var(--amber-ink);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.older-banner button {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--amber-ink);
  border: 1px solid color-mix(in srgb, var(--amber-ink) 45%, transparent);
  border-radius: 6px;
  padding: 4px 10px;
}

.app-body { display: block; }
.app-main { padding-top: 16px; }

/* Top-Meldungen */
.top-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 12px; }
.top-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 15px 15px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.top-card .rank {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--red);
  line-height: 1;
}
.top-card h3, .story h3 {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -0.005em;
  text-wrap: balance;
}
.top-card h3 { font-size: 17.5px; }
.top-card .summary, .story .summary { color: var(--muted); font-size: 13px; line-height: 1.5; }
.top-card .chips { margin-top: 4px; }

.why { font-size: 13px; line-height: 1.45; }
.why b {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--red);
  font-weight: 600;
  margin-right: 6px;
}

/* Rubriken */
.rubrik-grid { display: grid; grid-template-columns: 1fr; gap: 26px; margin-top: 26px; }
.rubrik { display: flex; flex-direction: column; gap: 12px; }
.rubrik .a-label { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.story { display: flex; flex-direction: column; gap: 6px; }
.story + .story { border-top: 1px dotted var(--line); padding-top: 13px; }
.story h3 { font-size: 15.5px; }

/* Statuszeile */
.statusline {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

/* ═══ Seitenleiste / Signale ══════════════════════════════════ */
.app-rail { display: flex; flex-direction: column; gap: 24px; margin-top: 28px; }
.rail-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Archiv-Vorschau nur im breiten Rail; schmal via Tab-Leiste erreichbar. */
.rail-archive { display: none; }

.reddit-row, .gh-row, .archiv-row { display: flex; flex-direction: column; gap: 3px; text-decoration: none; }
.reddit-row + .reddit-row, .gh-row + .gh-row, .archiv-row + .archiv-row {
  border-top: 1px dotted var(--line);
  padding-top: 11px;
}
.reddit-row:hover .t, .gh-row:hover .t { color: var(--red); }

.reddit-row .sub { font-family: var(--mono); font-size: 10.5px; color: var(--reddit); font-weight: 600; }
.reddit-row .t, .gh-row .t { font-size: 13px; line-height: 1.35; }
.reddit-row .t { font-weight: 600; }
.reddit-row .m, .gh-row .m, .archiv-row .n {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.gh-row .repo { font-family: var(--mono); font-size: 11px; color: var(--blue); font-weight: 600; }

.archiv-row { flex-direction: row; justify-content: space-between; align-items: baseline; font-size: 13px; }
.archiv-row .d { font-weight: 600; }
.archiv-row:hover .d { color: var(--red); }
.archiv-row .n { text-transform: uppercase; }

/* ═══ Archiv-Ansicht ══════════════════════════════════════════ */
.archive-title { font-family: var(--serif); font-size: 26px; font-weight: 700; margin-top: 20px; }
.archive-sub { color: var(--muted); font-size: 14px; margin-top: 4px; margin-bottom: 20px; }
.archive-list { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.15s ease;
}
.archive-item:hover { border-color: var(--red); }
.archive-item .d { font-size: 15px; font-weight: 600; }
.archive-item:hover .d { color: var(--red); }
.archive-item .n {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.archive-empty { color: var(--muted); font-size: 14px; }

/* ═══ Untere Tab-Leiste (nur schmal) ══════════════════════════ */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 10px 30px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.tab.active { color: var(--red); font-weight: 600; }
.tab svg { display: block; }

/* ═══ Detail-Ansicht ══════════════════════════════════════════ */
.detail {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  opacity: 1;
  visibility: hidden;
  pointer-events: none;
}
.detail.open { visibility: visible; pointer-events: auto; }
body.detail-lock { overflow: hidden; }

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 24, 0.5);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.detail.open .detail-backdrop { opacity: 1; }

/* Schmal = eingeschobene Vollbild-Seite */
.detail-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s ease;
}
.detail.open .detail-panel { transform: none; }

.detail-close { display: none; }
.detail-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.detail-back { color: var(--blue); font-size: 15px; padding: 4px 8px; }
.detail-kicker {
  margin-left: auto;
  margin-right: auto;
  transform: translateX(-24px);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.detail-body { padding: 18px 20px calc(60px + env(safe-area-inset-bottom)); }

/* Detail-Inhalt */
.d-eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 10px;
}
.detail-body h2 {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.18;
  font-weight: 700;
  letter-spacing: -0.005em;
  text-wrap: balance;
  margin-bottom: 8px;
}
.d-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-sec { margin-top: 22px; }
.d-sec-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--red);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 12px;
}
.d-sec p { font-size: 13.5px; line-height: 1.6; }
.d-sec p + p { margin-top: 10px; }

.d-src { display: grid; grid-template-columns: 1fr; gap: 3px; padding: 9px 0; }
.d-src + .d-src { border-top: 1px dotted var(--line); }
.d-src .chip { justify-self: start; }
.d-src p { font-size: 13px; line-height: 1.5; color: var(--muted); }

.d-links { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.d-link {
  font-size: 13.5px;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.d-link::after { content: " ↗"; font-size: 11px; }

/* ═══ Breit (≥ 900px) = Mac-Layout ════════════════════════════ */
@media (min-width: 900px) {
  .app { max-width: 1180px; margin: 0 auto; }

  .app-head { gap: 22px; padding: 18px 32px; }
  .app-head .wordmark { font-size: 26px; }
  .head-date { font-size: 12px; }
  .pill { order: 0; flex-basis: auto; }
  .head-nav { display: flex; }

  .status-note, .error-banner { padding-left: 32px; padding-right: 32px; }
  .filter-chips { display: none; }

  #view-today, #view-archive { padding: 0 32px 40px; }

  .app-body {
    display: grid;
    grid-template-columns: 1fr 292px;
    gap: 36px;
    padding-top: 12px;
  }
  .app-main { padding-top: 0; }

  .top-grid { grid-template-columns: 1.45fr 1fr 1fr; gap: 20px; margin-top: 16px; }
  .top-card { padding: 18px 18px 16px; gap: 10px; }
  .top-card .rank { font-size: 30px; }
  .top-card h3 { font-size: 18px; }
  .top-card.lead h3 { font-size: 23px; }
  .top-card .chips { margin-top: auto; }

  .rubrik-grid { grid-template-columns: 1fr 1fr; gap: 30px 34px; margin-top: 34px; }
  .story h3 { font-size: 16.5px; }

  .statusline { flex-direction: row; flex-wrap: wrap; gap: 18px; margin-top: 34px; }

  .app-rail { margin-top: 0; gap: 30px; }
  .rail-archive { display: flex; }

  .tabbar { display: none; }

  /* Detail = zentriertes Overlay-Modal */
  .detail { align-items: center; justify-content: center; }
  .detail-panel {
    width: min(680px, 88%);
    height: auto;
    max-height: 86vh;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--modal-shadow);
    transform: translateY(12px);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .detail.open .detail-panel { transform: none; opacity: 1; }

  .detail-head { display: none; }
  .detail-close {
    display: block;
    position: sticky;
    top: 0;
    float: right;
    margin: 22px 24px -10px 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--chip);
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
  }
  .detail-close:hover { color: var(--red); border-color: var(--red); }
  .detail-body { padding: 30px 34px 26px; }
  .detail-body h2 { font-size: 25px; }
  .detail-body .d-sec p { font-size: 14px; }
  .d-src { grid-template-columns: 118px 1fr; gap: 12px; align-items: start; }
}

/* Mittelbreite Fenster: Rubriken/Top etwas luftiger, aber noch einspaltig-freundlich */
@media (min-width: 620px) and (max-width: 899px) {
  .top-grid { grid-template-columns: 1fr 1fr; }
  .rubrik-grid { grid-template-columns: 1fr 1fr; }
}

/* ═══ Reduzierte Bewegung ═════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .detail-panel, .detail-backdrop, .clickable, .archive-item, .retry-btn { transition: none !important; }
  .spinner { animation-duration: 1.6s; }
}
