/* ==== Theme-Variablen =============================================== */

:root {
  --bg: #fffaf0;            /* Fond (hell) */
  --text: #222;
  --text-weak: #333;
  --muted: #888;
  --border: #ccc;
  --shadow: #eee;
  --h1: #111;
  --h2: #663399;
  --accent: #ff6600;
  --link: #ff6600;
  --link-hover: #000;
  --chip: rgba(255,255,255,0.7);
  --code-bg: #f5f5f5;
  --selection-fg: #fff;
  --selection-bg: #ff6600;
}

html[data-theme="dark"] {
  --bg: #0f1115;            /* Fond (dunkel) */
  --text: #e6e6e6;
  --text-weak: #d8d8d8;
  --muted: #a0a0a0;
  --border: #2b2f36;
  --shadow: #1a1e24;
  --h1: #f2f2f2;
  --h2: #caa6ff;
  --accent: #ff7a1a;        /* leicht heller fürs Dark theme */
  --link: #ff7a1a;
  --link-hover: #ffffff;
  --chip: rgba(255,255,255,0.05);
  --code-bg: #1b1f27;
  --selection-fg: #0f1115;
  --selection-bg: #ff7a1a;
}

/* ==== Grundlayout ==================================================== */

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  line-height: 1.6;
  padding: 4rem 2rem;
  max-width: 800px;
  margin: auto;
  scroll-behavior: smooth; 
}

h1 {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: hue 8s infinite alternate;
  color: var(--h1);
}

h2 {
  font-size: 1.5rem;
  margin-top: 3rem;
  color: var(--h2);
}

p {
  margin-bottom: 1.5rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-weak);
  max-width: 700px;
  text-align: justify;
}

@keyframes hue {
  0% { color: var(--h1); }
  100% { color: var(--accent); }
}

footer {
  margin-top: 5rem;
  font-size: 0.9rem;
  color: var(--muted);
  border-top: 1px dotted var(--border);
  padding-top: 1rem;
  text-align: center;
  font-style: italic;
}

/* Inline code */
code {
  font-family: 'Courier Prime', monospace;
  color: var(--text);
  background: var(--code-bg);
  padding: 0 0.3rem;
  border-radius: 3px;
}

/* Links */
a {
  color: var(--link);
  text-decoration: none;
  font-weight: bold;
}
a:hover {
  text-decoration: underline;
  color: var(--link-hover);
}

/* Textauswahl */
::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}
::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

/* ==== Navigation ===================================================== */

nav {
  position: absolute;
  top: 2rem;
  right: 2rem;
  font-family: 'Space Grotesk', sans-serif;
  text-align: right;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

/* Nur wenn Untermenü vorhanden */
nav.with-sub ul.main-nav {
  margin-bottom: 0.3rem;
}
nav.with-sub ul.sub-nav {
  display: flex;
  font-size: 0.9rem;
  opacity: 0.75;
}
/* Standard: kein sub-nav anzeigen */
nav:not(.with-sub) ul.sub-nav {
  display: none;
}

nav a {
  text-decoration: none;
  color: #555;
  border-bottom: 1px dotted var(--accent);
  transition: all 0.2s ease-in-out;
}
html[data-theme="dark"] nav a {
  color: #cfcfcf;
  border-bottom-color: var(--accent);
}
nav a:hover {
  color: var(--link-hover);
  border-bottom: 1px solid var(--accent);
}
nav a.active {
  font-weight: bold;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* ==== TOC (Inhaltsverzeichnis) ====================================== */

#toc {
  margin-bottom: 2rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  color: #555;
}
html[data-theme="dark"] #toc { color: #cfcfcf; }

#toc strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: var(--text);
}

#toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
#toc li { margin: 0; }

#toc a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  transition: all 0.2s ease-in-out;
}
#toc a:hover {
  color: var(--link-hover);
  border-bottom: 1px solid var(--accent);
}

/* ==== Back-to-top Button ============================================ */

#toTopBtn {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out;
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 99;
  font-size: 1.5rem;
  border: none;
  outline: none;
  background-color: var(--accent);
  color: white;
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
}
#toTopBtn.show {
  opacity: 1;
  visibility: visible;
}
#toTopBtn::before {
  content: "";
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(135deg);
  margin-top: 0.2rem;
}
#toTopBtn:hover {
  background-color: #e65500;
}

/* ==== Theme Toggle Button =========================================== */

.theme-toggle {
  position: fixed;
  top: 1.2rem;
  left: 1.2rem;
  z-index: 100;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--chip);
  backdrop-filter: blur(6px);
  box-shadow: 2px 2px 0 var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

/* Icon via CSS: Sonne/Mond */
.theme-toggle::before {
  content: "☀️";
  font-size: 1rem;
  line-height: 1;
}
html[data-theme="dark"] .theme-toggle::before {
  content: "🌙";
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

/* === Blog-Übersicht: Cards ========================================= */

.posts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.2rem;
  margin-top: 1.5rem;
  max-width: 720px;
}

@media (min-width: 860px) {
  .posts { grid-template-columns: 1fr 1fr; }
}

.post {
  position: relative;
  background: var(--chip);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  padding: 1rem 1rem 1.1rem 1rem;
  box-shadow: 0 2px 0 var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .2s ease, background .2s ease;
  overflow: hidden;
}

html[data-theme="dark"] .post {
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}

.post:hover,
.post:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,.08);
  border-left-color: var(--accent);
}

.post h3 {
  margin: 0 0 .25rem 0;
  font-size: 1.25rem;
  color: var(--accent);
  line-height: 1.25;
}

.post .meta {
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: .6rem;
}

.post p {
  margin: 0 0 .8rem 0;
  color: var(--text-weak);
  text-align: left;         /* auf Cards kein Blocksatz */
  max-width: none;          /* Card darf volle Breite nutzen */
}

.post a.more {
  display: inline-block;
  font-weight: 600;
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 2px;
  transition: color .15s ease, border-color .15s ease;
}

.post a.more:hover,
.post a.more:focus-visible {
  color: var(--link-hover);
  border-bottom-color: var(--accent);
}

/* Fokus sichtbar für Tastatur-Nutzer */
.post a:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

/* Einzelbild & Slideshow: Rahmen farbvariabel */
.single-image {
  max-width: 100%;
  display: block;
  margin: 2rem auto;
  border: 2px solid var(--border);
}

.slideshow {
  max-width: 100%;
  margin: 2rem 0;
  position: relative;
}
.slideshow img {
  width: 100%;
  display: none;
  border: 2px solid var(--border);
}
.slideshow img.active {
  display: block;
}

/* Codeblöcke – hell/dunkel über Variablen */
.code-block {
  background: var(--code-bg);
  color: var(--text);
  font-family: 'Courier Prime', monospace;
  padding: 1rem 1rem 1rem 1rem;
  font-size: 0.9rem;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  position: relative;
  margin: 1.5rem 0 1.5rem 2rem;
  box-shadow: 0 1px 0 var(--shadow) inset;
  overflow-x: auto;              /* lange Zeilen scrollen horizontal */
}

/* pre/code inside Blocks */
.code-block pre {
  margin: 0;
  white-space: pre;              /* Zeilenumbrüche beibehalten */
  tab-size: 2;
}
.code-block pre code {
  display: block;
  background: transparent;
  color: inherit;                /* von .code-block erben */
  padding: 0;
  border-radius: 0;
}

/* Copy-Button */
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  transition: background 0.2s ease, transform 0.1s ease;
}
.copy-btn:hover { background: #e65500; }
.copy-btn:active { transform: translateY(1px); }

/* ==== Mobile Tweaks (nur <= 640px) ================================== */
@media (max-width: 640px) {
  /* mehr Breite nutzen */
  html, body {
    max-width: 100%;
    padding: 1.25rem 1rem;         /* statt 4rem/2rem */
  }

  /* Typo leicht kleiner/kompakter */
  h1 { font-size: 2.2rem; }
  h2 { font-size: 1.25rem; margin-top: 2rem; }
  p  { font-size: 1rem; line-height: 1.7; max-width: 100%; text-align: left; }

  /* Nav etwas näher an den Rand */
  nav { top: 1rem; right: 1rem; }
  nav.with-sub ul.sub-nav { font-size: 0.95rem; }

  /* Blog-Karten: volle Breite */
  .posts { max-width: 100%; gap: 1rem; }
  .post  { border-radius: 10px; padding: 0.9rem 0.9rem 1rem; }

  /* Einzelbilder/Slideshow: Rahmen bleibt, aber ohne Randverlust */
  .single-image,
  .slideshow img { border-width: 1px; }

  /* Codeblöcke: lesbarer + nicht abgeschnitten */
  .code-block {
    margin: 1rem 0;                 /* kein 2rem-Indent links */
    padding: 0.9rem;
    border-radius: 8px;
    font-size: 0.95rem;
  }
  .code-block pre {
    white-space: pre-wrap;          /* Umbrüche auf schmalen Screens erlauben */
    word-break: break-word;         /* lange Tokens umbrechen */
  }
  .code-block pre code {
    line-height: 1.5;
  }

  /* Copy-Button: tap-freundlich + weiter an den Rand */
  .copy-btn {
    top: 0.45rem;
    right: 0.45rem;
    font-size: 0.85rem;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
  }

  /* Back-to-top sitzt etwas höher, damit er Text weniger überlappt */
  #toTopBtn { bottom: 1.2rem; right: 1.2rem; }
}

/* 1) Sauberer Box-Model & kein horizontales Scrollen der Seite */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  overflow-x: hidden;                 /* verhindert Seiten-Overflow */
}

/* 2) Container-Setup entkoppeln: max-width/padding nur auf <body> anwenden */
html {
  /* alles wie gehabt (Farben etc.) – KEIN padding/max-width hier */
}
body {
  max-width: 800px;                   /* bleibt gleich */
  margin: 0 auto;                     /* center */
  padding: 4rem 2rem;                 /* innenabstand */
}

/* 3) Codeblöcke: niemals breiter als der Viewport-Container */
.code-block {
  max-width: 100%;
}
.code-block pre {
  max-width: 100%;
  overflow-x: auto;                   /* eigener horizontaler Scroll nur im Block */
  white-space: pre;                   /* Desktop: kein Umbruch */
}

/* 4) Sicherheitsnetz: Medien (Bilder/Slides) dürfen nie überlaufen */
.single-image,
.slideshow,
.slideshow img {
  max-width: 100%;
}

/* 5) Mobile-Tweak bleibt – hier nur ergänzen: kein Seiten-Overflow auf Phones */
@media (max-width: 640px) {
  html, body {
    max-width: 100%;
    padding: 1.25rem 1rem;
  }
  .code-block {
    margin: 1rem 0;
  }
  .code-block pre {
    white-space: pre-wrap;            /* Mobile: weicher Umbruch */
    word-break: break-word;
    overflow-x: visible;              /* horizontale Leiste auf Phones vermeiden */
  }
}

/* Nur INLINE-Code umbrechen, damit lange Pfade/Kommandos mobil keinen Overflow erzeugen */
:not(pre) > code {
  white-space: pre-wrap;       /* respektiert Spaces/Wraps */
  overflow-wrap: anywhere;     /* darf überall umbrechen */
  word-break: break-word;      /* fallback */
}
