/* ==========================================================================
   System Design — Architect's Drafting Theme
   Palette: warm off-white + steel blue + amber accent
   Cảm hứng: bàn vẽ kỹ sư kiến trúc — component diagram + arrow
   ========================================================================== */

:root {
  --bg:           #f4f1eb;          /* warm off-white drafting paper */
  --bg-alt:       #ece7dc;          /* slightly darker — nav strip */
  --bg-card:      #fbf8f1;          /* card / surface */
  --bg-deep:      #e2dccc;          /* deeper cream for emphasis */

  --text:         #1f2937;          /* charcoal */
  --text-soft:    #374151;
  --text-muted:   #6b7280;
  --ink:          #0f172a;          /* deepest for headings */

  --steel:        #2c4a6b;          /* primary accent — borders, links */
  --steel-deep:   #1e3550;          /* emphasis */
  --steel-soft:   #dbe5f0;          /* tint background */
  --amber:        #c47b00;          /* highlight */
  --amber-soft:   #f4e7c9;
  --slate:        #475569;          /* secondary */
  --olive:        #4a7048;          /* tertiary — success */
  --rust:         #b3401c;          /* warning / important */

  --border:       #c8c0ad;          /* warm gray-blue border */
  --border-soft:  #ddd5c4;
  --shadow-sm:    0 1px 2px rgba(31,41,55,0.06);
  --shadow-md:    0 4px 12px rgba(31,41,55,0.10);
  --shadow-lg:    0 10px 32px rgba(31,41,55,0.14);

  --font-body:    "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "IBM Plex Serif", "Source Serif Pro", Georgia, serif;
  --font-mono:    "JetBrains Mono", "Fira Code", "Menlo", monospace;

  --radius-sm: 3px;
  --radius:    6px;
  --radius-lg: 12px;

  --container: 1200px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  /* Subtle drafting grid */
  background-image:
    linear-gradient(rgba(44,74,107,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44,74,107,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: -1px -1px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
h1 { font-size: 2.5rem; margin: 0 0 0.6rem; }
h2 {
  font-size: 1.85rem;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--steel);
  position: relative;
}
h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 60px;
  height: 2px;
  background: var(--amber);
}
h3 {
  font-size: 1.35rem;
  margin: 1.9rem 0 0.7rem;
  color: var(--steel-deep);
  font-weight: 600;
}
h4 {
  font-size: 1.05rem;
  margin: 1.2rem 0 0.5rem;
  color: var(--slate);
  font-family: var(--font-body);
  font-weight: 600;
}

p { margin: 0.7rem 0; }
strong { color: var(--ink); font-weight: 600; }
em { color: var(--text-soft); }

a {
  color: var(--steel);
  text-decoration: none;
  border-bottom: 1px dotted var(--steel);
  transition: color 0.15s, border-color 0.15s;
}
a:hover { color: var(--steel-deep); border-bottom-style: solid; }

ul, ol { padding-left: 1.4rem; }
li { margin: 0.35rem 0; }

hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 2rem 0;
}

blockquote {
  border-left: 3px solid var(--steel);
  margin: 1.5rem 0;
  padding: 0.4rem 0 0.4rem 1.4rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-soft);
  background: var(--steel-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ---------- Layout ---------- */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(244,241,235,0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
  gap: 18px;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--steel-deep);
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo::before {
  content: "";
  display: inline-block;
  width: 26px;
  height: 26px;
  border: 2px solid var(--steel);
  border-radius: 3px;
  position: relative;
  background:
    linear-gradient(var(--steel), var(--steel)) no-repeat 4px 7px / 14px 1.5px,
    linear-gradient(var(--steel), var(--steel)) no-repeat 4px 13px / 9px 1.5px,
    linear-gradient(var(--amber), var(--amber)) no-repeat 4px 19px / 5px 1.5px,
    var(--bg-card);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 22px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  padding: 6px 0;
  transition: border-color 0.2s, color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--steel-deep);
  border-bottom-color: var(--steel);
}

/* ---------- Hero ---------- */
.hero {
  padding: 70px 0 50px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.hero h1 {
  font-size: 3.1rem;
  margin-bottom: 1rem;
  letter-spacing: -0.015em;
}

.hero .subtitle {
  font-size: 1.15rem;
  color: var(--text-soft);
  max-width: 740px;
  line-height: 1.65;
}

.hero .badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 1.4rem;
}

.badge {
  display: inline-block;
  padding: 4px 14px;
  background: var(--steel-soft);
  color: var(--steel-deep);
  border: 1px solid var(--steel);
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.badge-amber { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); }
.badge-olive { background: #e3eadd; color: var(--olive); border-color: var(--olive); }
.badge-rust  { background: #f3dccf; color: var(--rust); border-color: var(--rust); }

/* ---------- Section ---------- */
.section {
  padding: 60px 0;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; }
.section .lead {
  font-size: 1.05rem;
  color: var(--text-soft);
  max-width: 800px;
  line-height: 1.6;
}

/* ---------- Roadmap (chapter cards) ---------- */
.roadmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 22px;
  margin-top: 32px;
}

.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 24px;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
  border-bottom: none;
}

.chapter-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 0;
  background: var(--steel);
  border-radius: var(--radius) var(--radius) 0 0;
  transition: height 0.2s;
}

.chapter-card::after {
  content: "";
  position: absolute;
  top: 14px; right: 14px;
  width: 24px; height: 24px;
  border: 1.5px solid var(--steel);
  border-radius: 50%;
  background: var(--bg);
  transition: background 0.2s, transform 0.2s;
}

.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--steel);
  box-shadow: var(--shadow-md);
}
.chapter-card:hover::before { height: 4px; }
.chapter-card:hover::after { background: var(--amber); transform: scale(1.1); }

.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--steel);
  letter-spacing: 0.14em;
  margin-bottom: 8px;
  text-transform: uppercase;
  font-weight: 500;
}

.chapter-card h3 {
  margin: 0 0 10px;
  font-size: 1.2rem;
  color: var(--ink);
  font-weight: 600;
  padding-right: 36px;
}

.chapter-card p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.92rem;
  line-height: 1.6;
}

.chapter-card .topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 14px;
}

.chapter-card .topic-tag {
  font-size: 0.72rem;
  padding: 2px 9px;
  background: var(--bg-deep);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ---------- Chapter pages ---------- */
.chapter-hero {
  padding: 55px 0 32px;
  border-bottom: 1px solid var(--border);
}

.chapter-hero .label {
  font-family: var(--font-mono);
  color: var(--amber);
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 10px;
  font-weight: 600;
}

.chapter-hero h1 {
  font-size: 2.55rem;
  margin: 0 0 16px;
}

.chapter-hero .subtitle {
  font-size: 1.1rem;
  color: var(--text-soft);
  max-width: 800px;
  line-height: 1.6;
}

.chapter-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 50px;
  padding: 36px 0 70px;
}

.toc {
  position: sticky;
  top: 80px;
  align-self: start;
  font-size: 0.88rem;
  border-left: 2px solid var(--steel);
  padding-left: 18px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.toc h4 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--steel-deep);
  margin: 0 0 14px;
  font-weight: 600;
}

.toc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.toc li { margin: 5px 0; }

.toc a {
  color: var(--text-soft);
  border-bottom: none;
  display: block;
  padding: 3px 0;
  line-height: 1.4;
  transition: color 0.15s, padding-left 0.15s;
}

.toc a:hover {
  color: var(--steel-deep);
  padding-left: 4px;
}

.chapter-body {
  max-width: 820px;
}

.chapter-body section {
  scroll-margin-top: 80px;
  margin-bottom: 38px;
}

/* ---------- Cards & Callouts ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin: 18px 0;
}

.callout {
  border-left: 3px solid var(--steel);
  background: var(--bg-card);
  padding: 16px 22px;
  margin: 20px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.callout-title {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--steel-deep);
  margin-bottom: 6px;
  font-weight: 600;
}

.callout-warn { border-left-color: var(--rust); background: #f9e7df; }
.callout-warn .callout-title { color: var(--rust); }

.callout-tip { border-left-color: var(--olive); background: #e7eedf; }
.callout-tip .callout-title { color: var(--olive); }

.callout-note { border-left-color: var(--amber); background: var(--amber-soft); }
.callout-note .callout-title { color: var(--amber); }

/* ---------- Code blocks ---------- */
pre {
  background: #1a2330;
  color: #d6e0ec;
  border: 1px solid var(--steel-deep);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.6;
  position: relative;
  margin: 16px 0;
}

pre code { font-family: inherit; color: inherit; background: none; padding: 0; }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--steel-soft);
  color: var(--steel-deep);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(44,74,107,0.18);
}

.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  background: rgba(244,241,235,0.1);
  color: #d6e0ec;
  border: 1px solid rgba(214,224,236,0.3);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s, background 0.15s, color 0.15s;
}

pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.copy-btn.copied { background: var(--olive); color: var(--bg-card); border-color: var(--olive); }

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 0.92rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 11px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

th {
  background: var(--steel);
  color: var(--bg-card);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(44,74,107,0.04); }

/* ---------- Component box (architecture diagram) ---------- */
.comp-box {
  display: inline-block;
  border: 2px solid var(--steel);
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin: 8px 14px 8px 0;
  vertical-align: top;
  min-width: 140px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.comp-box .comp-name {
  background: var(--steel);
  color: var(--bg-card);
  padding: 6px 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
  text-align: center;
}

.comp-box ul {
  list-style: none;
  padding: 8px 14px;
  margin: 0;
}

.comp-box li {
  margin: 3px 0;
  font-size: 0.84rem;
  color: var(--text-soft);
}

/* ---------- ASCII diagram ---------- */
.ascii {
  background: #1a2330;
  color: #d6e0ec;
  border: 1px solid var(--steel-deep);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  margin: 18px 0;
}

/* ---------- Compare boxes ---------- */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 20px 0;
}

.compare > div {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
}

.compare h4 {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--steel-deep);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Quiz ---------- */
.quiz {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 4px solid var(--steel);
  border-radius: var(--radius);
  padding: 26px 30px;
  margin: 32px 0;
}

.quiz h3 {
  margin-top: 0;
  color: var(--steel-deep);
  display: flex;
  align-items: center;
  gap: 12px;
}

.quiz h3::before {
  content: "?";
  font-family: var(--font-display);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  background: var(--steel);
  color: var(--bg-card);
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.1rem;
}

.quiz-question {
  margin: 20px 0;
  padding-bottom: 20px;
  border-bottom: 1px dashed var(--border);
}
.quiz-question:last-child { border-bottom: none; padding-bottom: 0; }

.quiz-question .q-text {
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--ink);
}

.quiz-options {
  list-style: none;
  padding: 0;
  margin: 0;
}

.quiz-option {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 7px 0;
  cursor: pointer;
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-option::before {
  content: "○";
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.quiz-option:hover {
  border-color: var(--steel);
  background: var(--steel-soft);
}

.quiz-option.correct {
  background: #e3eadd;
  border-color: var(--olive);
  color: var(--olive);
}
.quiz-option.correct::before { content: "✓"; color: var(--olive); }

.quiz-option.wrong {
  background: #f3dccf;
  border-color: var(--rust);
  color: var(--rust);
}
.quiz-option.wrong::before { content: "✗"; color: var(--rust); }

.quiz-explain {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--bg-deep);
  border-left: 3px solid var(--steel);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
  color: var(--text-soft);
  display: none;
}
.quiz-explain.show { display: block; }

/* ---------- Chapter dropdown menu ---------- */
.chapter-jump { position: relative; }

.chapter-jump-btn {
  background: var(--bg-card);
  color: var(--steel-deep);
  border: 1px solid var(--steel);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}

.chapter-jump-btn:hover {
  background: var(--steel);
  color: var(--bg-card);
}

.chapter-jump-btn::after { content: "▾"; font-size: 0.75rem; }

.chapter-jump-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 380px;
  max-height: 480px;
  overflow-y: auto;
  z-index: 100;
  padding: 6px;
}

.chapter-jump-menu.open { display: block; }

.chapter-jump-menu a {
  display: flex;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
  align-items: center;
  transition: background 0.12s;
}

.chapter-jump-menu a:hover {
  background: var(--steel-soft);
  color: var(--steel-deep);
}

.chapter-jump-menu a.current {
  background: var(--steel);
  color: var(--bg-card);
}

.chapter-jump-menu .ch-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
  min-width: 44px;
  letter-spacing: 0.04em;
}
.chapter-jump-menu a.current .ch-num { color: var(--bg-card); opacity: 0.85; }

/* ---------- Steps list ---------- */
.steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}

.steps li {
  counter-increment: step;
  padding: 12px 0 12px 56px;
  position: relative;
  border-bottom: 1px dashed var(--border);
}
.steps li:last-child { border-bottom: none; }

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: 12px;
  width: 36px; height: 36px;
  background: var(--steel);
  color: var(--bg-card);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
}

/* ---------- Footer ---------- */
.site-footer {
  padding: 36px 0;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 40px;
}

.site-footer a { color: var(--steel); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .chapter-layout { grid-template-columns: 1fr; }
  .toc {
    position: static;
    border-left: none;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    margin-bottom: 24px;
    max-height: none;
  }
  .compare { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2.4rem; }
  .nav-links { gap: 12px; }
  .nav-links a:not(.chapter-jump-btn) { display: none; }
}

@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .hero { padding: 50px 0 35px; }
  .hero h1 { font-size: 2rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.4rem; }
  pre { font-size: 0.78rem; padding: 14px 14px; }
}

::selection {
  background: var(--steel);
  color: var(--bg-card);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-alt); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
