/* DeepScroll Unified Mobile-First Zero-Overflow & Wayfinding System (CSP-safe) */
html,
body {
  max-width: 100%;
  overflow-x: clip;
}

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

/* Prevent CSS Grid & Flex children from pushing smartphone viewports wider than 100vw */
.grid > *,
main section,
main article,
main div {
  min-width: 0;
}

code,
pre,
.ds-break {
  overflow-wrap: anywhere;
  word-break: break-word;
}

pre.ds-code-scroll {
  max-width: 100%;
  overflow-x: auto;
  word-break: normal;
  overflow-wrap: normal;
  -webkit-overflow-scrolling: touch;
}

/* Unified Top Wayfinding Bar */
.ds-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 15, 23, 0.94);
  border-bottom: 1px solid #243350;
  backdrop-filter: blur(10px);
}

.ds-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.ds-subnav a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 0.75rem;
  border: 1px solid #243350;
  background: rgba(22, 31, 48, 0.9);
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #cbd5e1;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ds-subnav a:hover {
  border-color: rgba(0, 240, 255, 0.6);
  color: #ffffff;
}

.ds-subnav a[aria-current="page"] {
  border-color: #00f0ff;
  background: rgba(0, 240, 255, 0.14);
  color: #00f0ff;
}

/* Breadcrumb orientation strip */
.ds-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: #94a3b8;
}

.ds-breadcrumb a {
  color: #cbd5e1;
  text-decoration: none;
}

.ds-breadcrumb a:hover {
  color: #00f0ff;
  text-decoration: underline;
}

/* Smartphone Sticky Bottom Navigation Dock (< 640px) */
.ds-mobile-dock {
  display: none;
}

@media (max-width: 639px) {
  body.has-ds-dock {
    padding-bottom: calc(4.6rem + env(safe-area-inset-bottom, 0px));
  }

  /* Compact single-row horizontal chip strip on phones: saves ~95px above the fold with zero page overflow */
  .ds-subnav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
  }

  .ds-subnav::-webkit-scrollbar {
    display: none;
  }

  .ds-subnav a {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .ds-mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    border-top: 1px solid #243350;
    background: rgba(11, 15, 23, 0.97);
    backdrop-filter: blur(12px);
    padding: 0.3rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
  }

  .ds-mobile-dock a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12rem;
    min-height: 44px;
    border-radius: 0.65rem;
    color: #94a3b8;
    font-size: 0.65rem;
    font-weight: 700;
    text-decoration: none;
    line-height: 1.1;
    text-align: center;
    padding: 0.2rem 0.1rem;
  }

  .ds-mobile-dock a .ds-dock-ico {
    font-size: 1rem;
    line-height: 1;
  }

  .ds-mobile-dock a[aria-current="true"] {
    color: #00f0ff;
    background: rgba(0, 240, 255, 0.11);
  }
}

/* Crisp Ink-Saving 1-Page Printable Study Sheet for AI-Wiki Articles */
@media print {
  @page {
    margin: 12mm;
  }

  html,
  body {
    background: #ffffff !important;
    color: #0f172a !important;
    padding-bottom: 0 !important;
    font-size: 10.5pt !important;
  }

  .ds-topbar,
  .ds-subnav,
  .ds-mobile-dock,
  .ds-breadcrumb,
  .no-print,
  #bridgeWidgetMount,
  footer {
    display: none !important;
  }

  main {
    max-width: 100% !important;
    padding: 0 !important;
  }

  .glass,
  .glass-card,
  article section,
  article div {
    background: #ffffff !important;
    backdrop-filter: none !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
    box-shadow: none !important;
  }

  [data-quiz-box],
  .glass-card,
  article section .grid > div,
  article section .grid > article {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  [data-quiz-box] button[data-quiz-idx] {
    display: block !important;
    width: 100% !important;
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #94a3b8 !important;
  }

  [data-quiz-box] button[data-quiz-idx]::before {
    content: "☐ ";
    font-weight: 700;
  }

  h1,
  h2,
  h3,
  strong,
  .text-white,
  .text-slate-100,
  .text-slate-200,
  .text-slate-300,
  .text-focus,
  .text-brain {
    color: #0f172a !important;
  }

  .text-slate-400,
  .text-slate-500 {
    color: #475569 !important;
  }
}
