:root {
  --bg: #f5f3ec;
  --bg-alt: #ffffff;
  --text: #1a1a1a;
  --accent: #b77b3a;
  --accent-soft: #e2c59a;
  --border: #ddd0c0;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.10);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 6px;
  --transition-fast: 0.18s ease-out;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", sans-serif;
  --font-serif: "Georgia", "Times New Roman", serif;
  --font-mono: ui-monospace, Menlo, Monaco, Consolas, monospace;
}

body.theme-dark {
  --bg: #0e0b08;
  --bg-alt: #17120e;
  --text: #f7f2ea;
  --accent: #e5b16b;
  --accent-soft: #3a2917;
  --border: #3b2a1d;
  --shadow-soft: 0 12px 36px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: radial-gradient(circle at top, #c9a576 0, #4a3220 45%, #120c09 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: 1.5rem;
}

/* App-Shell darf wachsen -> Seite kann scrollen */
.app-shell {
  background: var(--bg);
  max-width: 1200px;
  width: 100%;
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(0, 0, 0, 0.10);
}

/* Header */
.app-header {
  padding: 0.85rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0)
  );
  backdrop-filter: blur(10px);
}

.app-badge {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: conic-gradient(
    from 220deg,
    #ffcf62,
    #ff7a6f,
    #b55cff,
    #ffcf62
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #231108;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
}

.app-title-block {
  flex: 1;
  min-width: 0;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: center;
}

.app-subtitle span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #34c759;
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.25);
}

.pill {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.theme-toggle {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.15rem 0.65rem;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  transition: background var(--transition-fast),
              transform var(--transition-fast),
              box-shadow var(--transition-fast);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  color: #222;
}

body.theme-dark .theme-toggle {
  background: rgba(23, 18, 12, 0.94);
  color: #f7f2ea;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
}

.theme-toggle-icon {
  font-size: 1rem;
}

/* Layout */
.app-main {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  min-height: 0;
}

@media (max-width: 880px) {
  body {
    padding: 0.75rem;
  }
  .app-shell {
    border-radius: 18px;
  }
  .app-main {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* Seitenleiste */
.sidebar {
  border-right: 1px solid var(--border);
  background: radial-gradient(circle at top, rgba(255,255,255,0.45), transparent 60%),
              linear-gradient(to bottom, rgba(255,255,255,0.8), rgba(0,0,0,0.02));
  padding: 0.85rem 0.95rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;

  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.sidebar-top {
  flex-shrink: 0;
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
}
.sidebar-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.7;
  margin-bottom: 0.2rem;
}

.search-box {
  position: relative;
}

.search-input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.5rem 2.2rem 0.5rem 0.85rem;
  font-size: 0.8rem;
  outline: none;
  background: rgba(255,255,255,0.9);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              background var(--transition-fast),
              transform var(--transition-fast);
}

body.theme-dark .search-input {
  background: rgba(18, 12, 8, 0.96);
  color: var(--text);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(183, 123, 58, 0.25);
  transform: translateY(-0.5px);
}

.search-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.65;
  pointer-events: none;
}

.search-status {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  opacity: 0.8;
}

/* TOC */
.toc {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
}

.toc li {
  margin: 0.15rem 0;
}

.toc a {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast),
              border-color var(--transition-fast),
              transform var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc a[data-level="2"] {
  padding-left: 1.4rem;
  font-size: 0.78rem;
  opacity: 0.9;
}

.toc a:hover {
  background: rgba(0, 0, 0, 0.03);
  transform: translateX(1px);
}

.toc a.is-active {
  border-color: var(--accent);
  background: rgba(183, 123, 58, 0.12);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px dashed rgba(0, 0, 0, 0.15);
  font-size: 0.7rem;
  opacity: 0.8;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge-soft {
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.06);
}

/* Content */
.content {
  padding: 0.9rem 1.2rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: radial-gradient(circle at top left,
              rgba(255,255,255,0.38),
              transparent 55%),
              linear-gradient(to bottom right,
              rgba(255,255,255,0.92),
              rgba(236, 225, 210, 0.96));
}

body.theme-dark .content {
  background: radial-gradient(circle at top left,
              rgba(77, 48, 28, 0.7),
              transparent 55%),
              linear-gradient(to bottom right,
              #18110c,
              #261912);
}

.content-inner {
  border-radius: var(--radius-lg);
  background: var(--bg-alt);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 1.1rem 1.15rem 1.2rem;
}

.content-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  margin-bottom: 0.7rem;
  opacity: 0.8;
}

.content-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.content-meta strong {
  font-weight: 600;
}

.article-header {
  margin-bottom: 0.75rem;
}

.article-header h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 1rem + 0.8vw, 1.8rem);
  line-height: 1.1;
}

.article-header p {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

#article-content {
  font-size: 0.9rem;
  line-height: 1.5;
}

#article-content h1,
#article-content h2,
#article-content h3 {
  font-family: var(--font-serif);
}

#article-content h2,
#article-content h3 {
  margin-top: 1.3rem;
  margin-bottom: 0.25rem;
  line-height: 1.2;
}

#article-content h2 {
  font-size: 1.1rem;
}

#article-content h3 {
  font-size: 0.98rem;
  opacity: 0.95;
}

#article-content p {
  margin: 0.25rem 0 0.4rem;
}

#article-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

#article-content mark.search-hit {
  background: rgba(255, 238, 173, 0.95);
  padding: 0 0.12em;
  border-radius: 3px;
}

/* Footer */
.app-footer {
  padding: 0.3rem 0.9rem 0.45rem;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  opacity: 0.85;
}

.app-footer span {
  white-space: nowrap;
}

@media (max-width: 600px) {
  .app-footer {
    font-size: 0.64rem;
  }
  .article-header h1 {
    font-size: 1.15rem;
  }
  .content-inner {
    padding-inline: 0.8rem;
  }
}