:root {
  --bg: #0b1220;
  --bg-2: #0f1a2e;
  --card: #121f36;
  --card-2: #172742;
  --line: #22355a;
  --text: #e6edf7;
  --muted: #8ea0bf;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --arr: #22c55e;
  --dep: #f97316;
  --gnd: #a78bfa;
  --over: #64748b;
  --gold: #fbbf24;
  --gold-2: #f59e0b;
  --red: #ef4444;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

/* Hell: fest gewählt oder per Systemeinstellung (data-theme setzt theme.js / das Skript im <head>) */
:root[data-theme='light'] {
  --bg: #eef3fa;
  --bg-2: #e3ebf6;
  --card: #ffffff;
  --card-2: #f4f7fc;
  --line: #d5deec;
  --text: #0f1b2d;
  --muted: #5b6b85;
  --over: #94a3b8;
  --shadow: 0 8px 24px rgba(15, 27, 45, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #eef3fa;
    --bg-2: #e3ebf6;
    --card: #ffffff;
    --card-2: #f4f7fc;
    --line: #d5deec;
    --text: #0f1b2d;
    --muted: #5b6b85;
    --over: #94a3b8;
    --shadow: 0 8px 24px rgba(15, 27, 45, .08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, .12), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(167, 139, 250, .10), transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.wrap { width: min(1280px, 100% - 32px); margin-inline: auto; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); }
section { margin-block: 28px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  font-family: var(--mono); font-weight: 700; font-size: .95rem;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff; padding: 6px 9px; border-radius: 10px; letter-spacing: .05em;
}
.brand-text { font-weight: 800; font-size: 1.1rem; display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 500; font-size: .72rem; color: var(--muted); }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 500; font-size: .92rem; }
.nav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.clock { font-family: var(--mono); font-size: .82rem; text-align: right; }
.clock-label { color: var(--muted); font-size: .7rem; }

/* Hero */
.hero { display: grid; grid-template-columns: 1.1fr 1.4fr; gap: 24px; align-items: center; margin-top: 32px; }
.hero h1 { font-size: clamp(1.8rem, 3.4vw, 2.6rem); font-weight: 800;
  background: linear-gradient(90deg, var(--text), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 10px 0 0; max-width: 52ch; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.kpi-val { font-size: 1.9rem; font-weight: 800; font-family: var(--mono); }
.kpi-lbl { font-size: .78rem; color: var(--muted); }
.kpi-gold { border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.kpi-gold .kpi-val { color: var(--gold); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }
.pill { font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.pill.vfr { color: var(--arr); border-color: var(--arr); }
.pill.mvfr { color: var(--accent); border-color: var(--accent); }
.pill.ifr { color: var(--red); border-color: var(--red); }
.pill.lifr { color: #e879f9; border-color: #e879f9; }

/* Runway */
.runway-visual { color: var(--accent); }
#runway-svg { width: 100%; height: auto; }
.rwy { fill: #334155; }
.rwy-center { stroke: #e2e8f0; stroke-width: 2; stroke-dasharray: 12 10; }
.rwy-num { fill: #fff; font-family: var(--mono); font-weight: 700; font-size: 13px; }
.rwy-arrow path { stroke: var(--arr); fill: none; stroke-width: 4; color: var(--arr); }
.wind-arrow line { stroke: var(--accent); stroke-width: 3; }
.wind-arrow text { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.runway-text { font-weight: 600; margin: 8px 0 4px; }
.runway-text b { color: var(--arr); font-family: var(--mono); font-size: 1.2rem; }

/* Wetter */
.wx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.wx-grid > div { display: flex; flex-direction: column; }
.span-2 { grid-column: span 2; }
.wx-lbl { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.wx-val { font-weight: 700; font-size: 1.05rem; }
.metar { display: block; margin-top: 14px; font-family: var(--mono); font-size: .78rem; color: var(--muted); background: var(--card-2); padding: 10px; border-radius: 10px; word-break: break-word; }
.light-tip { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--gold) 12%, transparent); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); font-size: .9rem; }

/* Live */
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .88rem; font-weight: 600; padding: 7px 12px; border-radius: 9px; cursor: pointer; }
.seg button.active { background: var(--accent-2); color: #fff; }
.btn { font: inherit; font-size: .88rem; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.on { border-color: var(--gold); color: var(--gold); }
.btn-ghost { margin-top: 12px; width: 100%; }


.live-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 40px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.ac {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  border-left: 4px solid var(--over);
  animation: pop .3s ease;
}
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.ac.ph-approach, .ac.ph-inbound { border-left-color: var(--arr); }
.ac.ph-departure { border-left-color: var(--dep); }
.ac.ph-ground { border-left-color: var(--gnd); }
.ac.ph-local { border-left-color: var(--accent); }
.ac-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.ac-reg { font-family: var(--mono); font-weight: 700; font-size: 1.35rem; letter-spacing: .02em; }
.ac-reg a { color: inherit; }
.ac-type { font-size: .88rem; color: var(--muted); }
.ac-op { font-size: .82rem; color: var(--muted); }
.phase { font-size: .72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.phase.ph-approach, .phase.ph-inbound { color: var(--arr); border-color: var(--arr); }
.phase.ph-departure { color: var(--dep); border-color: var(--dep); }
.phase.ph-ground { color: var(--gnd); border-color: var(--gnd); }
.phase.ph-local { color: var(--accent); border-color: var(--accent); }
.ac-data { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ac-data div { background: var(--card-2); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; }
.ac-data span { font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ac-data b { font-family: var(--mono); font-size: .9rem; }
.ac-visits { display: flex; align-items: center; gap: 10px; font-size: .86rem; }
.visit-count { white-space: nowrap; font-family: var(--mono); font-weight: 700; font-size: 1.05rem; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); padding: 4px 10px; border-radius: 10px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line); }
.tag.hl { color: #e879f9; border-color: #e879f9; }
.tag.mil { color: #84cc16; border-color: #84cc16; }
.tag.rare { color: var(--accent); border-color: var(--accent); }
.tag.sq { color: var(--red); border-color: var(--red); }

/* Erstbesuch: normale Karte, nur goldene Kante und Markierung */
.ac.first { border-left-color: var(--gold); }
.ac.first .visit-count { background: var(--gold); color: #1c1300; }
.tag.first { color: var(--gold); border-color: var(--gold); }


/* Ranglisten */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; background: var(--card-2); }
.rank .r-reg { font-family: var(--mono); font-weight: 700; min-width: 80px; }
.rank .r-info { color: var(--muted); font-size: .85rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .r-val { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.rank li.none { color: var(--muted); justify-content: center; }

/* Tabelle */
#db-search { font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); min-width: min(320px, 100%); }
#db-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.table-wrap { overflow-x: auto; }
.db-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.db-table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.db-table th.sorted::after { content: " ▾"; }
.db-table th.sorted.asc::after { content: " ▴"; }
.db-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.db-table tr:hover td { background: var(--card-2); }
.db-table .num { text-align: right; font-family: var(--mono); font-weight: 700; }
.db-table td.reg { font-family: var(--mono); font-weight: 700; }

/* Infos */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .92rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.spots { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: .92rem; }
.links-card { margin-top: 16px; }
.links { display: flex; flex-wrap: wrap; gap: 10px; }
.links a { padding: 8px 14px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); font-weight: 600; font-size: .88rem; }
.links a:hover { border-color: var(--accent); text-decoration: none; }

.footer { border-top: 1px solid var(--line); margin-top: 40px; padding: 24px 0 40px; color: var(--muted); font-size: .82rem; }

/* Toasts */
.toast-stack { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; z-index: 100; max-width: min(380px, calc(100% - 32px)); }
.toast { background: var(--card); border: 2px solid var(--gold); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); animation: pop .3s ease; }
.toast b { color: var(--gold); }

/* Responsive */
@media (max-width: 1100px) {
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .nav { display: none; }
  .clock { margin-left: auto; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .live-list { grid-template-columns: 1fr; }
  .ac-data { grid-template-columns: repeat(2, 1fr); }
  .seg button { padding: 7px 9px; font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}

.db-note { margin-top: 4px; max-width: 70ch; }

/* ---------- Vorhersage (TAF) ---------- */
.taf-card { margin-top: 16px; }
.taf-table td { white-space: nowrap; }
.taf-table td.muted { white-space: normal; }

/* ---------- Ereignisse ---------- */
.events-card { margin-top: 16px; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 92px 120px 90px 1fr; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.ev:last-child { border-bottom: 0; }
.ev-time { color: var(--muted); font-size: .82rem; }
.ev-kind { font-weight: 700; }
.ev-goaround .ev-kind { color: var(--dep); }
.ev-training .ev-kind { color: var(--accent); }
.ev-emergency .ev-kind { color: var(--red); }
.ev-first .ev-kind { color: var(--gold); }
.ev-reg { font-family: var(--mono); font-weight: 700; color: var(--text); }
.tag.ev-tag { color: var(--dep); border-color: var(--dep); }
.tag.ev-tag.emergency { color: var(--red); border-color: var(--red); }

/* ---------- Flugplan ---------- */
.grid-2 > *, .grid-3 > * { min-width: 0; }
.sched .card { padding-bottom: 8px; }
.sched-table td { vertical-align: top; }
.sched-table td b { font-family: var(--mono); }
.sched-table tr.canceled td { opacity: .5; text-decoration: line-through; }
.sched-table td.num a { color: var(--accent); font-weight: 700; }
.tag.first { color: var(--gold); border-color: var(--gold); }
.tag.spotted { color: var(--arr); border-color: var(--arr); }

/* ---------- Datenbank: Logbuch-Filter ---------- */
.db-tools { display: flex; gap: 8px; flex-wrap: wrap; }
#db-filter { font: inherit; font-size: .9rem; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); }
.db-table td.reg a { cursor: pointer; }

/* ---------- Statistik ---------- */
.stat-kpis { margin-bottom: 16px; }
.cols { display: flex; align-items: flex-end; gap: 2px; height: 150px; padding-top: 8px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; outline: none; }
.col-bar { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.col-lbl { font-size: .66rem; color: var(--muted); text-align: center; height: 14px; margin-top: 4px; font-family: var(--mono); }
.col:hover .col-bar, .col:focus .col-bar { filter: brightness(1.2); }
.col:hover::after, .col:focus::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: .75rem; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 5; pointer-events: none;
}
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: 150px 1fr 48px; gap: 10px; align-items: center; font-size: .88rem; }
.bars-lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars-track { height: 10px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.bars-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.bars-val { text-align: right; font-weight: 700; }
.chip-links { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-link { font-size: .85rem; padding: 6px 10px; border-radius: 8px; background: var(--card-2); border: 1px solid var(--line); color: var(--text); font-family: var(--mono); }
.chip-link:hover { border-color: var(--accent); text-decoration: none; }
.logbook { display: flex; flex-direction: column; gap: 10px; }
.logbook .kpi-val { display: block; }
.logbook-actions { display: flex; gap: 8px; }

/* ---------- Detailseite ---------- */
.detail { width: min(640px, calc(100% - 24px)); max-height: calc(100vh - 40px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 0; box-shadow: var(--shadow); }
.detail::backdrop { background: rgba(5, 10, 20, .6); }
.detail-close { position: absolute; top: 10px; right: 12px; z-index: 2; width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 1.3rem; cursor: pointer; }
#detail-body { padding: 0 20px 20px; }
.detail-photo { margin: 0 -20px 16px; background: var(--card-2); min-height: 80px; }
.detail-photo img { display: block; width: 100%; max-height: 340px; object-fit: cover; }
.photo-ph { padding: 30px 20px; text-align: center; }
.photo-credit { font-size: .72rem; color: var(--muted); padding: 6px 20px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-head h2 { font-size: 1.8rem; }
.detail-head p { color: var(--muted); margin-top: 4px; }
.detail-live { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--card-2); font-size: .9rem; }
.detail .facts { margin: 16px 0; }
.detail h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.detail-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: .9rem; }
.detail-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.detail-list .mono { font-size: .82rem; margin-right: 8px; }
.detail-links { margin-top: 16px; }

@media (max-width: 560px) {
  .ev { grid-template-columns: 70px 1fr; }
  .ev-text { grid-column: 1 / -1; }
  .bars li { grid-template-columns: 100px 1fr 40px; }
  .detail-head { flex-direction: column; }
}

/* ---------- Umschalter Hell / System / Dunkel ---------- */
.theme-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.theme-switch button { width: 30px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; padding: 0; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button.active { background: var(--accent-2); color: #fff; }
.theme-switch svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lang-switch button { width: 32px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; }
@media (max-width: 900px) { .lang-switch { margin-left: auto; } .clock { margin-left: 0; } }
@media (max-width: 480px) { .brand-text { display: none; } .topbar-inner { gap: 10px; } }
