/* Runtime Stability — Design System */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&family=DM+Sans:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; overflow-x: hidden; }
body { background: #0B1A2E; color: #B0B8C9; font-family: 'DM Sans', sans-serif; overflow-x: hidden; max-width: 100vw; }
::selection { background: rgba(0,170,204,0.2); }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1A2D4A; border-radius: 3px; }

:root {
  --navy: #0B1A2E;
  --navy-mid: #1A2D4A;
  --white: #FFFFFF;
  --gray-300: #B0B8C9;
  --gray-500: #6B7A94;
  --gray-700: #3D4F6A;
  --cyan: #00AACC;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'DM Sans', sans-serif;
}

/* Header */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(11,26,46,0.93); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--navy-mid);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; height: 56px;
}
.site-header a.logo {
  font-family: var(--serif); font-size: 1.05rem; font-weight: 600;
  color: var(--white); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex-shrink: 1;
}
.site-header .version {
  font-family: var(--sans); font-size: 0.7rem; color: var(--gray-500); letter-spacing: 1px;
}
.lang-toggle { display: flex; border: 1px solid rgba(0,170,204,0.27); border-radius: 2px; overflow: hidden; flex-shrink: 0; }
.lang-toggle button {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: 1.5px; padding: 5px 14px; border: none; cursor: pointer;
  background: transparent; color: var(--gray-300); transition: all 0.3s;
}
.lang-toggle button.active { background: var(--cyan); color: var(--navy); }

/* Title Area */
.title-area { padding-top: 56px; background: linear-gradient(to bottom, var(--navy-mid), var(--navy)); }
.title-area .inner { max-width: 1200px; margin: 0 auto; padding: 4rem 2rem 3rem; text-align: center; }
.title-area .label {
  font-family: var(--sans); font-size: 10px; letter-spacing: 3px;
  text-transform: uppercase; color: var(--cyan); margin-bottom: 1rem;
}
.title-area h1 {
  font-family: var(--serif); font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 600; color: var(--white); margin: 0 0 0.5rem;
  overflow-wrap: break-word; word-break: break-word;
}
.title-area .subtitle {
  font-size: 0.85rem; color: var(--gray-500);
  overflow-wrap: break-word; word-break: break-word;
}
.title-area .meta { font-size: 0.75rem; color: var(--gray-700); margin-top: 0.5rem; }

/* Document Grid */
.doc-layout {
  max-width: 1200px; margin: 0 auto; display: grid;
  grid-template-columns: 260px 1fr; gap: 3rem;
  padding: 2rem; min-height: 100vh;
}
.doc-main {
  max-width: 780px; padding-bottom: 6rem;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* TOC Sidebar */
.toc-sidebar { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; padding-right: 1rem; }
.toc-sidebar .toc-label {
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--cyan); margin-bottom: 1rem; padding-left: 12px;
}
.toc-sidebar a {
  display: block; font-size: 0.78rem; font-weight: 400; color: var(--gray-500);
  text-decoration: none; padding: 4px 12px; border-left: 2px solid transparent;
  line-height: 1.5; transition: all 0.2s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px;
}
.toc-sidebar a.h3 { font-size: 0.72rem; padding-left: 24px; }
.toc-sidebar a.active { font-weight: 600; color: var(--cyan); border-left-color: var(--cyan); }

/* Document Content — H1 (from markdown # heading, rendered as document title) */
.doc-main h1 {
  font-family: var(--serif); font-size: clamp(1.6rem, 3.5vw, 2.2rem); font-weight: 600;
  color: var(--white); margin: 0 0 0.5rem; line-height: 1.3;
  overflow-wrap: break-word; word-break: break-word;
  scroll-margin-top: 80px;
}
.doc-main h2 {
  font-family: var(--serif); font-size: 1.55rem; font-weight: 600;
  color: var(--white); margin: 3rem 0 1rem; padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--navy-mid); scroll-margin-top: 80px;
  overflow-wrap: break-word; word-break: break-word;
}
.doc-main h3 {
  font-family: var(--serif); font-size: 1.2rem; font-weight: 500;
  color: var(--white); margin: 2.2rem 0 0.8rem; scroll-margin-top: 80px;
  overflow-wrap: break-word; word-break: break-word;
}
.doc-main h4 {
  font-family: var(--serif); font-size: 1.05rem; font-weight: 500;
  color: var(--white); margin: 1.5rem 0 0.6rem; scroll-margin-top: 80px;
}
.doc-main .sec-num { color: var(--cyan); margin-right: 8px; font-weight: 400; font-size: 0.85em; }
.doc-main p {
  font-size: 0.92rem; color: var(--gray-300); line-height: 1.8; margin: 0.6rem 0;
  overflow-wrap: break-word; word-break: break-word;
}
.doc-main strong { color: var(--white); font-weight: 600; }
.doc-main ul { margin: 0.5rem 0 0.5rem 1.2rem; padding: 0; list-style: none; }
.doc-main ul li {
  font-size: 0.9rem; color: var(--gray-300); line-height: 1.75;
  margin-bottom: 0.3rem; position: relative; padding-left: 16px;
  overflow-wrap: break-word; word-break: break-word;
}
.doc-main ul li::before { content: '\00b7'; position: absolute; left: 0; color: var(--cyan); }

/* Tables — scrollable container to prevent page overflow */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 1rem 0;
}
.doc-main table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin: 0; }
.doc-main th {
  padding: 10px 14px; text-align: left; color: var(--cyan);
  font-weight: 600; border-bottom: 2px solid var(--navy-mid); white-space: nowrap;
}
.doc-main td {
  padding: 10px 14px; color: var(--gray-300);
  border-bottom: 1px solid rgba(26,45,74,0.2); line-height: 1.6;
}

/* Notice */
.notice {
  margin: 1.5rem 0; padding: 1.2rem 1.5rem;
  background: rgba(0,170,204,0.04); border-left: 3px solid rgba(0,170,204,0.33);
  border-radius: 0 2px 2px 0;
  overflow-wrap: break-word; word-break: break-word;
}
.notice p { font-size: 0.85rem; line-height: 1.75; margin: 0; }

/* Blockquote */
.doc-main blockquote {
  margin: 1rem 0; padding: 0.8rem 1.5rem;
  border-left: 3px solid var(--gray-700); font-size: 0.9rem; line-height: 1.75;
  overflow-wrap: break-word; word-break: break-word;
}

/* Horizontal Rule (rendered from --- in markdown) */
.doc-main hr {
  border: none; border-top: 1px solid var(--navy-mid);
  margin: 2rem 0;
}

/* Footer */
.site-footer {
  background: var(--navy); border-top: 1px solid var(--navy-mid);
  padding: 2rem; text-align: center;
}
.site-footer p { font-size: 0.7rem; color: var(--gray-700); }

/* ==========================================================================
   Responsive — Tablet (max-width: 860px)
   ========================================================================== */
@media (max-width: 860px) {
  .doc-layout {
    grid-template-columns: 1fr;
    padding: 1.5rem;
    gap: 0;
  }
  .doc-layout .toc-sidebar { display: none; }
  .doc-main { max-width: 100%; }
}

/* ==========================================================================
   Responsive — Mobile (max-width: 600px)
   ========================================================================== */
@media (max-width: 600px) {

  /* Header — compact for small screens */
  .site-header {
    padding: 0 0.8rem;
    height: 48px;
    gap: 0.5rem;
  }
  .site-header a.logo {
    font-size: 0.85rem;
  }
  .site-header .version {
    font-size: 0.6rem;
  }
  .lang-toggle button {
    font-size: 10px;
    padding: 4px 10px;
    letter-spacing: 1px;
  }

  /* Title Area — tighter on mobile */
  .title-area { padding-top: 48px; }
  .title-area .inner {
    padding: 2rem 1rem 1.5rem;
  }
  .title-area .label {
    font-size: 9px;
    letter-spacing: 2px;
    margin-bottom: 0.6rem;
  }
  .title-area h1 {
    font-size: clamp(1.4rem, 6vw, 1.8rem);
    margin-bottom: 0.3rem;
  }
  .title-area .subtitle {
    font-size: 0.75rem;
    line-height: 1.5;
  }
  .title-area .meta {
    font-size: 0.65rem;
  }

  /* Document Content — mobile spacing */
  .doc-layout {
    padding: 0.8rem;
  }
  .doc-main {
    padding-bottom: 3rem;
  }
  .doc-main h1 {
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    margin: 0 0 0.3rem;
    line-height: 1.3;
  }
  .doc-main h2 {
    font-size: 1.2rem;
    margin: 2rem 0 0.7rem;
    scroll-margin-top: 56px;
  }
  .doc-main h3 {
    font-size: 1rem;
    margin: 1.5rem 0 0.5rem;
    scroll-margin-top: 56px;
  }
  .doc-main h4 {
    font-size: 0.92rem;
    scroll-margin-top: 56px;
  }
  .doc-main p {
    font-size: 0.85rem;
    line-height: 1.7;
  }
  .doc-main ul {
    margin-left: 0.5rem;
  }
  .doc-main ul li {
    font-size: 0.83rem;
    line-height: 1.65;
    padding-left: 14px;
  }

  /* Tables — compact on mobile */
  .doc-main table {
    font-size: 0.7rem;
  }
  .doc-main th {
    padding: 6px 8px;
    font-size: 0.68rem;
    letter-spacing: 0;
  }
  .doc-main td {
    padding: 6px 8px;
    font-size: 0.7rem;
    line-height: 1.45;
  }

  /* Notice — tighter padding */
  .notice {
    margin: 1rem 0;
    padding: 0.7rem 0.8rem;
  }
  .notice p {
    font-size: 0.78rem;
    line-height: 1.6;
  }

  /* Blockquote */
  .doc-main blockquote {
    padding: 0.5rem 0.8rem;
    font-size: 0.83rem;
  }

  /* Footer */
  .site-footer {
    padding: 1.2rem 0.8rem;
  }
}

/* ==========================================================================
   Responsive — Very small screens (max-width: 380px) — iPhone SE etc.
   ========================================================================== */
@media (max-width: 380px) {
  .site-header {
    padding: 0 0.5rem;
  }
  .site-header a.logo {
    font-size: 0.78rem;
  }
  .lang-toggle button {
    padding: 3px 7px;
    font-size: 9px;
  }
  .title-area .inner {
    padding: 1.8rem 0.8rem 1.2rem;
  }
  .title-area h1 {
    font-size: 1.3rem;
  }
  .title-area .subtitle {
    font-size: 0.7rem;
  }
  .doc-layout {
    padding: 0.5rem;
  }
  .doc-main h1 {
    font-size: 1.1rem;
    line-height: 1.3;
  }

  /* Tables — minimal for SE */
  .doc-main table {
    font-size: 0.65rem;
  }
  .doc-main th {
    padding: 5px 6px;
    font-size: 0.62rem;
  }
  .doc-main td {
    padding: 5px 6px;
    font-size: 0.65rem;
    line-height: 1.4;
  }

  .doc-main p {
    font-size: 0.82rem;
  }
  .doc-main ul li {
    font-size: 0.8rem;
  }
  .notice p {
    font-size: 0.75rem;
  }
}
