/* ==========================================================
   open·explained — hệ thiết kế dùng chung
   ========================================================== */

:root {
  --paper: #f6f1e7;
  --surface: #fffcf6;
  --surface-2: #f0e9dc;
  --ink: #1c2230;
  --ink-2: #454d5e;
  --muted: #7b8191;
  --line: #e2d9c7;
  --line-strong: #cdbfa6;

  --accent: #e0532a;      /* cam đỏ — vật B, điểm nhấn */
  --accent-soft: #fbe3d8;
  --blue: #2b6bd6;        /* vật A */
  --blue-soft: #dce8fb;
  --green: #23926a;
  --green-soft: #d8f0e5;
  --gold: #d9952b;
  --gold-soft: #f8ead0;
  --violet: #6f55cf;
  --violet-soft: #e6e0f8;

  --sky-top: #cfe3f6;
  --sky-bottom: #f3ecdf;
  --ground: #c9b48f;
  --stone: #e9dfcc;
  --stone-dark: #b9a684;

  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28, 34, 48, .06), 0 8px 24px rgba(28, 34, 48, .06);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --maxw: 1120px;
  --textw: 680px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11141b;
    --surface: #191d26;
    --surface-2: #222733;
    --ink: #edf0f5;
    --ink-2: #b9c0cc;
    --muted: #8a92a2;
    --line: #2b3140;
    --line-strong: #3b4354;
    --accent: #ff7b52;
    --accent-soft: #3a2219;
    --blue: #6fa3ff;
    --blue-soft: #1b2a45;
    --green: #4fc797;
    --green-soft: #173329;
    --gold: #f0b35a;
    --gold-soft: #3a2d17;
    --violet: #a48ef5;
    --violet-soft: #2a2442;
    --sky-top: #16233a;
    --sky-bottom: #1d2330;
    --ground: #4a4031;
    --stone: #3a3a40;
    --stone-dark: #57555a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11141b;
  --surface: #191d26;
  --surface-2: #222733;
  --ink: #edf0f5;
  --ink-2: #b9c0cc;
  --muted: #8a92a2;
  --line: #2b3140;
  --line-strong: #3b4354;
  --accent: #ff7b52;
  --accent-soft: #3a2219;
  --blue: #6fa3ff;
  --blue-soft: #1b2a45;
  --green: #4fc797;
  --green-soft: #173329;
  --gold: #f0b35a;
  --gold-soft: #3a2d17;
  --violet: #a48ef5;
  --violet-soft: #2a2442;
  --sky-top: #16233a;
  --sky-bottom: #1d2330;
  --ground: #4a4031;
  --stone: #3a3a40;
  --stone-dark: #57555a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas { display: block; max-width: 100%; }
a { color: var(--blue); text-underline-offset: 3px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

/* ---------- Thanh điều hướng ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: -.01em; color: var(--ink); text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; }
.brand small { font-weight: 500; color: var(--muted); }
.topbar nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.topbar nav a {
  color: var(--ink-2); text-decoration: none; font-size: 15px; padding: 6px 10px; border-radius: 8px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); }
.theme-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer;
}
.theme-btn svg { width: 18px; height: 18px; }
.progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 0;
  background: var(--accent); transition: width .1s linear;
}

/* ---------- Bố cục chung ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
.prose { max-width: var(--textw); margin: 0 auto; }
.prose p { margin: 0 0 1.05em; color: var(--ink-2); }
.prose p strong, .prose li strong { color: var(--ink); }
.prose ul { padding-left: 1.2em; color: var(--ink-2); }
section.block { padding: 56px 0; }
section.block + section.block { border-top: 1px dashed var(--line); }

.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent);
}
.kicker .num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; letter-spacing: 0;
}
h1, h2, h3 { line-height: 1.2; letter-spacing: -.02em; margin: 0; }
h2 { font-size: clamp(26px, 4vw, 36px); margin: 10px 0 18px; }
h3 { font-size: 20px; margin: 0 0 8px; }

.lead { font-size: 19px; color: var(--ink-2); }

/* ---------- Khối tương tác ---------- */
.widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 28px auto;
  overflow: hidden;
}
.widget-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.widget-head .tag {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--violet); background: var(--violet-soft); padding: 3px 9px; border-radius: 999px;
}
.widget-head h3 { margin: 0; font-size: 17px; }
.widget-body { padding: 18px; }
.widget-foot {
  padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2);
  font-size: 14.5px; color: var(--ink-2);
}
.widget canvas { width: 100%; touch-action: manipulation; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; }
.control { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.control > label, .control > .label {
  font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.control output { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; text-transform: none; letter-spacing: 0; }

select, .seg button, .btn {
  font: inherit; font-size: 15px;
}
select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%237b8191' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 11px center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 32px 8px 12px; color: var(--ink); min-height: 40px; cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; transition: transform .12s ease, background .15s ease;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--blue)); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.seg {
  display: inline-flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap;
}
.seg button {
  border: 0; background: transparent; border-radius: 999px; padding: 6px 13px; cursor: pointer;
  color: var(--ink-2); font-size: 14.5px; font-weight: 500; min-height: 34px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; min-width: 150px; height: 28px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: var(--line-strong); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--line-strong); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; margin-top: -8px;
  background: var(--surface); border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
}

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 15px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2.5px solid var(--blue); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px dashed var(--line-strong); background: transparent; border-radius: 999px;
  padding: 5px 12px; font-size: 14px; cursor: pointer; color: var(--ink-2);
}
.chip:hover { border-style: solid; color: var(--ink); background: var(--surface-2); }

/* ---------- Ô số liệu ---------- */
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.readout {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface);
}
.readout .k { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.readout .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.readout .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- Hộp ghi chú ---------- */
.note {
  border-left: 4px solid var(--gold); background: var(--gold-soft);
  padding: 14px 18px; border-radius: 0 12px 12px 0; margin: 22px 0; color: var(--ink);
}
.note.blue { border-color: var(--blue); background: var(--blue-soft); }
.note.green { border-color: var(--green); background: var(--green-soft); }
.note b:first-child { display: block; margin-bottom: 2px; }
.note p { margin: 0; color: var(--ink); }

.formula {
  font-family: var(--serif); font-style: italic; font-size: 26px; text-align: center;
  padding: 18px; margin: 18px 0; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.formula .sub { font-family: var(--font); font-style: normal; font-size: 14px; color: var(--muted); display: block; margin-top: 4px; }

blockquote.quote {
  margin: 28px 0; padding: 0 0 0 20px; border-left: 3px solid var(--accent);
  font-family: var(--serif); font-style: italic; font-size: 21px; line-height: 1.5; color: var(--ink);
}
blockquote.quote cite { display: block; font-family: var(--font); font-style: normal; font-size: 14px; color: var(--muted); margin-top: 8px; }

/* ---------- Chân trang ---------- */
.site-footer {
  border-top: 1px solid var(--line); margin-top: 40px; padding: 32px 0 48px; color: var(--muted); font-size: 14.5px;
}
.site-footer p { margin: 0 0 6px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 640px) {
  body { font-size: 16.5px; }
  section.block { padding: 40px 0; }
  .widget-body { padding: 14px; }
  .widget-head { padding: 12px 14px; }
  .topbar nav a.hide-sm { display: none; }
  .formula { font-size: 22px; }
}

/* chừa chỗ cho thanh đầu trang dính khi nhảy tới mục */
section[id], [id^="w-"] { scroll-margin-top: 76px; }
