*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.hidden,
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
  z-index: 999;
}

.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
  border-radius: var(--radius-sm);
}

:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

#main-content:focus {
  outline: none;
  box-shadow: none;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p {
  margin: 0 0 0.75rem;
}

p:last-child {
  margin-bottom: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* App-Shell: Mobil zuerst (360 px), Desktop mit linker Seitenleiste (>= 960 px) */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 0.875rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: transparent;
  border: none;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.top-strips {
  width: 100%;
}

.unofficial-strip {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 0.35rem 0.75rem;
}

.offline-strip {
  background: var(--warning-soft);
  border-bottom: 1px solid var(--border);
  color: var(--warning);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 0.38rem 0.75rem;
}

.sidebar {
  display: none;
}

.main-content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 0.875rem calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1.5rem);
}

/* Untere Tab-Leiste auf Mobilgeräten (iOS-Safe-Area-kompatibel) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.25rem 0.25rem calc(0.25rem + env(safe-area-inset-bottom, 0px));
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.1rem;
  min-height: 44px;
}

.nav-item .nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.nav-item[aria-current="page"] {
  color: var(--primary);
  background: var(--primary-soft);
}

@media (min-width: 960px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "sidebar strip"
      "sidebar main";
  }

  .topbar {
    display: none;
  }

  .bottom-nav {
    display: none;
  }

  .top-strips {
    grid-area: strip;
  }

  .unofficial-strip,
  .offline-strip {
    text-align: left;
    padding: 0.45rem 2rem;
  }

  .sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.25rem 0.9rem;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }

  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.25rem 0.5rem 1rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand-title {
    font-weight: 800;
    font-size: 1.15rem;
    display: block;
  }

  .sidebar-brand-sub {
    font-size: 0.76rem;
    color: var(--text-muted);
    display: block;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }

  .sidebar-nav .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.7rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.93rem;
  }

  .sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
  }

  .main-content {
    grid-area: main;
    min-width: 0;
    padding: 1.75rem 2rem 3rem;
  }
}

/* Rich Text, MathML und Java-Codeblöcke */
.rich-p {
  margin: 0 0 0.65rem;
}

.rich-p:last-child {
  margin-bottom: 0;
}

.rich-list {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.3rem;
}

.rich-list li {
  margin-bottom: 0.35rem;
}

.rich-sublist {
  margin: 0.28rem 0 0.2rem;
  padding-left: 1.25rem;
}

.rich-sublist li {
  margin-bottom: 0.22rem;
}

.rich-li-cont {
  margin-top: 0.25rem;
}

.rich-h {
  font-size: 0.96rem;
  font-weight: 700;
  margin: 0.65rem 0 0.35rem;
  color: var(--text);
}

.table-wrap {
  margin: 0.6rem 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.rich-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  line-height: 1.45;
  background: var(--surface);
}

.rich-table th,
.rich-table td {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.rich-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
}

.rich-table tr:last-child td {
  border-bottom: none;
}

.rich-table .align-center { text-align: center; }
.rich-table .align-right { text-align: right; }

.math-inline {
  font-family: var(--font-math);
  font-size: 1.04em;
}

.math-nowrap {
  white-space: nowrap;
}

.math-tt {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.math-bf,
.math-bf mi {
  font-weight: 700;
  font-style: normal;
  text-transform: none;
}

.math-it {
  font-style: italic;
}

.math-ul {
  border-bottom: 1px solid currentColor;
  padding-bottom: 0.05em;
}

.math-block,
.math-display {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.65rem 0.75rem;
  margin: 0.55rem 0;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-family: var(--font-math);
  font-size: 1.08em;
  line-height: 1.4;
  text-align: center;
}

math {
  font-family: var(--font-math);
}

.math-aug-left {
  border-left: 1px solid currentColor;
  padding-left: 0.45em;
}

.math-aug-right {
  padding-right: 0.45em;
}

.math-hline-top > mtd {
  border-top: 1px solid currentColor;
  padding-top: 0.25em;
}

.inline-code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0.08rem 0.32rem;
  overflow-wrap: anywhere;
}

.code-block {
  margin: 0.7rem 0;
  padding: 0.75rem 0;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.5;
}

.code-line {
  display: flex;
  padding: 0 0.75rem 0 0.45rem;
  white-space: pre;
}

.code-ln {
  user-select: none;
  color: var(--code-ln);
  min-width: 2.1rem;
  padding-right: 0.75rem;
  text-align: right;
  flex-shrink: 0;
}

.code-src {
  flex: 1;
}

.tok-kw { color: var(--tok-kw); font-weight: 600; }
.tok-type { color: var(--tok-type); }
.tok-string { color: var(--tok-string); }
.tok-num { color: var(--tok-num); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-anno { color: var(--tok-anno); }
