/* ----------------------------------------------------
   Grundlayout
---------------------------------------------------- */
:root {
  --bg-page: #46c8ff;
  --bg-panel: #80d9ff;
  --bg-soft: #48b9ea;

  --fg-main: #151515;
  --fg-muted: #373737;
  --fg-soft: #4b4b4b;
  --fg-suntitle: #f1870f;
  --fg-moontitle: #1c36ff;

  --border-soft: #eee;
  --shadow-panel: 0 2px 8px rgba(0,0,0,0.12);

  --moon-night: rgba(67,183,255,0.02); 
  --moon-light: rgba(217,244,255,0.5);
  --moon-eclipse-light: #ffffff;
  --moon-group-opacity: 0.35; /* Tag: Atmosphäre lüütet dure */
  --moon-night-opacity: 0.02; /* Tag: Struktur fast weg */
}

[data-theme="dark"] {
  --bg-page: #000000;
  --bg-panel: #0f0f0f;
  --bg-soft: #1a1a1a;

  --fg-main: #eaeaea;
  --fg-muted: #bdbdbd;
  --fg-soft: #888;
  --fg-suntitle: #f1c40f;
  --fg-moontitle: #b3eaff;

  --border-soft: #383838;
  --shadow-panel: 0 2px 12px rgba(0,0,0,0.6);

  --moon-night: #7b7b7b;
  --moon-light: #ffffff;
  --moon-eclipse-light: #ffffff;
  --moon-group-opacity: 1.0;  /* Nacht: Mond solide */
  --moon-night-opacity: 1.0;  /* Nacht: Struktur für Erdschein voll da */
}

body {
  background: var(--bg-page);
  color: var(--fg-main);
  transition: background 0.3s ease, color 0.3s ease;
}

.himmel-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: Arial, sans-serif;
}

.himmel-container h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--fg-main);
    margin: 0;
}

/* Die Server-Uhr im Desktop-Modus */
.server-live-clock {
    display: flex;
    flex-direction: column; /* Datum oben, Uhrzeit unten */
    align-items: center;
    text-align: center;
    font-family: monospace; /* Monospace verhindert ein "Zappeln" der Zahlen */
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: var(--fg-main);
    font-weight: 500;
}

#moonPanel-serverTime {
    font-size: 18px; /* Uhrzeit prominent */
    font-weight: 700;
    color: #0066cc; /* Deine Panel-Akzentfarbe */
}

#moonPanel-serverDate {
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: var(--fg-main);
}

.himmel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    margin-bottom: 16px;
}

.theme-switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.theme-wrapper {
    display: flex;
    align-items: center;
    gap: 10px; /* Abstand zwüsche Text und Schalter */
}

.theme-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--fg-muted); /* Dezent, demit s'H2 d'Hauptrolle bhaltet */
    text-transform: uppercase; /* Optional: wirkt oft edel bi söttige Labels */
    letter-spacing: 0.5px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-switch .slider {
  position: absolute;
  inset: 0;
  background: var(--bg-panel);
  border-radius: 999px;
  transition: background 0.25s ease;
  cursor: pointer;
}

.theme-switch .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.25s ease;
}

/* Dark Mode aktiv */
.theme-switch input:checked + .slider {
  background: #444;
}

.theme-switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* ----------------------------------------------------
   Panels
---------------------------------------------------- */
.panel {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 18px;
    box-shadow: var(--shadow-panel);
    margin-bottom: 20px;
    font-family: Arial, sans-serif;
}

.panel-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--fg-main);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-title img {
    height: 22px;
    width: auto;
}

/* ----------------------------------------------------
   Flexbox für Mond + Sonne
---------------------------------------------------- */
.himmel-top {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: stretch; /* NEU: Macht beide Panels gleich hoch */
    /* Zentrierung vo de Panels innerhalb vo de 1200px */
    max-width: 1000px;   /* Dini Wunsch-Breiti für d'Panels */
    margin: 0 auto;      /* DAS fixiert d'Links-Bündigkeit und schiebt alles i d'Mitti */
    width: 100%;         /* Sorgt defür, dass es bi chline Schirm nid starr blibt */
}

.mond-panel,
.sonnen-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 400px;
    /* Beidi Panels sölled im Container glich höch sii */
}

/* Container für d'Live-Wärt (vor dr Grafik) */
.mond-live,
.sonne-live {
    flex-grow: 1; /* Das füllt de hohli Ruum uf */
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* D'Zahle bliibed obe */
}

/* De Container, wo dr Canvas drin isch */
.mond-panel .graph-container, 
.sonnen-panel .graph-container {
    margin-top: auto;      /* Drückt alles nach unne */
    width: 100%;           /* Nutzt die ganzi Breiti */
    position: relative;
    line-height: 0;        /* Verhindert en "Gaischter-Abstand" unne am Canvas */
}
/* ---------------------------------------------------
   EINHEITLICHE INFO-TYPOGRAFIE (Mond + Sonne)
---------------------------------------------------- */
.moon-row,
.sun-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    margin-bottom: 4px;
    line-height: 1.25;
    font-size: 13px;
    color: var(--fg-main);
}

/* ----------------------------------------------------
   Mondbereich
---------------------------------------------------- */
.mond-main {
  display: flex;
  gap: 20px;
  align-items: center;
  border-radius: 10px;
  margin-bottom: 20px;
}

/* ----------------------------------------------------
   Simulator Container rächts (Zurück zur stabilen Version)
   ---------------------------------------------------- */
.moon-simulator-container {
  margin-bottom: 6px;
  display: inline-block;
  border-radius: 8px;
  transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1), filter 0.25s ease, box-shadow 0.25s ease;
  will-change: transform;
}

/* Visueller Effekt für Desktop-Hover UND den ersten mobilen Touch-Tap */
@media (hover: hover) and (pointer: fine) {
  .moon-simulator-container:hover {
    transform: translateY(-4px) scale(1.02);
    filter: brightness(1.1) drop-shadow(0 6px 12px rgba(0, 0, 0, 0.25));
  }
}

/* Das mobile Äquivalent: Triggert exakt denselben Effekt beim 1. Tippen */
.moon-simulator-container.touch-focused {
  transform: translateY(-4px) scale(1.02);
  filter: brightness(1.1) drop-shadow(0 6px 12px rgba(0, 102, 204, 0.35)); /* Kleiner blauer Astro-Glow als Touch-Indikator */
}

/* Haptisches Feedback beim tatsächlichen Auslösen (Klick / 2. Tap) */
.moon-simulator-container:active {
  transform: translateY(-1px) scale(0.99);
  filter: brightness(0.95);
  transition: transform 0.05s ease;
}

.simulator-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
}

.stats-box {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  font-size: 13px;
  margin-bottom: 6px;
}

/* 🌙 Dark Mode Fix für Texte */
[data-theme="dark"] .mond-label,
[data-theme="dark"] .erdschein-label {
    color: var(--fg-main);
}

/* --- Status-Klassen --- */
/* Neumond */
#moon-orient-svg.moon-new {
  opacity: 0.2;
}

#moonGraph {
    width: 100% !important;
    height: 200px;
    display: block;
    border: none;
}

/* --- 2. MOND SVG LOGIK (Zusammengefasst) --- */
/* Die Gruppe, die rotiert (Lichtseite) */
#moon-rotation-group {
  opacity: var(--moon-group-opacity);
  transform-origin: 0 0;
  transition: transform 2s ease-in-out, opacity 0.5s ease;
}

/* Die Nachtseite (Basis-NASA-Bild) */
#moon-night-layer {
  opacity: 0.02;
  filter: brightness(0.9) sepia(0.3) saturate(1.2); /* Tag-Default */
  transition: opacity 0.5s ease, filter 0.5s ease;
}

/* Spezial-Filter für d'Nachtsite im Dark Mode */
[data-theme="dark"] #moon-night-layer {
  filter: brightness(0.30) contrast(1.1) grayscale(0.2);
  opacity: 0.3;
}

/* Der Terminator (Masken-Pfad) */
#moon-mask-path {
  filter: blur(1px);
  transition: d 1.5s ease-in-out;
}

.moon-title {
    font-weight: 600;
    color: var(--fg-moontitle);
    margin-top: 10px;
    margin-bottom: 4px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-soft);
}

/* ----------------------------------------------------
   Sonnenbereich
---------------------------------------------------- */
.sun-icon {
    height: 22px;
}

#sunGraph {
    width: 100% !important;
    height: 200px;
    display: block;
    border: none;
}

.graph-container {
    margin: 0 auto;
    text-align: center;
    /* --- NEU: Rundi Egge hie asetze --- */
    border-radius: 12px;
    overflow: hidden; 
    position: relative; /* Wichtig für de suubere Schnitt */
    /* Zwingt de Browser de Inhalt suuber abzschneide (Fix für Canvas) */
    -webkit-mask-image: -webkit-radial-gradient(white, black);
}

/* Titel der Dämmerungsgruppen */
.sun-twilight-title {
    font-weight: 600;
    color: var(--fg-suntitle);
    margin-top: 10px;
    margin-bottom: 4px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-soft);
}

/* Gruppe leicht eingerückt */
.sun-twilight-group {
    margin-bottom: 0px;
}

/* --- Graph Tooltip Basis-Design --- */
#sunGraphTooltip, #moonGraphTooltip {
    display: none;
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 4000;
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
    /* Sanfter Übergang für de Sitenwechsel */
    transition: opacity 0.1s ease;
    width: 180px;           /* Fixi Breiti für alli Richtige (N bis SSW) */
    text-align: left;       /* Immer linksbündig, wie vo dir gwünscht */
    box-sizing: border-box; /* Wichtig bi fixer Breiti */
}

/* De Pfiil (Uusstülpig) */
#sunGraphTooltip::after, #moonGraphTooltip::after {
    content: "";
    position: absolute;
    top: 50%;
    margin-top: -6px; /* Zentriert de Pfiil vertikal */
    border-width: 6px;
    border-style: solid;
}

/* Tooltip isch RÄCHTS vo dr Linie -> Pfiil zeigt nach LINKS */
#sunGraphTooltip.right-side::after, #moonGraphTooltip.right-side::after {
    left: -12px;
    border-color: transparent rgba(0, 0, 0, 0.9) transparent transparent;
}

/* Tooltip isch LINKS vo dr Linie -> Pfiil zeigt nach RÄCHTS */
#sunGraphTooltip.left-side::after, #moonGraphTooltip.left-side::after {
    right: -12px;
    border-color: transparent transparent transparent rgba(0, 0, 0, 0.9);
}

/* --- Die vertikale Tracker-Linie --- */
#sunGraphLine, #moonGraphLine {
    display: none;
    position: absolute;
    width: 1px;
    background: rgba(0, 102, 204, 0.6); /* Blau für Sonne, grau chasch per ID überschribe */
    pointer-events: none;
    z-index: 2500;
}

/* ----------------------------------------------------
   Mondvorschau
---------------------------------------------------- */
.mondvorschau-title {
    justify-content: space-between;
}

.title-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.moonphase-mini {
    display: flex;
    gap: 4px;
    opacity: 0.8;
}

.moonphase-mini img {
    height: 22px;
    width: auto;
}

.moon-preview-line {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 16px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.moon-preview-line-item {
  text-align: center;
  padding: 6px 8px;
  box-sizing: border-box;
  min-width: 0;
}

.moon-preview-line-item img {
  width: 80%;
  height: auto;
  display: block;
  margin: 0 auto 6px;
}

.moon-preview-line-date {
    font-size: 13px;
    color: var(--fg-soft)
}

.moon-preview-line-date {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px; /* Abstand zwischen Datum und Marker */
}

.moon-marker {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.moon-marker.full {
    background-color: #ffd700; /* goldener Vollmond */
}

.moon-marker.new {
    background-color: #555; /* dunkler Neumond */
}

.moon-preview-line-eighth {
    font-size: 13px;
    color: #999;
}

.moon-preview-line-percent {
    font-size: 13px;   /* etwas kleiner als Datum/Achtel */
    color: #999;       /* gleiche Farbe wie Achtel */
    margin-top: 2px;   /* kleiner Abstand nach oben */
}

/* ----------------------------------------------------
   Einheitliche Typografie für Labels & Werte (ohne !important)
---------------------------------------------------- */
/* Globale Regel: strong = dunkel (#222) */
strong {
    color: var(--fg-main);
    font-weight: 600;
}

/* Mond/Sonne: Label links */
.moon-row > span:first-child,
.sun-row > span:first-child {
    color: var(--fg-main);
    font-weight: 600;
}

/* Mond/Sonne: Werte rechts */
.moon-row > span:last-child,
.sun-row > span:last-child {
    color: var(--fg-muted);
    font-weight: normal;
    text-align: right;
}

/* Mond-Details (oben): Werte */
.mond-details span {
    color: var(--fg-muted);
    font-weight: normal;
}

/* Vorschau: normale Texte */
.moon-preview-line-date,
.moon-preview-line-eighth,
.moon-preview-line-percent {
    color: var(--fg-muted);
    font-weight: normal;
}

/* ----------------------------------------------------
   Overlay
---------------------------------------------------- */
.moon-toggle {
    font-size: 13px;
    color: #0066cc;
    cursor: pointer;
    text-align: center;
    margin-bottom: 20px;
}

.moon-toggle:hover {
    text-decoration: underline;
}

.moon-overlay-bg {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    display: none;
    z-index: 900;
}

.moon-overlay {
    position: absolute;
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    width: 360px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 901;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.moon-overlay-close {
    text-align: right;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    margin-bottom: 10px;
}

.moon-overlay-close:hover {
    color: #000;
}
/* ----------------------------------------------------
   Finsternisse
---------------------------------------------------- */

.finsternisse {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.finsternis-panel {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    font-size: 13px;
    color: var(--fg-muted);
}

.finsternis-panel div {
    margin-bottom: 4px;
    line-height: 1.25;
    font-size: 13px;
}

 .finsternis-panel .panel-title span {
     font-size: 18px;
     font-weight: bold;
     color: var(--fg-main);
 }

 .finsternis-inhalt {
    display: flex;
    flex-wrap: wrap; /* Schiebt die Grafik mobil automatisch unter den Text! */
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-top: 10px;
}

.finsternis-text {
    flex: 1;
    min-width: 180px; /* Hält den Text auf schmalen Bildschirmen lesbar */
}

.finsternis-grafik {
    flex: 0 0 auto;
    width: 140px; /* Perfekte, kompakte Desktop-Grösse im 1200px-Grid neben dem Text */
    height: 140px;
}

/* ----------------------------------------------------
   Mobile adjustments (cleaned: avoid !important where possible)
   - Uses a mobile padding variable --mobile-pad
   - More specific selectors placed here to rely on cascade instead of !important
---------------------------------------------------- */

:root {
  --mobile-pad: 12px; /* adjust 8px..16px as desired */
}

@media (max-width: 720px) {
  /* Headline sizing for mobile */

    .himmel-header {
        flex-direction: column; /* Elemente untereinander stapeln */
        gap: 15px;
        text-align: center;
        padding: 10px 0;
    } 

  .himmel-container h2 {
    font-size: 16px;
    color: var(--fg-main);
    width: 100%;
  }

      /* Uhrzeit und Switch nebeneinander unter das H2 setzen */
    .server-live-clock, 
    .theme-wrapper {
        display: inline-flex;
        vertical-align: middle;
    }

        /* Container für die untere Zeile auf Mobile (falls du sie gruppieren willst), 
       ansonsten erledigt das Column-Layout den Rest automatisch geordnet */
    .server-live-clock {
        font-size: 13px;
    }

    #moonPanel-serverTime {
        font-size: 15px;
    }
    
    .theme-label {
        font-size: 0.75em; /* Label auf Mobile unauffälliger */
    }

  /* Container edge-to-edge if desired, but panels keep inner padding via variable */
  .himmel-container {
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
  }

  /* Panels keep readable inner padding using the variable (no !important) */
  .himmel-container .panel {
    padding-left: var(--mobile-pad);
    padding-right: var(--mobile-pad);
    box-sizing: border-box;
  }

  /* Ensure moon/sun panels shrink correctly on small screens.
     Use a more specific selector and rely on cascade (placed at file end). */
  .himmel-top > .mond-panel,
  .himmel-top > .sonnen-panel {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
  }

  /* Graphs can visually extend to the edges while text stays inset */
  .himmel-container .graph-container {
    width: calc(100% + (var(--mobile-pad) * 2));
    margin-left: calc(var(--mobile-pad) * -1);
    margin-right: calc(var(--mobile-pad) * -1);
    box-sizing: border-box;
  }

  /* Canvas visual size (chart code should handle pixel ratio) */
  #moonGraph, #sunGraph {
    width: 100%;
    height: 180px;
    display: block;
  }

  /* Moon preview grid centering */
  .himmel-mid #moon-preview-line,
  .moon-preview-line {
    justify-items: center;
     align-items: center;
     width: 100%;
     box-sizing: border-box;
  }

  /* Finsternisse: switch to single column on mobile using a scoped selector */
  .himmel-mid .finsternisse {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .himmel-mid .finsternis-panel {
    width: 100%;
    box-sizing: border-box;
  }
  .himmel-bottom .finsternisse {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .himmel-bottom .finsternis-panel {
    width: 100%;
    box-sizing: border-box;
  }

  /* Compact typography for mobile */
  .stats-box,
  .moon-row,
  .sun-row,
  .mond-details,
  .sun-twilight-title,
  .moon-preview-line-date,
  .moon-preview-line-eighth,
  .moon-preview-line-percent,
  .finsternis-panel,
  .moon-tooltip,
  .finsternis-panel div {
    font-size: 12px;
  }

  .panel-title { font-size: 16px; }

  .finsternis-panel .panel-title span { font-size: 16px; }
}

 .finsternis-inhalt {
        justify-content: center;
    }

  .finsternis-grafik {
    flex: 0 0 auto;
    width: 130px;  /* Hier kannst du die Grösse BEIDER Körper gleichzeitig ändern (z.B. 120px oder 150px) */
    height: 130px; /* Muss immer exakt quadratisch identisch mit der width sein! */
}

/* 1. S'Hauptbild: Aggressiver schrumpfe loh uf Mobile */
.mond-gross {
  /* 22vw statt 36vw: Bild gibt schon früher Platz frei */
  /* 85px ist klein genug für Mobile, 150px ist ideal für Desktop */
  width: clamp(105px, 22vw, 150px);
  height: auto;
  display: block;
  flex-shrink: 0; /* Verhindert, dass das Bild "verquetscht" wird */
}

/* 2. Flex-Box fürs Layout */
.mond-main {
  display: flex;
  /* Kleinerer Gap auf Mobile (8px), normaler (16px) auf Desktop */
  gap: clamp(8px, 3vw, 16px); 
  align-items: center;
  margin-bottom: 13px;
  width: 100%;
}

/* 3. Text-Box rechts */
.mond-details {
  flex: 1; /* Füllt den Platz flexibel aus */
  min-width: 0; /* Wichtig für korrekte Flex-Berechnung */
  font-size: clamp(12px, 3.2vw, 13px); /* Schrift schrumpft leicht mit */
  color: var(--fg-muted);
  line-height: 1.3;
}

/* 4. SVG Icon dezent mit-skalieren */
#moon-orient-svg {
  /* Passt Grösse vom Icon der Bildschirmbreite an */
  width: clamp(40px, 7vw, 55px);
  height: clamp(40px, 7vw, 55px);
  display: block;
}

/* 5. Spezial-Fix für ganz schmale Handys */
@media (max-width: 360px) {
  .mond-main {
    gap: 6px;
  }
  .moon-orient-wrap {
    gap: 4px; /* Weniger Platz zwischen Icon und Grad-Zahl */
  }
}