:root {
  color-scheme: light;
  --sidebar-bg: #161b22;
  --sidebar-width: 272px;
  --accent: #ffec6e;
  --accent-dim: #9a6700;
  --accent-muted: rgba(255, 236, 110, 0.12);
  --content-bg: #f9f8f6;
  --card-bg: #ffffff;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --warning: #d97706;
  --warning-bg: rgba(245, 158, 11, 0.07);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --font-sans: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--content-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: clamp(13.5px, 0.9vw + 0.3rem, 15.5px);
  line-height: 1.65;
}
button, input { font: inherit; }
a { color: var(--accent-dim); text-underline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 500;
  top: 8px;
  left: 8px;
  padding: 7px 11px;
  border-radius: 5px;
  background: white;
  color: #111827;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

/* ── TOP HEADER ── */
.top-header {
  height: 52px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid #1e2a3a;
  background: var(--sidebar-bg);
  z-index: 200;
}
.home-btn {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 5px;
  color: #8b9cb5;
  font: 10px/1 var(--font-mono);
  letter-spacing: 0.12em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.15s;
}
.home-btn:hover { color: var(--accent); }
.top-header-title {
  flex-shrink: 0;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.top-header-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.top-search-wrap {
  width: clamp(180px, 20vw, 300px);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid #2d3748;
  border-radius: 6px;
  background: #1a2235;
  transition: border-color 0.15s;
}
.top-search-wrap:focus-within { border-color: var(--accent); }
.search-icon { flex-shrink: 0; color: #64748b; font-size: 13px; }
.top-search-wrap input {
  min-width: 0;
  flex: 1;
  padding: 2px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #e2e8f0;
  font-family: var(--font-sans);
  font-size: 12px;
}
.top-search-wrap input::placeholder { color: #64748b; }
.top-search-wrap input::-webkit-search-cancel-button { display: none; }
#search-clear { border: 0; background: none; color: #64748b; cursor: pointer; font-size: 12px; }
#search-clear:hover { color: #e2e8f0; }
.top-search-meta { min-width: 0; }
#search-count { color: var(--accent); font: 10.5px/1 var(--font-mono); white-space: nowrap; }
.theme-toggle, .menu-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid #2d3748;
  border-radius: 6px;
  background: none;
  color: #94a3b8;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover, .menu-btn:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle { font-size: 15px; }
.menu-btn { display: none; font-size: 16px; }

/* ── LAYOUT AND SIDEBAR ── */
.layout-row { display: flex; flex: 1; overflow: hidden; }
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--sidebar-bg);
  scrollbar-color: #2d3748 transparent;
  scrollbar-width: thin;
  z-index: 100;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { border-radius: 4px; background: #2d3748; }
.sidebar-header { padding: 20px 18px 14px; border-bottom: 1px solid #1e2a3a; }
.sidebar-logo { margin-bottom: 5px; color: var(--accent); font: 10px/1.3 var(--font-mono); letter-spacing: 0.15em; text-transform: uppercase; }
.sidebar-title { color: #e2e8f0; font-size: 13px; font-weight: 600; line-height: 1.4; }
.sidebar-subtitle { margin-top: 2px; color: #64748b; font-size: 11px; }
.sidebar-nav { flex: 1; padding: 6px 0 24px; }
.nav-section-label { padding: 12px 18px 4px; color: #475569; font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.nav-item {
  display: block;
  padding: 5px 18px;
  border-left: 2px solid transparent;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
  transition: all 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: #e2e8f0; }
.nav-item.active, .nav-item.current { border-left-color: var(--accent); background: var(--accent-muted); color: var(--accent); }
.nav-phase {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 18px 3px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.nav-phase:hover { color: #fff; }
.nav-phase.active { background: var(--accent-muted); color: var(--accent); }
.phase-dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: var(--accent); }
.nav-sub { padding-left: 32px; color: #7f8ea3; font-size: 11.5px; }
.back-to-resources {
  position: sticky;
  bottom: 0;
  display: block;
  margin-top: auto;
  padding: 13px 18px;
  border-top: 1px solid #1e2a3a;
  background: var(--sidebar-bg);
  color: #64748b;
  font: 10px/1.4 var(--font-mono);
  letter-spacing: 0.04em;
  text-decoration: none;
}
.back-to-resources:hover { color: var(--accent); }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); z-index: 90; }
.sidebar-backdrop.open { display: block; }

/* ── MAIN CONTENT ── */
.main {
  height: 100%;
  flex: 1;
  overflow-y: auto;
  padding: clamp(20px, 3vw, 48px) clamp(20px, 4vw, 64px) 80px;
}
.guide-article, .unit-directory, .page-navigation { margin-inline: auto; }
.page-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 2px solid var(--border); }
.page-title { margin-bottom: 9px; color: var(--text-primary); font-size: clamp(20px, 1.6vw + 0.6rem, 28px); font-weight: 700; line-height: 1.2; }
.page-desc { max-width: 800px; color: var(--text-secondary); font-size: clamp(13px, 0.9vw + 0.25rem, 14.5px); line-height: 1.65; }
.page-desc p { margin-top: 8px; }
.page-desc p:first-child { margin-top: 0; }
.how-to-use { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(10px, 1.5vw, 18px); margin-bottom: 36px; padding: clamp(12px, 1.5vw, 22px); border-radius: var(--radius); background: var(--sidebar-bg); color: white; }
.htu-item-label { margin-bottom: 4px; color: var(--accent); font: 10px/1.4 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; }
.htu-item-text { color: #94a3b8; font-size: 13px; line-height: 1.5; }
.topic { margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--card-bg); box-shadow: var(--shadow); scroll-margin-top: 20px; }
.topic-heading { margin: 0; }
.topic-trigger { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; border: 0; background: none; cursor: pointer; text-align: left; transition: background 0.15s; }
.topic-trigger:hover, .topic.open .topic-trigger { background: #f8fafc; }
.topic.open .topic-trigger { border-bottom: 1px solid var(--border); }
.topic-name { color: var(--text-primary); font-size: clamp(13px, 0.9vw + 0.25rem, 14px); font-weight: 600; line-height: 1.4; }
.topic-chevron { flex-shrink: 0; color: var(--text-muted); font-size: 11px; transition: transform 0.2s; }
.topic.open .topic-chevron { transform: rotate(180deg); }
.topic-body { display: none; padding: 16px 18px 18px; }
.topic.open .topic-body { display: block; }
.topic-body > :first-child { margin-top: 0; }
.topic-body > :last-child { margin-bottom: 0; }
.guide-article p { margin: 0 0 13px; color: var(--text-secondary); font-size: clamp(12.5px, 0.8vw + 0.25rem, 14px); line-height: 1.67; }
.guide-article strong { color: var(--text-primary); font-weight: 600; }
.guide-article h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 24px 0 9px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  scroll-margin-top: 20px;
}
.guide-article h3::before { content: ""; width: 3px; height: 14px; flex-shrink: 0; border-radius: 2px; background: var(--accent-dim); }
.guide-article ul, .guide-article ol { margin: 10px 0 16px; padding-left: 22px; color: var(--text-secondary); font-size: clamp(12.5px, 0.8vw + 0.25rem, 14px); }
.guide-article li { margin-bottom: 5px; padding-left: 2px; }
.guide-article li::marker { color: var(--accent-dim); font-weight: 600; }
.guide-article hr { margin: 26px 0; border: 0; border-top: 1px solid var(--border); }
.guide-article blockquote {
  margin: 16px 0;
  padding: 12px 15px;
  border-left: 3px solid var(--warning);
  border-radius: 6px;
  background: var(--warning-bg);
}
.guide-article blockquote p { color: var(--text-secondary); }
.guide-article :not(pre) > code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #f3f4f6;
  color: #825f00;
  font: 12px/1.5 var(--font-mono);
}

/* ── TABLES AND CODE ── */
.guide-article table { width: 100%; margin: 14px 0 18px; border: 1px solid var(--border); border-collapse: separate; border-spacing: 0; border-radius: var(--radius); overflow: hidden; font-size: clamp(12px, 0.75vw + 0.22rem, 13.5px); }
.guide-article th { padding: 8px 11px; background: #111827; color: #e2e8f0; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-align: left; }
.guide-article td { padding: 8px 11px; border-bottom: 1px solid var(--border); color: var(--text-secondary); line-height: 1.48; text-align: left; vertical-align: top; }
.guide-article tr:last-child td { border-bottom: 0; }
.guide-article tr:nth-child(even) td { background: #f9fafb; }
.code-block { margin: 14px 0 18px; border-radius: 6px; overflow: hidden; background: #0d1117; }
.code-toolbar { height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px 0 15px; border-bottom: 1px solid #252d38; color: #64748b; font: 10px/1 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; }
.copy-button { padding: 4px 8px; border: 1px solid #303a49; border-radius: 4px; background: none; color: #94a3b8; cursor: pointer; font: 10px/1 var(--font-sans); text-transform: none; }
.copy-button:hover { border-color: var(--accent); color: var(--accent); }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; color: #e2e8f0; font: 12px/1.7 var(--font-mono); tab-size: 2; }
.code-block pre code { font: inherit; }

/* ── DIRECTORY AND PAGE NAVIGATION ── */
.unit-directory { margin-top: 48px; }
.unit-directory > h2 { margin-bottom: 14px; color: var(--text-primary); font-size: 18px; }
.unit-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.unit-card {
  position: relative;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 42px 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: var(--shadow);
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.unit-card:hover { transform: translateY(-2px); border-color: var(--accent-dim); }
.unit-number { color: var(--accent-dim); font: 10px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.unit-card strong { font-size: 13.5px; line-height: 1.35; }
.unit-arrow { position: absolute; top: 50%; right: 16px; color: var(--accent-dim); transform: translateY(-50%); }
.page-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 54px; padding-top: 20px; border-top: 1px solid var(--border); }
.page-navigation-link { display: flex; flex-direction: column; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); box-shadow: var(--shadow); text-decoration: none; }
.page-navigation-link:hover { border-color: var(--accent-dim); }
.page-navigation-link span { color: var(--text-muted); font: 10px/1.4 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; }
.page-navigation-link strong { margin-top: 4px; color: var(--text-primary); font-size: 12.5px; line-height: 1.4; }
.page-navigation-link.next { text-align: right; }

/* ── SEARCH RESULTS ── */
.search-popover {
  position: fixed;
  z-index: 300;
  top: 58px;
  right: 52px;
  width: min(620px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 78px));
  overflow: hidden;
  border: 1px solid #30363d;
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.3);
}
.search-popover-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--sidebar-bg); }
.search-popover-header strong { color: #e2e8f0; font-size: 12px; }
.search-status { color: #94a3b8; font-size: 11px; }
.search-results { max-height: min(560px, calc(100vh - 126px)); overflow-y: auto; padding: 6px; }
.search-result { display: block; padding: 10px 11px; border-radius: 6px; color: var(--text-primary); text-decoration: none; }
.search-result:hover, .search-result:focus { background: var(--content-bg); outline: none; }
.search-result small { display: block; color: var(--accent-dim); font: 10px/1.4 var(--font-mono); }
.search-result strong { display: block; margin: 2px 0; color: var(--text-primary); font-size: 13px; }
.search-result p { margin: 0; color: var(--text-secondary); font-size: 11.5px; line-height: 1.45; }
.search-result mark { border-radius: 2px; background: #fef08a; color: #111827; }
.scroll-top { position: fixed; z-index: 80; right: 22px; bottom: 22px; width: 34px; height: 34px; border: 1px solid #2d3748; border-radius: 50%; background: var(--sidebar-bg); color: #94a3b8; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.scroll-top.visible { opacity: 1; pointer-events: auto; }

/* ── DARK MODE ── */
html.dark {
  color-scheme: dark;
  --content-bg: #0d1117;
  --card-bg: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #9aa4b2;
  --text-muted: #6e7681;
  --border: #30363d;
  --border-strong: #374151;
  --accent-dim: #ffec6e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --warning-bg: rgba(245, 158, 11, 0.11);
}
html.dark .guide-article :not(pre) > code { border-color: var(--border); background: #1f2937; color: #ffec6e; }
html.dark .topic { border-color: var(--border); background: var(--card-bg); }
html.dark .topic-trigger:hover, html.dark .topic.open .topic-trigger { background: rgba(255, 255, 255, 0.04); }
html.dark .guide-article tr:nth-child(even) td { background: rgba(255, 255, 255, 0.03); }
html.dark .guide-article th { background: #161b22; }
html.dark .search-result:hover, html.dark .search-result:focus { background: rgba(255, 255, 255, 0.04); }

/* ── MOBILE ── */
@media (max-width: 768px) {
  body { height: auto; overflow: auto; }
  .layout-row { overflow: visible; }
  .menu-btn { display: flex; }
  .top-header-title { display: none; }
  .top-search-wrap { width: clamp(130px, 35vw, 220px); }
  .top-search-meta { display: none; }
  .sidebar { position: fixed; top: 0; left: 0; width: min(300px, 85vw); min-width: 0; height: 100dvh; transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar.open { transform: translateX(0); }
  .main { width: 100%; height: auto; overflow: visible; padding: 24px 16px 80px; }
  .how-to-use { grid-template-columns: 1fr; }
  .search-popover { right: 14px; }
}

@media (max-width: 580px) {
  .top-header { gap: 8px; padding-inline: 11px; }
  .home-btn { display: none; }
  .top-header-right { gap: 6px; }
  .top-search-wrap { width: min(54vw, 220px); }
  .unit-grid, .page-navigation { grid-template-columns: 1fr; }
  .page-navigation > span { display: none; }
  .page-navigation-link.next { text-align: left; }
  .section-body { overflow-x: auto; }
  .guide-article table { min-width: 580px; }
}

@media print {
  body { display: block; height: auto; overflow: visible; background: white; color: black; }
  .top-header, .sidebar, .sidebar-backdrop, .search-popover, .scroll-top, .unit-directory, .page-navigation { display: none !important; }
  .layout-row, .main { display: block; height: auto; overflow: visible; padding: 0; }
  .guide-article { max-width: none; }
  .section-title { border: 1px solid #999; background: white; color: black; }
  .section-body { box-shadow: none; }
  .guide-section, .code-block { break-inside: avoid; }
}
