/* ============================================================
   Programming Language pillar — Shared base CSS
   Provides structure. Theme CSS (Dart/Flutter) overrides palette via :root variables.
   ============================================================ */

/* --- Reset + box-sizing --- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16.5px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; }
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 36px 0;
}

/* --- Selection + scrollbar --- */
::selection { background: var(--accent); color: var(--bg-card); }

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  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: 16px;
}
.site-logo {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: -0.01em;
}
.site-logo .mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
}
.site-nav {
  display: flex;
  align-items: center;
  gap: 22px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.92rem;
}
.site-nav a {
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a.active { color: var(--accent); }

/* --- Container --- */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}
.container.narrow { max-width: 880px; }
.container.reading { max-width: 760px; }

/* --- 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: 80px;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* --- Typography (prose) --- */
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-display);
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.prose h1 {
  font-size: 2.6rem;
  margin: 0 0 12px;
  font-weight: 700;
}
.prose h2 {
  font-size: 1.85rem;
  margin: 56px 0 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 12px;
  scroll-margin-top: 80px;
}
.prose h3 {
  font-size: 1.35rem;
  margin: 40px 0 12px;
  font-weight: 600;
  color: var(--accent-deep, var(--ink));
  scroll-margin-top: 80px;
}
.prose h4 {
  font-size: 1.08rem;
  margin: 28px 0 10px;
  font-weight: 600;
  color: var(--accent-deep, var(--ink));
}
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 12px 0 18px; padding-left: 26px; }
.prose li { margin-bottom: 6px; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose em { font-style: italic; }
.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}
.prose a:hover { text-decoration-color: var(--accent); }

/* Anchor links — heading hover */
.prose h2, .prose h3 { position: relative; }
.prose h2 .anchor, .prose h3 .anchor {
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }

/* --- Lead paragraph (chapter intro) --- */
.lead {
  font-size: 1.18rem;
  line-height: 1.65;
  color: var(--text-soft);
  font-family: var(--font-display);
  font-weight: 400;
  margin: 0 0 24px;
}

/* --- Chapter header --- */
.chapter-header {
  padding: 48px 0 28px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 36px;
}
.chapter-header .breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.chapter-header .breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}
.chapter-header .breadcrumb a:hover { color: var(--accent); }
.chapter-header .breadcrumb .sep { margin: 0 8px; opacity: 0.5; }
.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.chapter-meta .item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chapter-meta .item strong {
  color: var(--text-soft);
  font-weight: 500;
}

/* --- Hero (used on index pages) --- */
.hero {
  padding: 80px 0 48px;
  text-align: center;
}
.hero .eyebrow {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  font-weight: 600;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: 3.4rem;
  line-height: 1.08;
  margin: 0 0 18px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.hero .subtitle {
  font-size: 1.18rem;
  color: var(--text-soft);
  max-width: 680px;
  margin: 0 auto 24px;
  line-height: 1.6;
}

/* --- Section helpers --- */
.section {
  padding: 56px 0;
}
.section + .section { padding-top: 24px; }
.section-title {
  font-family: var(--font-display);
  font-size: 1.7rem;
  margin: 0 0 14px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.section-lead {
  color: var(--text-soft);
  font-size: 1.04rem;
  margin: 0 0 32px;
  max-width: 720px;
}

/* --- Callouts --- */
.callout {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  padding: 16px 20px;
  margin: 24px 0;
  font-size: 0.97rem;
  line-height: 1.65;
}
.callout p:last-child { margin-bottom: 0; }
.callout .callout-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.callout-note { --callout-color: #2563eb; border-left-color: var(--callout-color); }
.callout-note .callout-label { color: var(--callout-color); }
.callout-note { background: rgba(37, 99, 235, 0.07); }

.callout-tip { --callout-color: #059669; border-left-color: var(--callout-color); }
.callout-tip .callout-label { color: var(--callout-color); }
.callout-tip { background: rgba(5, 150, 105, 0.07); }

.callout-warning { --callout-color: #d97706; border-left-color: var(--callout-color); }
.callout-warning .callout-label { color: var(--callout-color); }
.callout-warning { background: rgba(217, 119, 6, 0.08); }

.callout-goal { --callout-color: #7c3aed; border-left-color: var(--callout-color); }
.callout-goal .callout-label { color: var(--callout-color); }
.callout-goal { background: rgba(124, 58, 237, 0.07); }

.callout-mental { --callout-color: #db2777; border-left-color: var(--callout-color); }
.callout-mental .callout-label { color: var(--callout-color); }
.callout-mental { background: rgba(219, 39, 119, 0.07); }

.callout-gotcha { --callout-color: #dc2626; border-left-color: var(--callout-color); }
.callout-gotcha .callout-label { color: var(--callout-color); }
.callout-gotcha { background: rgba(220, 38, 38, 0.07); }

.callout-compare { --callout-color: #0891b2; border-left-color: var(--callout-color); }
.callout-compare .callout-label { color: var(--callout-color); }
.callout-compare { background: rgba(8, 145, 178, 0.07); }

/* --- Code block --- */
pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 18px 22px;
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
  margin: 18px 0;
  border: 1px solid var(--border-soft);
  position: relative;
}
pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
:not(pre) > code {
  background: var(--code-inline-bg);
  color: var(--code-inline-fg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  font-weight: 500;
  border: 1px solid var(--border-soft);
}

.code-wrap {
  position: relative;
  margin: 18px 0;
}
.code-wrap pre { margin: 0; }
.code-wrap .code-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in srgb, var(--code-bg) 70%, var(--bg) 30%);
  border: 1px solid var(--border-soft);
  border-bottom: none;
  padding: 7px 14px;
  border-radius: 10px 10px 0 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.code-wrap .code-meta + pre { border-radius: 0 0 10px 10px; }
.code-wrap .copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.code-wrap .copy-btn:hover {
  background: var(--accent);
  color: var(--bg-card);
  border-color: var(--accent);
}
.code-wrap .copy-btn.copied {
  background: #059669;
  color: white;
  border-color: #059669;
}

/* Syntax highlight tokens (manual classes since no Prism by default) */
.tok-kw { color: var(--syn-kw); font-weight: 600; }
.tok-type { color: var(--syn-type); }
.tok-str { color: var(--syn-str); }
.tok-num { color: var(--syn-num); }
.tok-com { color: var(--syn-com); font-style: italic; }
.tok-fn { color: var(--syn-fn); }
.tok-op { color: var(--syn-op); }
.tok-cls { color: var(--syn-cls); }

/* --- Table --- */
.table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}
th, td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-soft);
}
th {
  font-family: var(--font-display);
  font-weight: 600;
  background: var(--bg-alt);
  color: var(--ink);
  font-size: 0.9rem;
}
tr:last-child td { border-bottom: none; }
td code { font-size: 0.86em; }

/* --- Blockquote --- */
blockquote {
  border-left: 3px solid var(--gold, var(--accent));
  padding: 10px 0 10px 22px;
  margin: 24px 0;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-soft);
  font-size: 1.08rem;
  line-height: 1.6;
}

/* --- Quiz --- */
.quiz {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 18px 0;
  padding: 0;
  overflow: hidden;
}
.quiz-question {
  padding: 16px 20px 14px;
  display: flex;
  gap: 12px;
  font-weight: 500;
}
.quiz-num {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 4px;
  height: fit-content;
}
.quiz-q-text { flex: 1; }
.quiz-q-text p { margin: 0; }
.quiz details {
  border-top: 1px solid var(--border-soft);
  background: var(--bg-alt);
}
.quiz summary {
  padding: 10px 20px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  user-select: none;
}
.quiz summary:hover { color: var(--accent); }
.quiz details[open] summary { color: var(--accent); border-bottom: 1px solid var(--border-soft); }
.quiz-answer {
  padding: 14px 20px 18px;
  font-size: 0.94rem;
  line-height: 1.65;
}
.quiz-answer p:last-child { margin-bottom: 0; }
.quiz-answer .answer-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #059669;
  text-transform: uppercase;
  margin-right: 6px;
}

/* --- Exercise --- */
.exercise {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin: 18px 0;
  position: relative;
}
.exercise::before {
  content: "Bài " counter(exercise);
  counter-increment: exercise;
  position: absolute;
  top: -10px;
  left: 18px;
  background: var(--accent);
  color: var(--bg-card);
  padding: 3px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.exercises { counter-reset: exercise; }
.exercise h4 {
  margin: 6px 0 8px;
  font-family: var(--font-display);
  font-size: 1.08rem;
  color: var(--ink);
}
.exercise-body p:first-child { margin-top: 0; }
.exercise-body p:last-child { margin-bottom: 0; }
.exercise-hint {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.exercise-hint summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}
.exercise-hint summary:hover { color: var(--accent); }
.exercise-hint .hint-content {
  margin-top: 12px;
  font-size: 0.94rem;
  color: var(--text-soft);
  line-height: 1.65;
}

/* --- TOC sidebar --- */
.layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 56px;
  align-items: start;
  padding: 28px 0 80px;
}
.layout main { min-width: 0; }
.layout .toc {
  position: sticky;
  top: 84px;
  align-self: start;
  font-size: 0.86rem;
  line-height: 1.55;
  border-left: 1px solid var(--border-soft);
  padding-left: 18px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}
.toc-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { margin-bottom: 5px; }
.toc a {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  padding: 2px 0;
  border-left: 2px solid transparent;
  padding-left: 10px;
  margin-left: -12px;
  transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--accent); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.toc li.level-3 a { padding-left: 22px; font-size: 0.83rem; }

/* --- Chapter navigation (prev/next at bottom) --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 60px;
  padding-top: 36px;
  border-top: 1px solid var(--border-soft);
}
.chapter-nav a {
  flex: 1;
  text-decoration: none;
  color: var(--text);
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  transition: border-color 0.15s, transform 0.15s;
  max-width: 48%;
}
.chapter-nav a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.chapter-nav .dir {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.chapter-nav .label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.04rem;
  color: var(--ink);
}
.chapter-nav .next { text-align: right; }

/* --- Chapter list card (used in sub-pillar TOC) --- */
.chapters {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}
.chapter-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.chapter-card:hover {
  border-color: var(--accent);
  transform: translateX(2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}
.chapter-card .num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.chapter-card .info h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
}
.chapter-card .info p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-soft);
  line-height: 1.5;
}
.chapter-card .cta {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
.chapter-card.locked {
  opacity: 0.55;
  pointer-events: none;
}
.chapter-card.locked .cta { color: var(--text-muted); }

/* --- DartPad / iframe embed --- */
.dartpad {
  margin: 18px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-card);
}
.dartpad-frame {
  width: 100%;
  height: 480px;
  border: none;
  display: block;
}
.dartpad-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.dartpad-label a {
  color: var(--accent);
  text-decoration: none;
}

/* --- Diagram / figure --- */
figure {
  margin: 24px 0;
  text-align: center;
}
figure svg, figure img {
  display: inline-block;
  max-width: 100%;
}
figcaption {
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-display);
}

/* --- Kbd (keyboard key) --- */
kbd {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 1px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink);
  box-shadow: 0 1px 0 var(--border);
}

/* --- Badge / tag --- */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 9px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
}

/* --- Progress bar (chapter progress on TOC) --- */
.progress {
  height: 6px;
  background: var(--bg-alt);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.progress > .fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* --- Responsive --- */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  .layout .toc {
    position: static;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--border-soft);
    padding-left: 0;
    padding-top: 24px;
    order: 2;
  }
  .hero h1 { font-size: 2.6rem; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .container { padding: 0 18px; }
  .hero { padding: 56px 0 32px; }
  .hero h1 { font-size: 2rem; }
  .prose h1 { font-size: 2rem; }
  .prose h2 { font-size: 1.5rem; }
  .prose h3 { font-size: 1.2rem; }
  .chapter-card { grid-template-columns: 44px 1fr; }
  .chapter-card .cta { display: none; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
}

/* --- Print --- */
@media print {
  .site-header, .site-footer, .toc, .chapter-nav { display: none; }
  body { background: white; color: black; font-size: 11pt; }
  .prose h2, .prose h3 { break-after: avoid; }
  pre { break-inside: avoid; }
}
