/* ==========================================================================
   Database Mastery — Schema Blueprint Light Theme
   Palette: warm off-white BG + deep teal accent (như bản vẽ kiến trúc cho ERD)
   ========================================================================== */

:root {
  --bg:           #f7f5f0;          /* warm off-white blueprint paper */
  --bg-alt:       #efece4;          /* slightly darker — sidebar/nav strip */
  --bg-card:      #fdfcf8;          /* card / code surface */
  --bg-grid:      #e8e4d8;          /* faint grid line color */

  --text:         #1f3030;          /* deep teal-black */
  --text-soft:    #3d5252;          /* secondary text */
  --text-muted:   #6b7373;          /* muted, captions */

  --teal:         #0d6e6e;          /* primary accent — schema lines, links */
  --teal-deep:    #0a4f4f;          /* darker teal — emphasis */
  --teal-soft:    #d6e7e6;          /* subtle teal tint — backgrounds */
  --forest:       #2d5a3d;          /* secondary accent — FK / relationships */
  --rust:         #a04428;          /* warning / important */
  --gold:         #b08838;          /* highlight / PK */

  --border:       #d4cfc1;          /* warm border */
  --border-soft:  #e3dfd2;
  --shadow-sm:    0 1px 2px rgba(31,48,48,0.06);
  --shadow-md:    0 4px 12px rgba(31,48,48,0.08);
  --shadow-lg:    0 8px 28px rgba(31,48,48,0.10);

  --font-body:    "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Fraunces", "Times New Roman", Georgia, serif;
  --font-mono:    "JetBrains Mono", "Fira Code", "Menlo", monospace;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 14px;

  --container: 1180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  /* Subtle blueprint grid */
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  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(--text);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 { font-size: 2.4rem; margin: 0 0 0.6rem; }
h2 { font-size: 1.8rem; margin: 2.4rem 0 1rem; }
h3 { font-size: 1.3rem; margin: 1.8rem 0 0.7rem; color: var(--teal-deep); }
h4 { font-size: 1.05rem; margin: 1.2rem 0 0.5rem; color: var(--text-soft); }

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

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

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

hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 2rem 0;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(247,245,240,0.92);
  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.2rem;
  font-weight: 700;
  color: var(--teal-deep);
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo::before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 24px;
  background:
    linear-gradient(var(--teal), var(--teal)) no-repeat 0 4px / 14px 2px,
    linear-gradient(var(--teal), var(--teal)) no-repeat 0 11px / 14px 2px,
    linear-gradient(var(--teal), var(--teal)) no-repeat 0 18px / 14px 2px,
    var(--bg-card);
  border: 1.5px solid var(--teal);
  border-radius: 3px;
}

.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: none;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s, color 0.2s;
}

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

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

.hero h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}

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

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

.badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--teal-soft);
  color: var(--teal-deep);
  border: 1px solid var(--teal);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-forest { background: #e2ebe5; color: var(--forest); border-color: var(--forest); }
.badge-rust   { background: #f5e2dc; color: var(--rust); border-color: var(--rust); }
.badge-gold   { background: #f3ead4; color: var(--gold); border-color: var(--gold); }

/* ---------- Section ---------- */
.section {
  padding: 50px 0;
  border-bottom: 1px dashed var(--border);
}
.section:last-child { border-bottom: none; }
.section .lead {
  font-size: 1.05rem;
  color: var(--text-soft);
  max-width: 780px;
}

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

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

.chapter-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 0;
  height: 3px;
  background: var(--teal);
  border-radius: var(--radius) var(--radius) 0 0;
  transition: width 0.25s ease;
}

.chapter-card:hover {
  transform: translateY(-2px);
  border-color: var(--teal);
  box-shadow: var(--shadow-md);
  border-bottom-color: var(--border);
}

.chapter-card:hover::before { width: 100%; }

.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--teal);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.chapter-card h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--text);
}

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

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

.chapter-card .topic-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  background: var(--bg-alt);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ---------- Chapter pages: hero + TOC sidebar ---------- */
.chapter-hero {
  padding: 50px 0 30px;
  border-bottom: 1px dashed var(--border);
}

.chapter-hero .label {
  font-family: var(--font-mono);
  color: var(--teal);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

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

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

.toc {
  position: sticky;
  top: 80px;
  align-self: start;
  font-size: 0.88rem;
  border-left: 1px solid var(--border);
  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.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.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(--teal-deep);
  padding-left: 4px;
}

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

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

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

.callout {
  border-left: 3px solid var(--teal);
  background: var(--bg-card);
  padding: 14px 20px;
  margin: 18px 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.08em;
  text-transform: uppercase;
  color: var(--teal-deep);
  margin-bottom: 6px;
  font-weight: 600;
}

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

.callout-tip { border-left-color: var(--forest); }
.callout-tip .callout-title { color: var(--forest); }

.callout-note { border-left-color: var(--gold); }
.callout-note .callout-title { color: var(--gold); }

/* ---------- Code blocks ---------- */
pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text);
  position: relative;
  margin: 14px 0;
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--teal-soft);
  color: var(--teal-deep);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(13,110,110,0.2);
}

pre code .kw   { color: var(--teal-deep); font-weight: 600; }
pre code .str  { color: var(--forest); }
pre code .num  { color: var(--rust); }
pre code .com  { color: var(--text-muted); font-style: italic; }
pre code .fn   { color: var(--gold); }

/* Copy button */
.copy-btn {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--bg);
  color: var(--text-soft);
  border: 1px solid var(--border);
  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(--teal); color: var(--bg-card); border-color: var(--teal); }
.copy-btn.copied { background: var(--forest); color: var(--bg-card); border-color: var(--forest); }

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

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

th {
  background: var(--bg-alt);
  color: var(--teal-deep);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(13,110,110,0.03); }

/* ---------- Schema box (ERD-like) ---------- */
.schema-box {
  display: inline-block;
  border: 2px solid var(--teal);
  border-radius: 6px;
  background: var(--bg-card);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 10px 12px 10px 0;
  vertical-align: top;
  min-width: 200px;
  box-shadow: var(--shadow-sm);
}

.schema-box .schema-title {
  background: var(--teal);
  color: var(--bg-card);
  padding: 6px 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

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

.schema-box li {
  margin: 3px 0;
  padding: 2px 0;
  border-bottom: 1px dotted var(--border-soft);
}
.schema-box li:last-child { border-bottom: none; }

.schema-box .pk { color: var(--gold); font-weight: 700; }
.schema-box .fk { color: var(--forest); font-weight: 600; }
.schema-box .col-type { color: var(--text-muted); float: right; font-size: 0.78rem; }

/* ---------- Quiz ---------- */
.quiz {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin: 30px 0;
}

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

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

.quiz-question {
  margin: 18px 0;
  padding-bottom: 18px;
  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: 10px;
  color: var(--text);
}

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

.quiz-option {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 6px 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(--teal);
  background: var(--teal-soft);
}

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

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

.quiz-explain {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--bg-alt);
  border-left: 3px solid var(--teal);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  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(--teal-deep);
  border: 1px solid var(--teal);
  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(--teal);
  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(--teal-soft);
  color: var(--teal-deep);
}

.chapter-jump-menu a.current {
  background: var(--teal);
  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; }

/* ---------- ASCII diagram block ---------- */
.ascii {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre;
  overflow-x: auto;
  color: var(--text);
  margin: 16px 0;
}

/* ---------- Compare boxes (two-column) ---------- */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 18px 0;
}

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

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

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

.steps li {
  counter-increment: step;
  padding: 10px 0 10px 50px;
  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: 10px;
  width: 32px; height: 32px;
  background: var(--teal);
  color: var(--bg-card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
}

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

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

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

@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .hero { padding: 40px 0 30px; }
  .hero h1 { font-size: 1.8rem; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
  pre { font-size: 0.78rem; padding: 14px 12px; }
}

/* ---------- Highlight selection ---------- */
::selection {
  background: var(--teal);
  color: var(--bg-card);
}

/* ---------- Scrollbar styling (Webkit) ---------- */
::-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); }
