:root, [data-theme="dark"] {
  --bg: #0f172a; --panel: #1e293b; --bg-deep: #0b1220;
  /* Dark mode: tăng độ tương phản — muted slate-300 thay vì slate-400 cho dễ đọc */
  --text: #f1f5f9; --muted: #cbd5e1; --muted-soft: #94a3b8;
  --accent: #38bdf8; --border: #475569;
  --on-accent: #0b1220;
  --act-grad: linear-gradient(90deg,#7f1d1d,#0b1220);
  --shadow: 0 4px 14px rgba(0,0,0,0.5);
  --shadow-panel: -8px 0 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
  --cell-def: #475569;
  --sol-t-bg:#065f46; --sol-t-fg:#d1fae5;
  --sol-k-bg:#7f1d1d; --sol-k-fg:#fecaca;
  --sol-i-bg:#854d0e; --sol-i-fg:#fef3c7;
  --sol-x-bg:#1f2937;
  --act-sep:rgba(255,255,255,0.6);
  --act-chip-bg:#ffffff; --act-chip-fg:#0b1220;
}
[data-theme="light"] {
  --bg: #f8fafc; --panel: #ffffff; --bg-deep: #f1f5f9;
  /* Light mode: muted slate-600 (đậm hơn slate-500) cho contrast cao */
  --text: #0f172a; --muted: #334155; --muted-soft: #64748b;
  --accent: #0284c7; --border: #94a3b8;
  --on-accent: #ffffff;
  --act-grad: linear-gradient(90deg,#fecaca,#e0f2fe);
  --shadow: 0 2px 10px rgba(15,23,42,0.12);
  --shadow-panel: -8px 0 24px rgba(15,23,42,0.15);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.18);
  --cell-def: #cbd5e1;
  --sol-t-bg:#bbf7d0; --sol-t-fg:#064e3b;
  --sol-k-bg:#fecaca; --sol-k-fg:#7f1d1d;
  --sol-i-bg:#fde68a; --sol-i-fg:#78350f;
  --sol-x-bg:#e5e7eb;
  --act-sep:rgba(15,23,42,0.35);
  --act-chip-bg:#0f172a; --act-chip-fg:#ffffff;
}
* { box-sizing: border-box; }
body { margin:0; font-family:"Segoe UI",system-ui,-apple-system,sans-serif;
       background:var(--bg); color:var(--text); min-height:100vh;
       font-size: 14.5px; line-height: 1.5;     /* baseline dễ đọc cho HS/GV */
       -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
       transition:background 0.2s, color 0.2s; }
header { padding:14px 20px; background:var(--panel); border-bottom:1px solid var(--border);
         display:flex; flex-wrap:wrap; gap:12px; align-items:center; justify-content:space-between; }
h1 { margin:0; font-size:20px; letter-spacing:0.3px; }
h1 small { color:var(--muted); font-weight:400; font-size:13px; margin-left:8px; }
.controls { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.controls button, .controls select, .controls input {
  background:var(--bg-deep); color:var(--text); border:1px solid var(--border);
  padding:7px 11px; border-radius:6px; font-size:13px; cursor:pointer;
}
.controls button.active { background:var(--accent); color:var(--on-accent); font-weight:600; }
.controls input[type=text] { min-width:140px; }
main { padding:16px; }
.table-wrap { overflow-x:auto; }
.pt { display:grid; gap:4px; min-width:1110px; }
.cell.grp-label { background:transparent; color:var(--muted);
                  cursor:default; padding:2px 0; font-size:10px;
                  display:flex; flex-direction:column; align-items:center; justify-content:center; }
.cell.grp-label .grp-num { font-weight:600; color:var(--text); font-size:11px; line-height:1; }
.cell.grp-label .grp-rom { color:var(--accent); font-size:10px; font-weight:600; line-height:1.2; margin-top:2px; }
.cell.per-label { background:transparent; color:var(--text); font-weight:600;
                  font-size:13px; cursor:default;
                  display:flex; align-items:center; justify-content:center; }
.cell.ln-ref { background:transparent; color:var(--muted); font-size:10px; font-style:italic;
               cursor:default; display:flex; align-items:center; justify-content:center; }
.cell { border-radius:6px; padding:4px 6px; font-size:11px; line-height:1.15;
        position:relative; cursor:pointer; user-select:none;
        transition: box-shadow 0.15s ease, filter 0.15s ease, opacity 0.2s;
        color:#0b1220; background:var(--cell-def); }
.cell:hover {
  z-index: 5;
  box-shadow: inset 0 0 0 2px var(--accent, #2c5fa6), 0 2px 6px rgba(0,0,0,0.18);
  filter: brightness(1.05);
}
.cell .num { font-size:10px; opacity:0.75; }
.cell .sym { font-size:18px; font-weight:700; display:block; margin-top:2px; }
.cell .name { font-size:9px; display:block; overflow:hidden;
              text-overflow:ellipsis; white-space:nowrap; }
.cell .mass { font-size:9px; opacity:0.7; }
.cell.label { background:transparent; color:var(--muted); cursor:default;
              display:flex; align-items:center; justify-content:center; font-size:10px; }
.cell.label:hover { box-shadow:none; filter:none; cursor:default; }
.cell.dim { opacity:0.35; }
.cell.highlight { outline:3px solid #fde047; outline-offset:-3px; }

/* Category colors — pastel, dùng chung cho cả 2 theme */
.cat-nonmetal  { background:#fde68a; } .cat-noble     { background:#c4b5fd; }
.cat-alkali    { background:#fca5a5; } .cat-alkaline  { background:#fdba74; }
.cat-metalloid { background:#86efac; } .cat-halogen   { background:#fcd34d; }
.cat-postmetal { background:#a5f3fc; } .cat-transition{ background:#f9a8d4; }
.cat-lanthanide{ background:#f0abfc; } .cat-actinide  { background:#fda4af; }
.cat-unknown   { background:#cbd5e1; }

.pt-extras { display:flex; gap:24px; flex-wrap:wrap; margin:16px 0; align-items:flex-start; }
.legend { display:flex; flex-wrap:wrap; gap:10px; flex:1; min-width:280px;
          font-size:12px; color:var(--muted); }
.legend-item { display:flex; align-items:center; gap:6px; }
.legend-swatch { width:14px; height:14px; border-radius:3px; }

/* Box "Ý nghĩa ô" */
.cell-key { background:var(--panel); border:1px solid var(--border);
            border-radius:8px; padding:12px 14px; min-width:280px; }
.ck-title { font-size:11px; color:var(--accent); text-transform:uppercase;
            letter-spacing:0.5px; font-weight:600; margin-bottom:8px; }
.ck-body { display:flex; gap:14px; align-items:flex-start; }
.ck-sample { width:90px; height:84px; border-radius:6px; padding:6px 8px;
             color:#0b1220; flex-shrink:0; }
.ck-sample .num { font-size:11px; opacity:0.75; }
.ck-sample .sym { font-size:24px; font-weight:700; display:block; margin-top:2px; }
.ck-sample .name { font-size:10px; display:block; }
.ck-sample .mass { font-size:10px; opacity:0.7; }
.ck-list { margin:0; padding:0; list-style:none; font-size:12px; line-height:1.7; }
.ck-list li { color:var(--muted); }
.ck-list b { color:var(--text); display:inline-block; min-width:42px; }

/* Quiz panel */
#quiz { background:var(--panel); padding:16px; border-radius:8px; margin-top:16px; }
#quiz-question { font-size:16px; margin-bottom:12px; }
#quiz-options { display:flex; flex-wrap:wrap; gap:8px; }
#quiz-options button { background:var(--bg-deep); color:var(--text); border:1px solid var(--border);
  padding:8px 16px; border-radius:6px; cursor:pointer; font-size:14px; }
#quiz-feedback { margin-top:12px; font-size:13px; min-height:20px; }
.quiz-score-wrap { margin-top:10px; color:var(--muted); font-size:12px; }

/* Detail panel */
.detail { position:fixed; top:0; right:0; width:min(440px, 92vw); height:100vh;
          background:var(--panel); border-left:1px solid var(--border);
          padding:20px; overflow-y:auto; transform:translateX(100%);
          transition:transform 0.25s ease; z-index:50;
          box-shadow:var(--shadow-panel); }
.detail.open { transform:translateX(0); }
.detail .close { position:absolute; top:10px; right:12px; background:transparent;
                 border:none; color:var(--muted); font-size:22px; cursor:pointer; }
.detail .hero { display:flex; gap:12px; align-items:center; margin-bottom:10px; }
.detail .sym-box { width:90px; height:90px; border-radius:10px;
                   display:flex; flex-direction:column; align-items:center; justify-content:center;
                   color:#0b1220; flex-shrink:0; }
.detail .sym-box .z { font-size:12px; opacity:0.8; }
.detail .sym-box .sy { font-size:40px; font-weight:700; line-height:1; }
.detail h2 { margin:0; font-size:22px; }
.detail .cat-tag { color:var(--muted); font-size:12px; }
.detail dl { display:grid; grid-template-columns:auto 1fr; gap:5px 12px;
             font-size:13px; margin:14px 0; }
.detail dt { color:var(--muted); }
.detail .section { margin-top:14px; padding-top:12px; border-top:1px solid var(--border); }
.detail .section h3 { font-size:12px; color:var(--accent); margin:0 0 6px;
                      text-transform:uppercase; letter-spacing:0.6px; }
.detail .section p { margin:0 0 6px; font-size:13px; line-height:1.5; }
.detail .imgs { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin-top:6px; }
.detail .imgs figure { margin:0; background:var(--bg-deep); border-radius:6px; overflow:hidden; }
.detail .imgs img { width:100%; height:90px; object-fit:cover; display:block; }
.detail .imgs figcaption { font-size:11.5px; color:var(--muted); padding:3px 6px; font-weight:500; }
.detail .ext-link { display:inline-block; margin-top:8px; font-size:13px;
                    color:var(--accent); text-decoration:none; font-weight:600; }
.detail .ext-link:hover { text-decoration:underline; }
.detail .note { font-size:12.5px; color:var(--muted); font-style:italic; }

footer { padding:14px 20px; color:var(--muted); font-size:12.5px; text-align:center;
         border-top:1px solid var(--border); margin-top:24px; font-weight:500; }

/* Tab điều hướng giữa các bảng */
.view-tabs { display:flex; flex-wrap:wrap; gap:4px; margin:0 0 14px; border-bottom:1px solid var(--border); }
.view-tab { background:transparent; color:var(--muted); border:none;
            padding:10px 16px; font-size:13px; cursor:pointer;
            border-bottom:2px solid transparent; margin-bottom:-1px; }
.view-tab:hover { color:var(--text); }
.view-tab.active { color:var(--accent); border-bottom-color:var(--accent); font-weight:600; }

/* Bảng phụ chung */
.aux-panel { padding:8px 0; }
.aux-panel h2 { margin:0 0 4px; font-size:18px; }
.aux-panel h3 { margin:18px 0 8px; font-size:14px; color:var(--accent);
                text-transform:uppercase; letter-spacing:0.5px; }
.aux-legend { font-size:12.5px; color:var(--muted); margin-bottom:12px; font-weight:500; }
.aux-note   { font-size:13px; color:var(--muted); margin-bottom:12px; font-weight:500; }
.table-scroll { overflow-x:auto; }

/* Bảng tính tan */
.sol-table { border-collapse:collapse; font-size:13px; min-width:820px; }
.sol-table th, .sol-table td { border:1px solid var(--border); padding:6px 8px;
                               text-align:center; min-width:42px; }
.sol-table thead th, .sol-table > tr:first-child th { background:var(--bg-deep); color:var(--muted); }
.sol-table .a-head { background:var(--bg-deep); color:var(--text); font-weight:600;
                     text-align:left; min-width:100px; }
.sol-table .a-head .a-name { font-size:11.5px; color:var(--muted); font-weight:500; }
.sol-table .sol-t { background:var(--sol-t-bg); color:var(--sol-t-fg); font-weight:600; }
.sol-table .sol-k { background:var(--sol-k-bg); color:var(--sol-k-fg); font-weight:600; }
.sol-table .sol-i { background:var(--sol-i-bg); color:var(--sol-i-fg); font-weight:600; }
.sol-table .sol-x { background:var(--sol-x-bg); color:var(--muted); }

/* Dãy hoạt động kim loại */
.act-line { display:flex; flex-wrap:wrap; align-items:center; gap:4px;
            padding:18px; background:var(--act-grad);
            border-radius:10px; margin:10px 0 8px; }
.act-chip { display:inline-flex; align-items:center; justify-content:center;
            min-width:44px; height:44px; padding:0 10px;
            background:var(--act-chip-bg); color:var(--act-chip-fg);
            border-radius:6px; font-weight:700; font-size:15px; cursor:pointer;
            transition: box-shadow 0.15s, filter 0.15s; }
.act-chip:hover { box-shadow: inset 0 0 0 2px var(--accent, #2c5fa6); filter: brightness(1.1); }
.act-chip.act-h { background:#facc15; color:#0b1220; }
/* Chip kim loại: cat-X paint background (đồng bộ palette PT). text dark cho contrast. */
.act-chip.cat-alkali     { background:#fca5a5; color:#0b1220; }
.act-chip.cat-alkaline   { background:#fdba74; color:#0b1220; }
.act-chip.cat-transition { background:#f9a8d4; color:#0b1220; }
.act-chip.cat-postmetal  { background:#a5f3fc; color:#0b1220; }
.act-chip.cat-metalloid  { background:#86efac; color:#0b1220; }
.act-chip.cat-nonmetal   { background:#fde68a; color:#0b1220; }
.act-chip.cat-halogen    { background:#fcd34d; color:#0b1220; }
.act-chip.cat-noble      { background:#c4b5fd; color:#0b1220; }
.act-chip.cat-lanthanide { background:#f0abfc; color:#0b1220; }
.act-chip.cat-actinide   { background:#fda4af; color:#0b1220; }
.act-sep { color:var(--act-sep); font-size:18px; font-weight:700; }
.act-rules { margin:0; padding-left:20px; font-size:13px; line-height:1.7; }
.act-rules li { margin:4px 0; }

/* Bảng độ âm điện */
.en-grid { display:grid; grid-template-columns:repeat(18, minmax(50px, 1fr));
           grid-auto-rows:52px; gap:3px; min-width:960px; }
.en-cell { border-radius:4px; padding:4px; color:#0b1220; cursor:pointer;
           display:flex; flex-direction:column; align-items:center; justify-content:center;
           transition: box-shadow 0.15s, filter 0.15s; position: relative; }
.en-cell:hover { z-index:5; box-shadow: inset 0 0 0 2px var(--accent, #2c5fa6); filter: brightness(1.05); }
.en-cell .en-sym { font-size:13px; font-weight:700; line-height:1; }
.en-cell .en-val { font-size:11px; margin-top:2px; font-weight:600; }
/* EN heatmap: gradient nâu→cam→xanh lá (KHÔNG đụng category palette
   để không gây hiểu lầm với cat-alkali/nonmetal/postmetal) */
.en-cell.en-high { background:#dc2626; color:#fff1f2; }  /* đỏ rượu vang ≠ #fca5a5 (cat-alkali) */
.en-cell.en-mid  { background:#f59e0b; color:#451a03; }  /* cam đậm ≠ #fde68a (cat-nonmetal) */
.en-cell.en-low  { background:#2563eb; color:#dbeafe; }  /* xanh dương đậm ≠ #a5f3fc (cat-postmetal) */
.en-cell.en-none { background:var(--cell-def); color:var(--muted); }
[data-theme="light"] .en-cell.en-high { background:#fecaca; color:#7f1d1d; }
[data-theme="light"] .en-cell.en-mid  { background:#fed7aa; color:#7c2d12; }
[data-theme="light"] .en-cell.en-low  { background:#bfdbfe; color:#1e3a8a; }
.en-sw { display:inline-block; width:14px; height:14px; border-radius:3px; vertical-align:middle; margin-right:4px; }

/* Bảng năng lượng liên kết */
.bond-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));
             gap:14px; margin-top:8px; }
.bond-card { background:var(--bg-deep); border:1px solid var(--border);
             border-radius:8px; padding:12px 14px; }
.bond-card h3 { margin:0 0 8px; font-size:12px; color:var(--accent);
                text-transform:uppercase; letter-spacing:0.5px; }
.bond-table { width:100%; border-collapse:collapse; font-size:13px; }
.bond-table th { color:var(--muted); font-weight:600; text-align:left;
                 padding:4px 6px; border-bottom:1px solid var(--border); font-size:12px; text-transform:uppercase; letter-spacing:0.3px; }
.bond-table td { padding:4px 6px; border-bottom:1px solid var(--border); }
.bond-table .bond-eq { font-family:"Cambria Math","Times New Roman",serif; font-weight:600; }
.bond-table .bond-val { text-align:right; color:var(--accent); }

/* Bảng nhiệt tạo thành */
.hf-table { border-collapse:collapse; font-size:13px; min-width:520px; }
.hf-table th, .hf-table td { padding:6px 12px; border-bottom:1px solid var(--border); text-align:left; }
.hf-table th { background:var(--bg-deep); color:var(--muted); font-weight:700; font-size:12px;
               text-transform:uppercase; letter-spacing:0.4px; }
.hf-table .hf-sub { font-family:"Cambria Math","Times New Roman",serif; font-weight:600; }
.hf-table td:last-child { text-align:right; font-variant-numeric:tabular-nums; min-width:110px; }
.hf-table .hf-neg { color:#86efac; font-weight:600; }
.hf-table .hf-pos { color:#fca5a5; font-weight:600; }

/* Bảng oxide / hydroxide chu kỳ 2,3 */
.ox-table { border-collapse:collapse; font-size:13px; margin-bottom:14px; min-width:520px; width:100%; max-width:760px; }
.ox-table th, .ox-table td { padding:8px 12px; border:1px solid var(--border); text-align:left; }
.ox-table th { background:var(--bg-deep); color:var(--muted); font-weight:700; font-size:12px;
               text-transform:uppercase; letter-spacing:0.4px; }
.ox-table .ox-el { font-weight:700; font-size:15px; cursor:pointer; color:var(--accent);
                   width:60px; text-align:center; }
.ox-table .ox-el:hover { text-decoration:underline; }
.ox-table .ox-formula { font-family:"Cambria Math","Times New Roman",serif; font-weight:600; }
.ox-table .ox-acid { color:#fca5a5; font-weight:600; }
.ox-table .ox-base { color:#86efac; font-weight:600; }
.ox-table .ox-amph { color:#fde68a; font-weight:600; }
[data-theme="light"] .ox-table .ox-acid { color:#b91c1c; }
[data-theme="light"] .ox-table .ox-base { color:#15803d; }
[data-theme="light"] .ox-table .ox-amph { color:#a16207; }
[data-theme="light"] .hf-table .hf-neg { color:#15803d; }
[data-theme="light"] .hf-table .hf-pos { color:#b91c1c; }

/* Sách liên quan (mô phạm) */
.related-books { max-width:1080px; margin:40px auto 0;
                 padding:18px 24px; background:var(--panel);
                 border-top:1px solid var(--border); border-bottom:1px solid var(--border); }
.related-books h2 { margin:0 0 4px; font-size:14px; color:var(--text);
                    letter-spacing:0.5px; text-transform:uppercase; }
.related-books .rb-sub { margin:0 0 10px; font-size:13px; color:var(--muted); font-weight:500; }
.related-books .rb-sub a { color:var(--accent); text-decoration:none; }
.related-books .rb-hero { display:flex; gap:16px; align-items:center;
                          padding:12px; background:var(--bg-deep); border:1px solid var(--border);
                          border-radius:8px; text-decoration:none; color:var(--text);
                          transition:border-color 0.15s, transform 0.1s; margin-top:10px; }
.related-books .rb-hero:hover { border-color:var(--accent); transform:translateY(-1px); }
.related-books .rb-hero img { width:320px; max-width:45%; height:auto;
                              border-radius:4px; flex-shrink:0; background:var(--panel);
                              object-fit:contain; }
.related-books .rb-hero-info { display:flex; flex-direction:column; gap:6px; flex:1; }
.related-books .rb-title { font-size:15px; font-weight:600; color:var(--text); }
.related-books .rb-meta  { color:var(--muted); font-size:13px; font-weight:500; }
.related-books .rb-note  { color:var(--text); font-size:13.5px; line-height:1.5; }
.related-books .rb-note em { color:#d97706; font-style:normal; font-weight:500; }
[data-theme="dark"] .related-books .rb-note em { color:#fde047; }
.related-books .rb-side { margin-top:10px; font-size:13px; color:var(--muted); font-weight:500;
                          display:flex; justify-content:space-between; gap:12px;
                          flex-wrap:wrap; }
.related-books .rb-side strong { color:var(--text); font-weight:600; }
.related-books .rb-side a { color:var(--accent); text-decoration:none; }
.related-books .rb-side a:hover { text-decoration:underline; }
@media (max-width:720px) {
  .related-books .rb-hero { flex-direction:column; align-items:stretch; }
  .related-books .rb-hero img { width:100%; max-width:100%; }
}

/* Chatbot */
.chatbot { position:fixed; bottom:16px; right:16px; width:min(380px, 92vw); height:min(540px, 80vh);
           background:var(--panel); border:1px solid var(--border); border-radius:12px;
           display:none; flex-direction:column; z-index:60;
           box-shadow:var(--shadow-lg); overflow:hidden; }
.chatbot.open { display:flex; }
.chat-header { display:flex; justify-content:space-between; align-items:center;
               padding:10px 14px; background:var(--bg-deep); border-bottom:1px solid var(--border);
               font-weight:600; }
.chat-header button { background:transparent; border:none; color:var(--muted);
                      font-size:20px; cursor:pointer; }
#chat-messages { flex:1; overflow-y:auto; padding:12px; display:flex;
                 flex-direction:column; gap:8px; }
.chat-msg { padding:8px 12px; border-radius:10px; font-size:13px; line-height:1.5;
            white-space:pre-wrap; max-width:90%; }
.chat-user { background:var(--accent); color:var(--on-accent); align-self:flex-end; }
.chat-bot  { background:var(--bg-deep); color:var(--text); align-self:flex-start;
             border:1px solid var(--border); }
#chat-suggestions { padding:8px 12px; border-top:1px solid var(--border);
                    display:flex; flex-wrap:wrap; gap:6px; font-size:11px; }
#chat-suggestions .sug-label { color:var(--muted); width:100%; margin-bottom:4px; }
#chat-suggestions .sug { background:transparent; border:1px solid var(--border);
                         color:var(--accent); padding:4px 8px; border-radius:12px;
                         font-size:11px; cursor:pointer; }
#chat-suggestions .sug:hover { background:var(--accent); color:var(--on-accent); }
.chat-input-wrap { display:flex; gap:6px; padding:10px; border-top:1px solid var(--border); }
.chat-input-wrap input { flex:1; background:var(--bg-deep); color:var(--text);
                         border:1px solid var(--border); padding:8px 10px;
                         border-radius:6px; font-size:13px; }
.chat-input-wrap button { background:var(--accent); color:var(--on-accent); border:none;
                          padding:8px 12px; border-radius:6px; font-size:12px;
                          font-weight:600; cursor:pointer; }
.chat-input-wrap button:last-child { background:transparent; color:var(--muted);
                                     border:1px solid var(--border); font-weight:400; }

@media (max-width: 720px) {
  .cell .name, .cell .mass { display:none; }
  .cell .sym { font-size:14px; }
  .pt { grid-auto-rows:48px; }
  .chatbot { width:100vw; height:70vh; right:0; bottom:0; border-radius:12px 12px 0 0; }
}

/* ============================================================
   6 CÔNG CỤ TƯƠNG TÁC
   ============================================================ */
.tools-panel { padding: 6px 4px 12px; }
.tool-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  border-bottom: 2px solid var(--accent, #2c5fa6);
  margin-bottom: 14px; padding-bottom: 0;
}
.tool-tab {
  background: transparent; border: 1px solid transparent; cursor: pointer;
  padding: 8px 14px; font-size: 14px; font-weight: 600; color: var(--text, #222);
  border-radius: 6px 6px 0 0;
}
.tool-tab:hover { background: rgba(44,95,166,.08); }
.tool-tab.active {
  background: var(--accent, #2c5fa6); color: #fff;
  border-color: var(--accent, #2c5fa6);
}
.tool-body { min-height: 360px; }
.tool-card {
  background: var(--card-bg, #fff); padding: 18px 20px; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  max-width: 900px;
}
.tool-card h3 { margin: 0 0 8px; color: var(--accent, #2c5fa6); font-size: 18px; }
.tool-note { font-size: 13px; color: #555; margin: 4px 0 14px; line-height: 1.5; }
.tool-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; align-items: center; }
.tool-row label { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.tool-row select, .tool-row input[type="text"] {
  padding: 6px 10px; border: 1px solid #bbb; border-radius: 5px; font-size: 14px;
}
.tool-btn {
  padding: 8px 18px; background: var(--accent, #2c5fa6); color: #fff; border: none;
  border-radius: 5px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.tool-btn:hover { filter: brightness(1.1); }
.tool-result { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #ccc; }
.loading { padding: 20px; color: #888; text-align: center; }

/* Tool 1 — Formula */
.formula-big {
  font-size: 36px; font-weight: 800; text-align: center;
  color: #0a2272; padding: 18px; background: #f0f4fa; border-radius: 8px;
  font-family: "Cambria Math", Cambria, serif;
}
.formula-explain { padding: 12px 4px; font-size: 14px; line-height: 1.7; color: #333; }
.formula-explain b { color: #c0392b; }

/* Tool 2 — Mix */
.mix-output {
  padding: 18px; border-radius: 10px; text-align: center;
  border: 1px solid rgba(0,0,0,.1);
}
.mix-icon { font-size: 40px; margin-bottom: 6px; }
.mix-formula { font-size: 22px; font-weight: 700; font-family: "Cambria Math", Cambria, serif; margin-bottom: 6px; }
.mix-state { font-size: 16px; margin-bottom: 8px; }
.mix-note { font-size: 13px; color: #444; font-style: italic; }

/* Tool 3 — React */
.react-output { padding: 16px; background: #f7fafc; border-left: 4px solid var(--accent, #2c5fa6); border-radius: 0 6px 6px 0; }
.react-icon { font-size: 30px; }
.react-text { font-size: 15px; line-height: 1.6; margin: 6px 0; }
.react-eq { font-family: "Cambria Math", Cambria, serif; font-size: 16px; color: #0a2272; padding: 8px 12px; background: #fff; border-radius: 5px; }

/* Tool 4 — Trend */
.trend-legend { margin-top: 8px; font-size: 12px; }
.trend-legend span { margin-right: 10px; }

/* Tool 5 — Search */
.search-results { display: flex; flex-direction: column; gap: 10px; }
.search-item {
  padding: 12px; background: #f9fafb; border-left: 3px solid var(--accent, #2c5fa6);
  border-radius: 0 6px 6px 0;
}
.search-rank { float: right; font-size: 12px; color: #888; }
.search-id { font-weight: 700; color: #0a2272; font-size: 14px; }
.search-type { color: #888; font-weight: 400; font-size: 12px; }
.search-text { margin-top: 4px; font-size: 13px; color: #333; line-height: 1.5; }
.search-empty { padding: 16px; color: #888; font-style: italic; text-align: center; }

/* Tool 7 — YCCĐ (yêu cầu cần đạt) */
.yccd-overview > .tool-note { margin: 0 0 10px; }
.yccd-mach { margin-bottom: 8px; border: 1px solid #e3e8f0; border-radius: 6px; background: #fff; }
.yccd-mach > summary {
  cursor: pointer; padding: 9px 12px; font-size: 14px; color: #0a2272;
  list-style: none; user-select: none;
}
.yccd-mach > summary::-webkit-details-marker { display: none; }
.yccd-mach > summary::before { content: "▸ "; color: var(--accent, #2c5fa6); }
.yccd-mach[open] > summary::before { content: "▾ "; }
.yccd-mach > summary:hover { background: #f4f7fb; }
.yccd-mach .search-results { padding: 4px 12px 12px; }

/* Tool 6 — Voice */
.voice-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px; margin-top: 10px;
}
.voice-card {
  display: grid; grid-template-columns: 28px 28px 1fr 36px;
  align-items: center; gap: 6px;
  padding: 8px 10px; background: #fff; border: 1px solid #e3e8ee; border-radius: 6px;
  border-left: 5px solid #cbd5e1;  /* sẽ override bởi cat-X */
  transition: all .15s; cursor: default;
}
/* Border trái theo category — đồng bộ palette PT */
.voice-card.cat-alkali     { border-left-color:#fca5a5; }
.voice-card.cat-alkaline   { border-left-color:#fdba74; }
.voice-card.cat-transition { border-left-color:#f9a8d4; }
.voice-card.cat-postmetal  { border-left-color:#a5f3fc; }
.voice-card.cat-metalloid  { border-left-color:#86efac; }
.voice-card.cat-nonmetal   { border-left-color:#fde68a; }
.voice-card.cat-halogen    { border-left-color:#fcd34d; }
.voice-card.cat-noble      { border-left-color:#c4b5fd; }
.voice-card.cat-lanthanide { border-left-color:#f0abfc; }
.voice-card.cat-actinide   { border-left-color:#fda4af; }
.voice-card.cat-unknown    { border-left-color:#cbd5e1; }
.voice-card:hover { border-color: var(--accent, #2c5fa6); }
.voice-card.speaking { background: #fff3cd; border-color: #f0b400; }
.voice-z { font-size: 12px; color: #475569; font-weight:600; }
.voice-sym { font-weight: 800; color: #0a2272; }
.voice-name { font-size: 14px; cursor: pointer; font-weight: 500; }
.voice-name:hover { text-decoration: underline; }
.voice-ipa { grid-column: 1 / 4; font-size: 12px; color: #334155; font-style: italic; font-weight:500; }
.voice-play {
  background: var(--accent, #2c5fa6); color: #fff; border: none; border-radius: 4px;
  width: 30px; height: 28px; cursor: pointer; font-size: 14px; grid-row: 1 / 3;
}
.voice-play:hover { filter: brightness(1.15); }

@media (max-width: 720px) {
  .tool-card { padding: 12px; }
  .formula-big { font-size: 28px; }
  .tool-tab { padding: 6px 10px; font-size: 12px; }
}

/* ============================================================
   POLISH LAYOUT — gọn, fit viewport, tiện theo dõi cho GV/HS THPT
   ============================================================ */

/* Sticky header + tabs — luôn nhìn thấy điều hướng */
header {
  position: sticky; top: 0; z-index: 30;
  padding: 8px 16px;
  backdrop-filter: blur(6px);
}
header h1 { font-size: 17px; line-height: 1.2; }
header h1 small { font-size: 11px; margin-left: 6px; }

.controls { gap: 6px; }
.controls button, .controls select, .controls input {
  padding: 5px 9px; font-size: 12.5px; border-radius: 5px;
}
.controls input[type=text] { min-width: 120px; }

/* Tabs cũng sticky, ngay dưới header */
#view-tabs {
  position: sticky; top: 50px; z-index: 25;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px 0; margin: -16px -16px 12px;
  display: flex; flex-wrap: wrap; gap: 2px;
}
.view-tab {
  background: transparent; border: none; cursor: pointer;
  padding: 8px 14px; font-size: 13px; color: var(--muted);
  border-radius: 6px 6px 0 0; font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.view-tab:hover { color: var(--text); background: rgba(127,127,127,0.06); }
.view-tab.active {
  color: var(--accent); border-bottom-color: var(--accent);
  font-weight: 600; background: transparent;
}

/* Main: bớt padding, cho PT chiếm tối đa viewport */
main { padding: 12px 16px 20px; }

/* PT grid: cells nhỏ lại để fit 1280px viewport, vẫn responsive */
.pt {
  gap: 3px;
  min-width: auto;       /* bỏ min-width 1110px gây scroll ngang */
  grid-template-columns: 26px repeat(18, minmax(46px, 1fr)) !important;
  /* row height đủ cho 4 element stack: num+sym+name (tối đa 2 dòng) + mass.
     Tên VI dạng "Hydrogen (Hiđro)" wrap 2 dòng → cần ~62-66px. */
  grid-template-rows: 32px repeat(9, minmax(62px, 66px)) !important;
}
.cell {
  padding: 3px 4px;
  font-size: 10.5px;
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;          /* clip nếu vẫn dư — không tràn xuống ô dưới */
}
.cell .num { font-size: 9.5px; line-height: 1.1; }
.cell .sym { font-size: 16px; margin-top: 1px; line-height: 1.1; }
.cell .name { font-size: 8.5px; line-height: 1.05; }
.cell .mass { font-size: 8.5px; line-height: 1.1; margin-top: auto; }  /* dính đáy ô */
.cell.grp-label .grp-num { font-size: 10px; }
.cell.grp-label .grp-rom { font-size: 9.5px; }
.cell.per-label { font-size: 12px; }

/* pt-extras: ngang gọn, ít chiếm chiều cao */
.pt-extras {
  margin: 8px 0 0;
  gap: 12px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.legend {
  font-size: 11px; gap: 8px 14px;
  min-width: 240px;
}
.legend-swatch { width: 12px; height: 12px; }
.cell-key {
  padding: 8px 10px;
  border: none;
  background: transparent;
  min-width: 220px;
}
.cell-key .ck-title { font-size: 10px; margin-bottom: 4px; }

/* aux panels: tăng max-width, padding khoa học */
.aux-panel { padding: 14px 18px; }
.aux-panel h2 { font-size: 16px; margin: 0 0 10px; }

/* Tools view: tabs nhỏ + body chiếm chiều cao tự nhiên */
.tool-tabs { gap: 3px; margin-bottom: 10px; }
.tool-tab { padding: 6px 12px; font-size: 13px; }

/* Detail panel: trượt từ phải, tự rộng theo nội dung nhưng giới hạn */
.detail { width: min(380px, 88vw); padding: 16px 18px; }
.detail h3 { font-size: 18px; }

/* Footer: gọn, chữ nhỏ */
footer { font-size: 12.5px; padding: 10px 16px; color: var(--muted); text-align: center; font-weight: 500; }
.related-books { padding: 12px 16px 20px; }
.related-books h2 { font-size: 15px; }

/* (Đã bỏ badge "Mới" trên tab Công cụ theo yêu cầu) */
.view-tab[data-view="tools"]::after { content: none; }

/* Responsive: 3 breakpoint cho từng cỡ màn hình */
@media (max-width: 1280px) {
  .pt { grid-template-columns: 24px repeat(18, minmax(42px, 1fr)) !important; }
  .cell .sym { font-size: 15px; }
  header h1 { font-size: 16px; }
  header h1 small { display: none; }   /* ẩn subtitle khi hẹp */
}

@media (max-width: 980px) {
  .pt {
    grid-template-columns: 22px repeat(18, minmax(38px, 1fr)) !important;
    grid-template-rows: 28px repeat(9, minmax(48px, 50px)) !important;
  }
  .cell .sym { font-size: 13.5px; }
  .cell .name { display: none; }       /* trên tablet ẩn tên, chỉ giữ Z + sym + mass */
  #view-tabs { top: 46px; padding: 4px 12px 0; }
  main { padding: 10px 12px 16px; }
  .pt-extras { flex-direction: column; gap: 6px; }
}

@media (max-width: 720px) {
  /* Mobile: cuộn ngang PT là chấp nhận được */
  .table-wrap { overflow-x: auto; }
  .pt { min-width: 720px !important; }
  header { padding: 6px 10px; }
  .view-tab { padding: 5px 8px; font-size: 12.5px; }
}

/* Theme dark: nền panel nhẹ hơn cho dễ đọc, accent rõ hơn */
[data-theme="dark"] header {
  background: rgba(30, 41, 59, 0.85);
}
[data-theme="dark"] #view-tabs {
  background: rgba(15, 23, 42, 0.95);
}
[data-theme="light"] header {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
[data-theme="light"] #view-tabs {
  background: rgba(248, 250, 252, 0.95);
}

/* Tooltip first-visit nhỏ cho GV (tự ẩn sau 8s) */
.first-tip {
  position: fixed; bottom: 16px; left: 16px; z-index: 40;
  background: var(--accent); color: var(--on-accent);
  padding: 10px 14px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-lg); max-width: 320px;
  animation: slideUp 0.4s ease-out, fadeOut 1s ease-out 8s forwards;
}
.first-tip b { font-weight: 700; }
.first-tip .close-tip {
  background: transparent; border: none; color: inherit;
  font-size: 18px; cursor: pointer; margin-left: 8px; padding: 0;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateY(20px); pointer-events: none; }
}

/* Tool 1 — A + B trên cùng 1 hàng (2 cột), wrap về 2 hàng trên màn hẹp */
.tool-row.t1-inputs {
  display: flex; flex-wrap: wrap; gap: 18px;
  align-items: flex-start;
}
.t1-group {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
  flex: 1 1 380px;
  min-width: 0;
}
.t1-group label { flex: 1 1 auto; }
.t1-group select { max-width: 100%; }
.t1-valence { flex: 0 0 auto !important; }
.t1-valence select { min-width: 60px; }

@media (max-width: 720px) {
  .tool-row.t1-inputs { gap: 10px; }
  .t1-group { flex-basis: 100%; }
}

/* Header thật gọn — 1 hàng trên màn rộng */
header {
  padding: 5px 14px !important;
  align-items: center;
  flex-wrap: nowrap;          /* không xuống dòng trên màn rộng */
  gap: 14px;
}
header h1 {
  font-size: 15px !important;
  font-weight: 700;
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
header h1 small { font-size: 11.5px !important; opacity: 0.85; font-weight: 500; }
.controls {
  flex: 1 1 auto;
  justify-content: flex-end;
  gap: 4px;
}
.controls button, .controls select, .controls input {
  padding: 4px 8px !important;
  font-size: 12px !important;
  height: 28px;
}
.controls input[type=text] { min-width: 110px; }

/* Tabs sticky theo header mới — top khớp chiều cao header thực */
#view-tabs { top: 38px !important; padding: 4px 14px 0 !important; }
.view-tab { padding: 6px 12px !important; font-size: 13.5px !important; font-weight: 500; }

@media (max-width: 1100px) {
  /* Khi quá hẹp — cho phép xuống 2 hàng */
  header { flex-wrap: wrap !important; padding: 4px 12px !important; gap: 6px; }
  header h1 { flex: 1 1 100%; }
  .controls { justify-content: flex-start; flex: 1 1 100%; }
  #view-tabs { top: 70px !important; }
}
@media (max-width: 720px) {
  header h1 { font-size: 13.5px !important; }
  header h1 small { display: none; }
  #view-tabs { top: 64px !important; }
}

/* ============================================================
   FINAL POLISH — accessibility, animations, print, micro-UX
   ============================================================ */

/* 1. Focus visible — vành xanh khi điều hướng bằng phím Tab */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, select:focus-visible, input:focus-visible {
  outline-offset: 1px;
}
.cell:focus-visible {
  z-index: 6;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 3px rgba(56, 189, 248, 0.4);
  outline: none;
}

/* 2. Loading spinner — thay text "Đang tải…" */
.loading {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 30px; color: var(--muted);
  font-size: 13px; font-style: italic;
}
.loading::before {
  content: "";
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 3. Smooth content fade khi đổi tab/view */
#view-pt, #view-aux, .tool-body {
  animation: fadeIn 0.25s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 4. Tool result micro-animation — kết quả "đẩy lên" khi cập nhật */
.tool-result, .mix-output, .react-output, .formula-big {
  animation: resultPop 0.3s ease-out;
}
@keyframes resultPop {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* 5. Form elements — thống nhất focus ring + transition */
input[type="text"], select, .tool-row select, .tool-row input {
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
  outline: none;
}

/* 6. Tool buttons — hover lift, active press */
.tool-btn {
  transition: transform 0.1s, box-shadow 0.15s, filter 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.tool-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.15); }
.tool-btn:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* 7. Sub-tabs (.tool-tab) chuyển động mượt */
.tool-tab { transition: background 0.15s, color 0.15s, border-color 0.15s; }

/* 8. Empty state cho search/tools */
.search-empty, .tool-empty {
  padding: 30px 20px; text-align: center;
  color: var(--muted); font-style: italic;
  background: var(--bg-deep); border-radius: 8px;
  border: 1px dashed var(--border);
}
.search-empty::before { content: "🔍 "; font-style: normal; font-size: 22px; display:block; margin-bottom:6px; }

/* 9. Detail panel — close button polished + backdrop subtle */
.detail .close, #chat-close {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.detail .close:hover, #chat-close:hover {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
}

/* 10. Scrollbar mảnh cho panel/aside */
.detail::-webkit-scrollbar, .chatbot::-webkit-scrollbar, main::-webkit-scrollbar { width: 6px; height: 6px; }
.detail::-webkit-scrollbar-thumb, .chatbot::-webkit-scrollbar-thumb, main::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 3px;
}
.detail::-webkit-scrollbar-thumb:hover, .chatbot::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* 11. Selection color match accent */
::selection { background: var(--accent); color: var(--on-accent); }

/* 12. View tab transition + indicator subtle pulse cho tab Mới */
.view-tab[data-view="tools"]::after {
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.7; transform: scale(0.95); }
}

/* 13. PRINT STYLESHEET — bản in sạch */
@media print {
  header, #view-tabs, .controls, .related-books, footer,
  .chatbot, #chat-toggle, #quiz-btn, #theme-toggle,
  .detail .close, .first-tip { display: none !important; }
  body { background: white; color: black; }
  main { padding: 0; }
  .pt { gap: 1px; min-width: auto !important; }
  .cell { background: white !important; border: 0.5pt solid #888; }
  .cell .sym { color: black; }
  /* Mỗi view-aux ra trang riêng */
  #view-aux { page-break-before: always; }
  a { color: black; text-decoration: none; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #555; }
}

/* 14. Reduced motion — tôn trọng người không thích animation */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* 15. Card hover micro-interaction cho voice + search items */
.voice-card, .search-item {
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.search-item:hover {
  border-left-width: 5px; padding-left: 11px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* 16. Disable user-select trên các nút điều hướng */
button, .view-tab, .tool-tab { user-select: none; }

/* 17. Selectbox xinh hơn — chevron tùy theme */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4l3 4 3-4z' fill='%23888'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px !important;
}

/* 18. Body có ngữ cảnh hover trên cells của PT — cursor pointer rõ ràng */
.cell:not(.label):not(.grp-label):not(.per-label):not(.ln-ref) { cursor: pointer; }

/* ============================================================
   POLISH UX (phản hồi GV) — dock detail, hover tooltip, highlight
   ============================================================ */

/* Highlight cells khi search — mạnh hơn (rõ ràng) */
.cell.highlight {
  outline: 3px solid #fde047 !important;
  outline-offset: -3px;
  box-shadow: 0 0 0 4px rgba(253, 224, 71, 0.35), 0 4px 14px rgba(253, 224, 71, 0.5) !important;
  z-index: 6;
  animation: hl-pulse 1.2s ease-in-out infinite;
}
@keyframes hl-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(253, 224, 71, 0.35), 0 4px 14px rgba(253, 224, 71, 0.5); }
  50%      { box-shadow: 0 0 0 7px rgba(253, 224, 71, 0.15), 0 6px 18px rgba(253, 224, 71, 0.7); }
}

/* Cell tooltip — hiển thị info ngắn theo chuột */
.cell-tip {
  position: fixed;
  pointer-events: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden;
  transition: opacity 0.1s;
  z-index: 100;
  max-width: 280px;
  min-width: 160px;
}
.cell-tip.show { opacity: 1; visibility: visible; }
.cell-tip .ct-row { margin: 0; }
.cell-tip .ct-row b { color: var(--accent); font-size: 14px; margin-right: 4px; }
.cell-tip .ct-name { font-weight: 600; margin: 2px 0; color: var(--text); }
.cell-tip .ct-meta { color: var(--muted); font-size: 12px; font-weight: 500; }

/* Dock button — trong detail panel */
.dock-btn {
  position: absolute;
  top: 12px; right: 50px;        /* sát bên trái nút × */
  width: 30px; height: 30px;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--border); border-radius: 50%;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.dock-btn:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Khi đã DOCK: detail panel inline cạnh PT, không trượt */
body.docked .detail {
  position: fixed;
  top: 90px;                     /* dưới header + tabs */
  right: 12px;
  bottom: 12px;
  transform: none !important;
  width: 340px;
  max-width: 35vw;
  box-shadow: var(--shadow-lg);
  border-radius: 12px;
}
body.docked main {
  padding-right: 360px;          /* chừa chỗ cho panel dock bên phải */
}
body.docked .pt { min-width: auto !important; }

@media (max-width: 980px) {
  body.docked .detail {
    position: fixed; left: 0; right: 0; bottom: 0;
    top: auto; width: 100%; max-width: 100%; height: 45vh;
    border-radius: 16px 16px 0 0;
  }
  body.docked main { padding-right: 16px; padding-bottom: 46vh; }
}

/* Ẩn các nút PT-only khi đổi sang view khác — JS toggle display, đây là fallback CSS */
body[data-view="sol"] #mode-cap2,
body[data-view="sol"] #mode-cap3,
body[data-view="sol"] #filter,
body[data-view="act"] #mode-cap2,
body[data-view="act"] #mode-cap3,
body[data-view="act"] #filter { display: none; }

/* ============================================================
   QUIZ MODAL — overlay riêng, không trộn với main view
   ============================================================ */
.quiz-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.quiz-modal[hidden] { display: none; }
.quiz-card {
  background: var(--panel); border-radius: 14px;
  border: 1px solid var(--border);
  width: min(520px, 100%); max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  padding: 22px 24px 20px;
  position: relative;
}
.quiz-close {
  position: absolute; top: 12px; right: 14px;
  width: 32px; height: 32px;
  background: transparent; color: var(--muted);
  border: none; border-radius: 50%;
  font-size: 22px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.quiz-close:hover { background: var(--bg-deep); color: var(--text); }
.quiz-head { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.quiz-head h2 { margin: 0 0 4px; font-size: 18px; color: var(--accent); font-weight: 700; }
.quiz-progress { font-size: 13px; color: var(--muted); font-weight: 500; }
.quiz-body #quiz-question {
  font-size: 16px; font-weight: 500; line-height: 1.6;
  margin-bottom: 16px; color: var(--text);
}
.quiz-body #quiz-options {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-bottom: 12px;
}
.quiz-body #quiz-options button {
  padding: 14px 16px;
  font-size: 16px; font-weight: 600;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: all 0.15s;
}
.quiz-body #quiz-options button:hover:not(:disabled) {
  border-color: var(--accent); background: var(--panel); transform: translateY(-1px);
}
.quiz-body #quiz-options button:disabled { cursor: default; opacity: 0.6; }
.quiz-body #quiz-options button.ans-correct {
  background: #10b981; color: #fff; border-color: #10b981; opacity: 1;
}
.quiz-body #quiz-options button.ans-wrong {
  background: #ef4444; color: #fff; border-color: #ef4444; opacity: 1;
}
.quiz-body #quiz-feedback {
  text-align: center; font-size: 14px; font-weight: 600;
  min-height: 22px; padding: 6px 0;
}
.quiz-foot { text-align: center; padding-top: 8px; }
.quiz-foot[hidden] { display: none; }
.quiz-foot #quiz-final {
  font-size: 20px; margin-bottom: 16px; color: var(--text); font-weight: 600;
}
.quiz-foot #quiz-final b { color: var(--accent); font-size: 28px; }
.quiz-foot .quiz-btn {
  padding: 10px 24px; font-size: 14px; font-weight: 600;
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: 8px; cursor: pointer;
}
.quiz-foot .quiz-btn:hover { filter: brightness(1.1); }

@media (max-width: 480px) {
  .quiz-body #quiz-options { grid-template-columns: 1fr; }
  .quiz-card { padding: 18px; }
}

/* Tool 1: ghi chú swap thứ tự */
.formula-note {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.formula-note b { color: var(--text); }
/* Tool 1: hợp chất có thật trong COMPOUND_DB */
.formula-real {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid #22c55e;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 500;
}
.formula-real .formula-link { color: #22c55e; cursor: pointer; text-decoration: underline; }
.formula-real .formula-link:hover { color: #16a34a; }
/* Tool 1: cảnh báo công thức không tồn tại */
.formula-warn-note {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
}
.formula-warn-note b { color: #f59e0b; }

/* ============================================================
   COMPACT aux-panel layout — phản hồi user: bảng phụ vừa khít viewport
   ============================================================ */
main { padding: 4px 12px !important; }
.aux-panel { padding: 4px 12px !important; }
.aux-panel h2 { margin: 0 0 2px !important; font-size: 15px !important; line-height: 1.2; }
.aux-panel > p:first-of-type,
.aux-panel .legend,
.aux-panel .sol-legend,
.aux-panel .panel-note { margin: 0 0 6px !important; font-size: 13px !important; line-height: 1.4; font-weight: 500; }
.aux-panel h3 { margin: 8px 0 4px !important; font-size: 14px !important; }

/* Tables: tăng font cho HS/GV dễ đọc */
.aux-panel table { font-size: 13px !important; border-collapse: collapse; }
.aux-panel table th,
.aux-panel table td {
  padding: 3px 6px !important;
  line-height: 1.25 !important;
}
.aux-panel table th { font-size: 13px !important; font-weight: 700; }

/* Solubility cells: chữ T/K/I/— giữ rõ nhưng padding giảm */
.aux-panel table td.sol-T,
.aux-panel table td.sol-K,
.aux-panel table td.sol-I,
.aux-panel table td.sol-X { padding: 3px 4px !important; font-size: 12px !important; }

/* Title của view-aux không có margin trên */
#view-aux { padding-top: 0 !important; margin-top: 0 !important; }
#view-aux > .aux-panel:first-child { padding-top: 6px !important; }

/* Tabs siết hơn */
.view-tabs { margin: 0 0 6px !important; padding-bottom: 0 !important; }
.view-tab { padding: 5px 10px !important; font-size: 12px !important; }

/* Header ngắn hơn nữa cho view-aux */
body[data-view="sol"] header,
body[data-view="act"] header,
body[data-view="en"] header,
body[data-view="bond"] header,
body[data-view="hf"] header,
body[data-view="ox"] header { padding: 3px 14px !important; }
body[data-view="sol"] header h1,
body[data-view="act"] header h1,
body[data-view="en"] header h1,
body[data-view="bond"] header h1,
body[data-view="hf"] header h1,
body[data-view="ox"] header h1 { font-size: 13px !important; }
body[data-view="sol"] header h1 small,
body[data-view="act"] header h1 small,
body[data-view="en"] header h1 small,
body[data-view="bond"] header h1 small,
body[data-view="hf"] header h1 small,
body[data-view="ox"] header h1 small { display: none; }

/* Enthalpy 2-col layout cho viewport rộng */
.hf-two-col { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 980px) {
  .hf-two-col { grid-template-columns: 1fr 1fr; gap: 16px; }
}

/* Tăng cỡ chữ aux table — user feedback "tăng cỡ chữ lên một chút" */
.aux-panel table { font-size: 13px !important; }
.aux-panel table th { font-size: 12px !important; }
.aux-panel table td { padding: 4px 8px !important; line-height: 1.3 !important; }
.aux-panel h2 { font-size: 17px !important; }
.aux-panel > p:first-of-type,
.aux-panel .legend,
.aux-panel .sol-legend,
.aux-panel .aux-note { font-size: 12px !important; }
.aux-panel h3 { font-size: 14px !important; }
.aux-panel table td.sol-T,
.aux-panel table td.sol-K,
.aux-panel table td.sol-I,
.aux-panel table td.sol-X { padding: 4px 6px !important; font-size: 13px !important; }

/* Tool 3 — box giải thích sư phạm */
.react-teach {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(16, 185, 129, 0.07);
  border-left: 3px solid #10b981;
  border-radius: 4px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}
.react-teach b { color: var(--text); }
.react-teach sup, .react-teach sub { font-size: 0.8em; }

/* Wikipedia enrichment trong detail panel */
.wiki-section { background: rgba(56, 189, 248, 0.04); padding: 8px 10px; border-radius: 6px; }
.wiki-row { display: flex; gap: 10px; align-items: flex-start; }
.wiki-body { flex: 1; min-width: 0; }       /* body chiếm phần còn lại bên phải ảnh */
.wiki-thumb {
  width: 80px; height: 80px;
  object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: block;
}
.wiki-text { margin: 0 0 8px; font-size: 13.5px; line-height: 1.6; color: var(--text); font-weight: 400; }
@media (max-width: 480px) {
  .wiki-row { flex-direction: column; }
  .wiki-thumb { width: 100%; height: 140px; }
}

/* Hero compact — ô symbol nhỏ lại, dành chỗ cho nội dung */
.detail .hero { gap: 10px !important; margin-bottom: 6px !important; align-items: center; }
.detail .sym-box {
  width: 60px !important; height: 60px !important;
  border-radius: 8px !important;
}
.detail .sym-box .z { font-size: 10px !important; }
.detail .sym-box .sy { font-size: 26px !important; }
.detail h2 { font-size: 18px !important; line-height: 1.2; margin: 0; }
.detail .cat-tag { font-size: 11px !important; line-height: 1.3; }

/* dl nhỏ gọn hơn */
.detail dl { gap: 3px 10px !important; font-size: 12px !important; margin: 8px 0 !important; }

/* Wiki paragraphs với line breaks */
.wiki-body { flex: 1; min-width: 0; }
.wiki-body .wiki-text { margin: 0 0 8px !important; font-size: 13.5px !important; line-height: 1.6 !important; color: var(--text) !important; }
.wiki-body .wiki-text:last-child { margin-bottom: 0 !important; }
.wiki-section { padding: 8px 12px !important; }
.wiki-section h3 { margin: 0 0 8px !important; font-size: 13px !important; font-weight: 700 !important; }
.wiki-thumb { width: 70px !important; height: 70px !important; }

/* Bond Energy 3D modal */
.bond-3d-cell { width: 1%; padding: 2px 6px !important; }
.bond-3d-btn {
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: 4px;
  padding: 3px 8px; font-size: 11px; cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s;
}
.bond-3d-btn:hover { filter: brightness(1.1); }
.bond3d-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
}
.bond3d-modal.open { display: flex; animation: fadeIn 0.15s ease; }
.bond3d-card {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px 18px;
  max-width: 92vw;
  width: 520px;
  max-height: 92vh;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.bond3d-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--text);
  padding-right: 30px;
}
.bond3d-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: none;
  font-size: 24px; cursor: pointer;
  color: var(--muted); width: 28px; height: 28px;
  border-radius: 50%;
}
.bond3d-close:hover { background: var(--bg-deep); color: var(--text); }
.bond3d-viewer {
  width: 100%;
  height: 360px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.bond3d-controls {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.bond3d-controls button[data-style] {
  background: var(--bg-deep);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}
.bond3d-controls button[data-style].active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.bond3d-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
}
@media (max-width: 480px) {
  .bond3d-viewer { height: 280px; }
  .bond3d-hint { display: none; }
}

/* Placeholder cho "57-71 Lanthanide" / "89-103 Actinide" giống bản in */
.cell.placeholder {
  background: var(--cell-def);
  color: #0b1220;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  line-height: 1.15;
  padding: 4px 2px;
  cursor: default;
}
.cell.placeholder:hover {
  box-shadow: inset 0 0 0 2px var(--accent);
  filter: brightness(1.05);
}
.cell.placeholder .ph-z {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent, #2c5fa6);
  line-height: 1.1;
}
.cell.placeholder .ph-name {
  font-size: 9px;
  font-weight: 600;
  margin-top: 2px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.2px;
}
/* Hai hàng Ln/An gắn liền với grid chính */
.pt > .cell[style*="grid-row: 9"],
.pt > .cell[style*="grid-row: 10"] {
  margin-top: 2px;
}

/* Compound detail modal — chia sẻ structure với bond3d-modal */
.compound-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center; justify-content: center;
  z-index: 210;
}
.compound-modal.open { display: flex; animation: fadeIn 0.15s ease; }
.compound-card {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px 18px;
  max-width: 92vw;
  width: 580px;
  max-height: 92vh;
  position: relative;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.compound-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: none;
  font-size: 24px; cursor: pointer;
  color: var(--muted); width: 28px; height: 28px;
  border-radius: 50%;
}
.compound-close:hover { background: var(--bg-deep); color: var(--text); }

.cd-header { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; padding-right: 30px; }
.cd-img { width: 80px; height: 80px; object-fit: contain; background: #fff; border-radius: 6px; padding: 4px; border: 1px solid var(--border); flex-shrink: 0; }
.cd-title h2 { margin: 0; font-size: 22px; color: var(--accent); }
.cd-name { font-size: 14px; font-weight: 500; color: var(--text); margin-top: 2px; }
.cd-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-weight: 500; }
.cd-section { margin: 10px 0; padding: 8px 10px; background: var(--bg-deep); border-radius: 6px; }
.cd-section h4 { margin: 0 0 6px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.3px; }
.cd-stat { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.cd-stat .hf-neg { color: #10b981; font-weight: 700; font-size: 14px; }
.cd-stat .hf-pos { color: #ef4444; font-weight: 700; font-size: 14px; }
.cd-tag { background: var(--accent); color: var(--on-accent); padding: 2px 8px; border-radius: 4px; font-size: 11.5px; font-weight: 600; }
.cd-rxn { font-size: 12px; margin: 6px 0; }
.cd-eq { font-family: "Cambria Math", serif; font-size: 13px; color: var(--text); }
.cd-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.5; font-weight: 500; }
.cd-elems { display: flex; flex-wrap: wrap; gap: 6px; }
.cd-el-tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600;
  border: none; cursor: pointer; color: #0b1220;
  transition: transform 0.1s;
}
.cd-el-tag:hover { transform: translateY(-1px); filter: brightness(1.05); }
.cd-link { color: var(--accent); font-size: 12.5px; text-decoration: none; }
.cd-link:hover { text-decoration: underline; }

/* Clickable cells trong bảng phụ */
.aux-panel .clickable {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  transition: filter 0.15s;
}
.aux-panel .clickable:hover { filter: brightness(1.2); }

/* Enthalpy table: cột rộng hợp lý — không stretch quá */
.hf-table { width: auto !important; }
.hf-table th, .hf-table td { white-space: nowrap; }
.hf-table th:nth-child(1), .hf-table td.hf-sub  { width: 1%; padding-right: 12px !important; }
.hf-table th:nth-child(2), .hf-table td:nth-child(2) { width: auto; min-width: 140px; padding-right: 16px !important; }
.hf-table th:nth-child(3), .hf-table td.hf-neg, .hf-table td.hf-pos { width: 1%; text-align: right; padding-left: 12px !important; }
.hf-two-col .table-scroll { overflow-x: visible !important; }

/* Tương tự cho Oxide table */
.ox-table { width: auto !important; }
.ox-table th, .ox-table td { white-space: nowrap; }
.ox-table th:nth-child(1), .ox-table td.ox-el { width: 1%; padding-right: 14px !important; font-weight: 600; }
.ox-table th:nth-child(2), .ox-table th:nth-child(3),
.ox-table td.ox-formula { width: 1%; padding: 4px 14px !important; }
.ox-table th:last-child, .ox-table td:last-child { width: auto; min-width: 140px; }

/* Bond table: cũng siết lại */
.bond-table { width: auto !important; }
.bond-table th, .bond-table td { white-space: nowrap; }
.bond-table td.bond-eq { width: 1%; padding-right: 14px !important; font-weight: 600; }
.bond-table td.bond-val { width: 1%; padding-right: 12px !important; text-align: right; }

/* Wikipedia block trong compound modal */
.cd-wiki-note { font-size: 12px; color: var(--muted); font-style: italic; margin: -4px 0 8px; }
.cd-wiki-row { display: flex; gap: 12px; align-items: flex-start; }
/* Ghi chú nguồn + giấy phép ảnh — text ngắn, không tràn ngang */
.img-credit {
  font-size: 10.5px;
  color: var(--muted);
  font-style: italic;
  line-height: 1.3;
  margin-top: 3px;
  font-weight: 500;
  white-space: normal;       /* wrap nếu dài */
  word-break: break-word;
}
/* Figure wrapping ảnh: KHÔNG stretch ra body — width = max-content = chỉ rộng bằng ảnh */
.cd-img-fig, .cd-wiki-fig, .wiki-thumb-fig {
  margin: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  flex-shrink: 0;
  width: max-content;        /* không kéo dài hơn ảnh */
  max-width: 130px;          /* hard cap cho caption 2-3 dòng dưới ảnh nhỏ */
}
.wiki-thumb-fig { max-width: 100px; }    /* thumb element panel: nhỏ hơn */
.wiki-thumb-fig .img-credit { font-size: 10px; }
.cd-wiki-img {
  width: 100px; height: 100px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); flex-shrink: 0; background: #fff;
}
.cd-wiki-body { flex: 1; min-width: 0; }
.cd-wiki-text { margin: 0 0 6px; font-size: 13px; line-height: 1.6; color: var(--text); }
.cd-wiki-text:last-child { margin-bottom: 0; }
@media (max-width: 540px) {
  .cd-wiki-row { flex-direction: column; }
  .cd-wiki-img { width: 100%; height: 160px; }
}

/* Ảnh trong modal/detail KHÔNG bị crop — dùng object-fit:contain + nền */
.wiki-thumb,
.cd-wiki-img,
.cd-img {
  object-fit: contain !important;
  background: #fff;
  padding: 4px;
}
/* Tăng nhẹ kích thước thumb wiki cho dễ xem */
.cd-wiki-img { width: 120px !important; height: 120px !important; }
.wiki-thumb { width: 90px !important; height: 90px !important; }
.cd-img { width: 100px !important; height: 100px !important; }
@media (max-width: 540px) {
  .cd-wiki-img { width: 100% !important; height: 200px !important; }
  .cd-wiki-row { flex-direction: column; }
}

/* ============================================================
   CO GIÃN — cell name + wiki summary
   ============================================================ */

/* PT cell: tên dài (Lawrencium, Rutherfordium…) hoặc VI "Hydrogen (Hiđro)"
   có thể wrap 2 dòng, font giảm nhẹ để vừa.
   max-height = 2 dòng × line-height 1.05 × 8.5px ≈ 18px (giữ nguyên),
   nhưng row-height đã tăng lên 62-66px nên mass không bị cắt nữa. */
.cell .name {
  white-space: normal !important;
  word-break: break-word;
  hyphens: auto;
  line-height: 1.05;
  font-size: 8.5px !important;
  max-height: 18px;
  overflow: hidden;
}

/* Wiki summary trong element detail panel + compound modal — KHÔNG truncate */
.wiki-text, .wiki-body p, .cd-wiki-text {
  display: block !important;
  -webkit-line-clamp: unset !important;
  overflow: visible !important;
  text-overflow: clip !important;
  max-height: none !important;
  white-space: normal !important;
}

/* Khung chứa wiki: bỏ height cố định, để flex grow theo nội dung */
.wiki-section, .cd-section {
  height: auto !important;
  min-height: 0;
  overflow: visible !important;
}
.wiki-row, .cd-wiki-row {
  align-items: flex-start !important;
}

/* Element detail panel: tăng padding/scroll mượt */
.detail { overflow-y: auto; }
.detail .section { margin-bottom: 12px; }
.detail .section p { line-height: 1.55; }

/* Compound modal card: cho cao tự nhiên theo nội dung */
.compound-card {
  max-height: 92vh;
  overflow-y: auto;
}

/* ============================================================
   POLISH FROM AUDIT — tap targets, touch UX, browser compat
   ============================================================ */

/* Tap targets — Apple HIG 44×44 minimum */
.controls button { min-height: 36px; }
.bond3d-close, .compound-close, .dock-btn, .detail .close, .chat-header button {
  min-width: 36px !important;
  min-height: 36px !important;
}
@media (pointer: coarse) {
  .bond3d-close, .compound-close, .dock-btn, .detail .close { min-width: 44px !important; min-height: 44px !important; }
  .controls button, .controls select { min-height: 40px; }
  .view-tab { min-height: 40px; padding: 8px 12px !important; }
  .tool-tab { min-height: 40px; }
  .act-chip { min-width: 44px !important; min-height: 44px !important; }
}

/* Tooltip hover chỉ trên thiết bị có hover; tap trên touch sẽ click vào cell */
@media (hover: none) {
  .cell-tip { display: none !important; }
}

/* backdrop-filter Safari 15.0/15.1 prefix */
*[style*="backdrop-filter"], header, .compound-card, .bond3d-card {
  -webkit-backdrop-filter: inherit;
}

/* 3D viewer: ngăn page scroll khi drag/pinch */
.bond3d-viewer, .compound-modal canvas {
  touch-action: none;
}

/* Header lang select — cap width để không tràn header trên 1366 */
#lang { max-width: 160px; }
@media (max-width: 1280px) { #lang { max-width: 130px; font-size: 12px; } }

/* Print: A3 landscape + tránh tách bảng giữa dòng */
@media print {
  @page { size: A3 landscape; margin: 8mm; }
  .aux-panel, table { page-break-inside: avoid; }
  /* Bỏ in URL sau link trong cell — đã có rule chung quá noisy */
  .cell a[href]::after { content: none !important; }
}

/* content-visibility: auto cho off-screen content (giảm initial layout ~50ms) */
.related-books { content-visibility: auto; contain-intrinsic-size: 1px 280px; }
.legend, .cell-key { content-visibility: auto; contain-intrinsic-size: 1px 200px; }

/* will-change cho highlight pulse (GPU-friendly) */
.cell.highlight { will-change: box-shadow; }

/* ============================================================
   Electron visualization (SGK lớp 10) — Bohr + Orbital diagram
   ============================================================ */
.ev-section { background: rgba(56, 189, 248, 0.05); padding: 10px 12px; border-radius: 6px; margin-top: 12px; }
.ev-section h3 { margin: 0 0 8px; }
.ev-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 480px) { .ev-grid { grid-template-columns: 1fr 1fr; } }
.ev-col h4 { margin: 0 0 6px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.3px; }
.ev-bohr-svg { width: 100%; height: auto; max-width: 260px; display: block; margin: 0 auto; }
.ev-orbital { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.ev-row { display: flex; align-items: center; gap: 8px; }
.ev-label { font-size: 12px; font-weight: 600; color: var(--text); min-width: 38px; }
.ev-svg { background: var(--bg-deep); border-radius: 3px; }
.ev-note { margin: 8px 0 0; font-size: 11px; line-height: 1.5; color: var(--muted); font-style: italic; }

/* Electron viz: cột "Đám mây orbital" — hình dạng s, p, d, f */
.ev-grid-3 { grid-template-columns: 1fr; }
@media (min-width: 720px) { .ev-grid-3 { grid-template-columns: 1fr 1fr 1fr; } }
.ev-cloud { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.ev-cloud-row { display: flex; align-items: center; gap: 8px; }
.ev-cloud-label { font-size: 14px; font-weight: 700; color: var(--accent); min-width: 24px; text-align: center; }
.ev-cloud-svg { background: var(--bg-deep); border-radius: 4px; max-width: 100%; height: auto; }

/* ============================================================================
   REVIEW MODE NXB GD VN — ẩn tạm chức năng "digital-only" cho vòng duyệt.
   Khi xong duyệt: web/js/review_mode.js → REVIEW_MODE = false (hoặc xoá file).
   ============================================================================ */
body.review-mode #search,
body.review-mode #quiz-btn,
body.review-mode #chat-toggle,
body.review-mode #chatbot,
body.review-mode #quiz-modal {
  display: none !important;
}

/* Ẩn tab Hữu cơ + Công cụ trong view-tabs (tables.js cũng đã filter, đây là backup) */
body.review-mode #view-tabs .view-tab[data-view="organic"],
body.review-mode #view-tabs .view-tab[data-view="tools"] {
  display: none !important;
}

/* Khi 1 phần tử bị ẩn → header bớt rộng, layout tự co lại */


/* ===== khôi phục 27/08: khối bị mất khi OneDrive lùi file ===== */
.cd-notes h4::after{ content: " · nhóm biên soạn"; font-weight: 400; font-size: 11px; color: var(--muted); }
.cd-eq-list{ list-style: none; margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--accent); background: rgba(127,127,127,0.07); border-radius: 0 4px 4px 0; }
.cd-eq-list .cd-eq{ display: block; padding: 2px 0; line-height: 1.6; }
