:root {
  --bg: #f0f4f9; --card: #ffffff; --ink: #1e293b; --muted: #64748b; --line: #d9e2ec;
  --brand: #1a4b8c; --brand-2: #0d5ab9; --accent: #f59e0b; --ok: #059669; --bad: #dc2626;
  --radius: 14px; --shadow: 0 2px 10px rgba(15, 40, 80, .08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-text-size-adjust: 100%;
}
a { color: var(--brand-2); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

header.top { background: var(--brand); color: #fff; }
header.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; }
header.top a.home { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: 8px; }
header.top h1 { font-size: 1.05rem; margin: 0; font-weight: 600; opacity: .95; }

.hero { padding: 28px 0 8px; }
.hero h2 { font-size: clamp(1.4rem, 4.5vw, 2rem); margin: 0 0 6px; color: var(--brand); }
.hero p { margin: 0; color: var(--muted); }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin: 20px 0; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line);
  transition: transform .12s, box-shadow .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15, 40, 80, .14); }
.card .ico { font-size: 2rem; }
.card h3 { margin: 0; font-size: 1.08rem; color: var(--brand); }
.card p { margin: 0; color: var(--muted); font-size: .93rem; }
.tag { display: inline-block; font-size: .75rem; background: #e0ecfb; color: var(--brand); padding: 2px 8px; border-radius: 99px; align-self: flex-start; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel h3 { margin: 0 0 10px; font-size: 1rem; color: var(--brand); }
.btn {
  appearance: none; border: 0; border-radius: 10px; background: var(--brand-2); color: #fff; font: inherit; font-weight: 600;
  padding: 10px 16px; min-height: 44px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: #e2e8f0; color: var(--ink); }
.btn.accent { background: var(--accent); color: #1f2937; }
.btn:disabled { opacity: .45; cursor: default; }

.dl { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; }
.dl ol { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: .93rem; }

footer { color: var(--muted); font-size: .85rem; padding: 24px 0 40px; text-align: center; }

/* Simulation pages */
.sim-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin: 16px 0 10px; }
.sim-head h2 { margin: 0; font-size: clamp(1.15rem, 3.6vw, 1.5rem); color: var(--brand); }
.stage { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stage canvas { display: block; width: 100%; height: auto; touch-action: none; }
.controls { display: grid; gap: 10px; margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stepper { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px; }
.stepper b { min-width: 74px; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .btn { min-width: 44px; padding: 8px 0; }
.status { background: #fffbea; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.hint { color: var(--muted); font-size: .88rem; }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.slider:last-child { border-bottom: 0; }
.slider label { font-weight: 600; font-size: .95rem; }
.slider output { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }
.slider input[type=range] { grid-column: 1 / -1; width: 100%; height: 32px; accent-color: var(--brand-2); }
.slider small { grid-column: 1 / -1; color: var(--muted); }

.layout-3 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .layout-3 { grid-template-columns: 340px 1fr; } .layout-3 .visual { grid-row: span 2; } }
.calc .box, .calc .lf { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; white-space: pre-wrap; }
.calc .card2 { white-space: pre-wrap; }
.calc .box { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--line); }
/* Điện thoại: giữ khung hình mô phỏng neuron dính trên đầu khi kéo thanh trượt */
@media (max-width: 979px) {
  .nn .vis { position: sticky; top: 0; z-index: 5; padding: 8px; border-radius: 0 0 var(--radius) var(--radius); }
  .nn .vis h3 { display: none; }
  .nn .vis canvas { max-height: 34vh; width: auto; max-width: 100%; margin: 0 auto; }
}
.result-on { color: var(--ok); font-weight: 800; }
.result-off { color: var(--bad); font-weight: 800; }
