/* ==========================================================================
   OS Exam-Prep Study Site — Shared Stylesheet
   Pure static. No external fonts/CDNs/frameworks. Works offline.
   Light theme default; dark theme via [data-theme="dark"] on <html>.
   ========================================================================== */

/* ---------- Design tokens ------------------------------------------------- */
:root {
  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Layout */
  --header-h: 56px;
  --sidebar-w: 280px;
  --content-max: 820px;
  --radius: 10px;
  --radius-sm: 6px;

  /* Light palette */
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sunken: #eef1f5;
  --text: #1a1f2b;
  --text-muted: #5b6472;
  --border: #dce1e8;
  --border-strong: #c2cad6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8f0fe;
  --term-bg: #eef4ff;
  --term-text: #1d4ed8;
  --term-border: #c7dbff;

  /* Semantic callouts */
  --summary-bg: #eef6ef;
  --summary-border: #2e7d4f;
  --note-bg: #eef4ff;
  --note-border: #2563eb;
  --warn-bg: #fdf2e7;
  --warn-border: #d97706;

  --code-bg: #eef1f5;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, 0.10);

  --focus: 0 0 0 3px rgba(37, 99, 235, 0.45);
}

[data-theme="dark"] {
  --bg: #0f141b;
  --bg-elev: #161c26;
  --bg-sunken: #1c2430;
  --text: #e7ebf2;
  --text-muted: #9aa6b6;
  --border: #283142;
  --border-strong: #38445a;
  --accent: #6ea8ff;
  --accent-hover: #93beff;
  --accent-soft: #1c2940;
  --term-bg: #16263f;
  --term-text: #9cc4ff;
  --term-border: #2c456e;

  --summary-bg: #13251c;
  --summary-border: #3fae72;
  --note-bg: #16263f;
  --note-border: #6ea8ff;
  --warn-bg: #2c2113;
  --warn-border: #e0a042;

  --code-bg: #1c2430;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.5);
}

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

html {
  scroll-behavior: smooth;
  /* offset anchored sections so they clear the sticky header */
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--radius-sm);
}

img {
  max-width: 100%;
  height: auto;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -60px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: var(--space-3);
}

/* ---------- Header -------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.hamburger {
  display: none; /* visible only on mobile */
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.hamburger svg {
  width: 22px;
  height: 22px;
}
.hamburger:hover {
  background: var(--bg-sunken);
}

.site-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.site-title:hover {
  text-decoration: none;
}

.main-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.main-nav a,
.nav-dropdown > .nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  background: transparent;
  border: 0;
  font-family: inherit;
}
.main-nav a:hover,
.nav-dropdown > .nav-link:hover {
  background: var(--bg-sunken);
  color: var(--text);
  text-decoration: none;
}
.main-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Final dropdown (CSS hover on desktop, JS toggle on mobile) */
.nav-dropdown {
  position: relative;
}
.nav-dropdown > .nav-link::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  margin-left: 2px;
}
.nav-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: var(--space-2);
  display: none;
  flex-direction: column;
  gap: 2px;
}
.nav-dropdown:hover .nav-menu,
.nav-dropdown:focus-within .nav-menu,
.nav-dropdown.open .nav-menu {
  display: flex;
}
.nav-menu a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
}
.nav-menu a:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}
.nav-menu .menu-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3) var(--space-1);
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: var(--space-2);
}
.theme-toggle:hover {
  background: var(--bg-sunken);
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
}
.theme-toggle .icon-sun {
  display: none;
}
[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}
[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

/* ---------- Layout shell -------------------------------------------------- */
.layout {
  display: flex;
  align-items: flex-start;
}

/* Sidebar (per-page TOC) */
.sidebar {
  position: sticky;
  top: var(--header-h);
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: var(--space-5) var(--space-4);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}
.sidebar-title {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
}
.toc,
.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc li {
  margin: 1px 0;
}
.toc a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  border-left: 2px solid transparent;
}
.toc a:hover {
  background: var(--bg-sunken);
  color: var(--text);
  text-decoration: none;
}
.toc a.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}
/* nested (subsection) links on combined pages */
.toc .toc-sub {
  padding-left: var(--space-3);
}
.toc .toc-sub a {
  font-size: 0.85rem;
  padding-left: var(--space-4);
}
.toc .toc-group-label {
  display: block;
  margin: var(--space-4) 0 var(--space-1);
  padding: 0 var(--space-3);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Sidebar overlay (mobile only) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(8, 12, 20, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

/* Main content */
.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--space-6) var(--space-6) var(--space-7);
}
.content-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ---------- Typography in content ---------------------------------------- */
.page-title {
  font-size: 1.9rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-2);
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0 0 var(--space-6);
}

.content section {
  margin: 0 0 var(--space-7);
  scroll-margin-top: calc(var(--header-h) + var(--space-4));
}

.section-heading {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding-bottom: var(--space-2);
  margin: 0 0 var(--space-4);
  border-bottom: 2px solid var(--border-strong);
}
.subsection-heading {
  font-size: 1.15rem;
  font-weight: 700;
  margin: var(--space-6) 0 var(--space-3);
}
.content h4 {
  font-size: 1.02rem;
  font-weight: 700;
  margin: var(--space-5) 0 var(--space-2);
}

.content p {
  margin: 0 0 var(--space-4);
}
.content ul,
.content ol {
  margin: 0 0 var(--space-4);
  padding-left: 1.4em;
}
.content li {
  margin: var(--space-1) 0;
}
.content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}
.content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
}
.content pre code {
  background: none;
  padding: 0;
}

/* ---------- Component: English technical term ----------------------------- */
.term {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.92em;
  color: var(--term-text);
  background: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: 5px;
  padding: 0.05em 0.4em;
  white-space: nowrap;
}

/* ---------- Component: Summary callout ------------------------------------ */
.summary-box {
  background: var(--summary-bg);
  border: 1px solid var(--summary-border);
  border-left: 5px solid var(--summary-border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin: 0 0 var(--space-4);
}
.summary-box > :first-child {
  margin-top: 0;
}
.summary-box > :last-child {
  margin-bottom: 0;
}

/* ---------- Component: Core-concept cards / glossary ----------------------- */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-4);
}
.concept-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-1);
}
.concept-card .concept-term {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--term-text);
  margin: 0 0 var(--space-2);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.concept-card .concept-term .ko {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.concept-card .concept-def {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}
.concept-card .concept-def :last-child {
  margin-bottom: 0;
}

/* ---------- Component: Note / Warning callouts ---------------------------- */
.callout {
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-4);
  border: 1px solid;
  border-left-width: 5px;
}
.callout .callout-label {
  font-weight: 700;
  font-size: 0.85rem;
  display: block;
  margin-bottom: var(--space-1);
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout.note {
  background: var(--note-bg);
  border-color: var(--note-border);
}
.callout.note .callout-label {
  color: var(--note-border);
}
.callout.warning {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}
.callout.warning .callout-label {
  color: var(--warn-border);
}

/* ---------- Component: Comparison table ----------------------------------- */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--bg-elev);
}
table caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3);
}
th,
td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  background: var(--bg-sunken);
  font-weight: 700;
  border-bottom: 2px solid var(--border-strong);
  position: sticky;
  top: 0;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover {
  background: var(--bg-sunken);
}

/* ---------- Component: Essay question + collapsible answer ----------------- */
.essay {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 var(--space-4);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.essay .essay-q {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4) var(--space-5);
  font-weight: 600;
  font-size: 1rem;
}
.essay .essay-q .q-num {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.55em;
  font-size: 0.88rem;
  line-height: 1.5;
}
/* <details>/<summary> based answer toggle */
.essay details {
  border-top: 1px solid var(--border);
}
.essay summary {
  cursor: pointer;
  list-style: none;
  padding: var(--space-3) var(--space-5);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  user-select: none;
}
.essay summary::-webkit-details-marker {
  display: none;
}
.essay summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transition: transform 0.15s ease;
}
.essay details[open] summary::before {
  transform: rotate(90deg);
}
.essay summary:hover {
  background: var(--bg-sunken);
}
.essay .essay-a {
  padding: 0 var(--space-5) var(--space-4);
  background: var(--bg-sunken);
  border-top: 1px solid var(--border);
}
.essay .essay-a > :first-child {
  margin-top: var(--space-4);
}
.essay .essay-a > :last-child {
  margin-bottom: 0;
}

/* ---------- Landing page cards (index.html) ------------------------------- */
.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
  margin: var(--space-5) 0 var(--space-6);
}
.exam-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
}
.exam-card h3 {
  margin: 0 0 var(--space-1);
  font-size: 1.2rem;
}
.exam-card .exam-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.15em 0.6em;
  border-radius: 999px;
  margin-bottom: var(--space-3);
}
.exam-card p {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 var(--space-4);
}
.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.chapter-list li {
  margin: 0;
}
.chapter-list a {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.93rem;
}
.chapter-list a:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}
.chapter-list .ch-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 0 0 auto;
}
.exam-card .exam-cta {
  margin-top: auto;
  padding-top: var(--space-4);
}
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
}
.btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

/* ---------- Footer -------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: var(--space-5) var(--space-6);
  text-align: center;
}

/* ---------- Responsive: mobile (<1000px) ---------------------------------- */
@media (max-width: 999px) {
  .hamburger {
    display: inline-flex;
  }

  /* Header nav collapses to dropdown-only essentials */
  .main-nav .nav-link-text-hide {
    display: none;
  }
  .main-nav {
    gap: 0;
  }
  .main-nav .nav-item-secondary {
    display: none; /* keep header light; full nav lives in the Final menu + sidebar */
  }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 95;
    height: 100vh;
    width: min(86vw, var(--sidebar-w));
    padding-top: calc(var(--header-h) + var(--space-4));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-2);
    border-right: 1px solid var(--border);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .content {
    padding: var(--space-5) var(--space-4) var(--space-6);
  }
  .page-title {
    font-size: 1.55rem;
  }
  .section-heading {
    font-size: 1.25rem;
  }
}

/* Prevent body scroll when drawer open (toggled by JS) */
body.drawer-open {
  overflow: hidden;
}

@media (min-width: 1000px) {
  /* On desktop the overlay never shows */
  .sidebar-overlay {
    display: none !important;
  }
}

/* ---------- Print --------------------------------------------------------- */
@media print {
  .site-header,
  .sidebar,
  .sidebar-overlay,
  .site-footer,
  .theme-toggle,
  .hamburger {
    display: none !important;
  }
  .content {
    padding: 0;
  }
  .essay details {
    border: 0;
  }
  .essay .essay-a {
    display: block !important;
  }
}
