/* Shared mobile/responsive fixes for Wissen articles (not index).
   Loaded after the inline <style> of each article.
   IMPORTANT: Do not override desktop content measures (chapter-grid 960px, hero 1040px, 76ch text). */

/* Safe globals only */
img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto;
}

/* ── Shared shell: aligned with wissen/index.html ─────────── */
.chapter-grid {
  grid-template-columns: 1fr !important;
  gap: 0 !important;
}

.ch-num {
  display: none !important;
}

.main-nav {
  gap: 2.2rem;
}

.nav-links {
  gap: 2.2rem;
}

.nav-github {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--text);
  padding: .4rem .9rem;
  border-radius: 8px;
  transition: border-color .2s, color .2s;
}

.nav-github:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.nav-github svg {
  width: 15px;
  height: 15px;
}

.nav-toggle {
  display: none;
  position: absolute;
  right: clamp(1.5rem,5vw,4rem);
  width: 40px;
  height: 40px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  z-index: 101;
  transition: border-color .2s;
}

.nav-toggle:hover {
  border-color: var(--accent);
}

.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0;
  background: var(--text);
  border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
}

.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-menu {
  display: none;
  position: fixed;
  top: var(--nav-h);
  left: 0;
  right: 0;
  background: rgba(12,12,15,.98);
  z-index: 102;
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
}

.mobile-menu.open {
  max-height: calc(100vh - var(--nav-h));
  overflow-y: auto;
}

.mobile-menu li + li {
  border-top: 1px solid var(--border);
}

.mobile-menu a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .95rem .2rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 0;
  font-size: 1rem;
  font-weight: 500;
  transition: color .2s;
}

.mobile-menu a:hover {
  color: var(--accent);
}

.mobile-menu .mobile-github {
  color: var(--accent);
}

.mobile-menu .mobile-github svg {
  width: 17px;
  height: 17px;
}

footer {
  font-size: .82rem;
}

.footer-logo {
  display: inline-block;
  margin-bottom: .9rem;
}

.footer-brand p {
  line-height: 1.6;
  color: var(--muted);
}

.footer-col ul {
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

footer a {
  transition: color .2s;
}

footer a:hover {
  color: var(--accent);
}

.footer-bottom {
  align-items: center;
}

.article-table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* ── NAV / Burger ───────────────────────────── */
@media (max-width: 960px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    width: 100%;
  }

  .main-nav {
    justify-content: flex-start;
    padding: 0 1.5rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .main-nav .nav-links,
  .main-nav .nav-github {
    display: none !important;
  }

  .nav-logo {
    position: static;
  }

  .nav-toggle {
    display: flex;
  }

  .mobile-menu {
    display: block;
  }

  .mobile-menu ul {
    padding: .4rem 1.5rem 1.4rem;
  }
}

/* ── Layout ≤980 ────────────────────────────── */
@media (max-width: 980px) {
  section {
    padding: 2.75rem 1.15rem;
  }

  #article-hero {
    padding-left: 1.15rem;
    padding-right: 1.15rem;
    max-width: 100%;
    box-sizing: border-box;
  }

  .chapter-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    max-width: 100%;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .cta-box,
  .related-grid {
    max-width: 100%;
    box-sizing: border-box;
  }

  .ch-num {
    position: static;
    padding-top: 0;
  }

  .ch-body,
  .ch-text {
    min-width: 0;
    max-width: 100%;
  }

  .ch-text,
  .article-lead,
  .article-title,
  .section-title,
  .formula-box,
  .note-box {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .metric-grid {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .metric-card {
    min-width: 0;
    max-width: 100%;
  }

  .related-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
    width: 100%;
    min-width: 0;
  }
}

/* ── Phone ≤768 ─────────────────────────────── */
@media (max-width: 768px) {
  #article-hero {
    padding-top: calc(var(--nav-h) + 1.5rem);
    padding-bottom: 2rem;
  }

  .article-title {
    font-size: clamp(1.65rem, 8vw, 2.4rem);
    letter-spacing: -0.03em;
  }

  .article-lead {
    font-size: 1rem;
    line-height: 1.7;
  }

  .article-meta {
    flex-wrap: wrap;
    gap: 0.55rem 1rem;
  }

  .section-title {
    font-size: clamp(1.4rem, 6.5vw, 1.95rem);
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .cta-box {
    flex-direction: column;
    align-items: flex-start;
    padding: 1.5rem 1.15rem;
    gap: 1.2rem;
    max-width: 100%;
  }

  .cta-box p {
    max-width: none;
  }

  .cta-actions {
    width: 100%;
  }

  .btn {
    min-height: 48px;
    justify-content: center;
  }

  .formula-box {
    padding: 1.1rem 1.15rem;
    font-size: 0.98rem;
    overflow-x: auto;
  }

  .note-box {
    padding: 1rem 1.05rem;
  }

  .article-table {
    min-width: 560px;
    font-size: 0.8rem;
  }

  .article-table th,
  .article-table td {
    padding: 0.7rem 0.75rem;
  }

  .related-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .related-card:hover {
    transform: none;
  }

  .footer-inner {
    grid-template-columns: 1fr;
    gap: 1.75rem;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
  }

  footer {
    padding: 2.25rem 1.15rem 1.75rem;
    max-width: 100%;
    box-sizing: border-box;
  }

  .footer-brand p {
    max-width: none;
  }

  .flow-list li {
    grid-template-columns: 30px minmax(0, 1fr);
    min-width: 0;
  }
}

/* ── Narrow phones ──────────────────────────── */
@media (max-width: 420px) {
  section,
  #article-hero {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .article-title {
    font-size: clamp(1.5rem, 8.5vw, 2rem);
  }

  .article-table {
    min-width: 480px;
  }
}

@media (hover: none) {
  .related-card:hover {
    transform: none;
  }
  .btn-primary:hover {
    transform: none;
    box-shadow: none;
  }
}
