/* ===== Design tokens ===== */
:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-2: #efe9dd;
  --ink: #20242b;
  --muted: #6b6f78;
  --line: #d9d2c4;
  --accent: #b8232c;
  --accent-soft: #f2dada;
  --good: #1f7a4d;
  --good-bg: #dff0e6;
  --avoid: #b8232c;
  --avoid-bg: #f6dede;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  /* unit colors */
  --ky: #2563b8;
  --cung: #1f7a4d;
  --thuong: #b8232c;
  --khien: #8a6d1f;
  /* faction colors: Ngụy xanh đậm, Thục xanh lá, Ngô đỏ, Quần vàng */
  --f-nguy: #1f3a93;
  --f-thuc: #1f7a4d;
  --f-ngo: #b8232c;
  --f-quan: #c9962a;
  --f-honhop: #7349a8;
}
:root[data-theme="dark"] {
  --bg: #14161b;
  --panel: #1d2027;
  --panel-2: #23272f;
  --ink: #e7e3da;
  --muted: #9aa0ab;
  --line: #333944;
  --accent: #e0555d;
  --accent-soft: #3a2326;
  --good: #5fce95;
  --good-bg: #1c3328;
  --avoid: #e0555d;
  --avoid-bg: #362325;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
  --ky: #6aa6ff;
  --cung: #5fce95;
  --thuong: #e0555d;
  --khien: #d6b85a;
  --f-nguy: #4f74d6;
  --f-thuc: #5fce95;
  --f-ngo: #e0555d;
  --f-quan: #e0b94e;
  --f-honhop: #a884e0;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

/* ===== Header ===== */
.site-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: .7rem 1.2rem;
  background: var(--panel); border-bottom: 2px solid var(--accent);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.logo { font-size: 1.8rem; }
.site-header h1 { font-size: 1.15rem; margin: 0; }
.tagline { margin: 0; font-size: .78rem; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: .8rem; }
.stats { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: .35rem .55rem; cursor: pointer; font-size: 1rem; color: var(--ink); }

/* ===== Section nav ===== */
.section-nav {
  display: flex; gap: .3rem; padding: .5rem 1.2rem 0; background: var(--panel);
  position: sticky; top: 54px; z-index: 40; flex-wrap: wrap;
}
.nav-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: .5rem .9rem; font-size: .92rem; cursor: pointer; color: var(--muted);
  border-radius: 6px 6px 0 0;
}
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.filter-toggle { margin-left: auto; display: none; }
.disclaimer { font-size: .76rem; color: var(--muted); padding: .5rem 1.2rem 0; margin: 0; font-style: italic; }

/* ===== Layout ===== */
.layout { display: grid; grid-template-columns: 270px 1fr; gap: 1.2rem; padding: 1rem 1.2rem 3rem; align-items: start; }
/* Khi ẩn sidebar lọc (section không phải Team PK), nội dung tràn full để card xếp nhiều cột. */
.layout.full { grid-template-columns: 1fr; }
.content { min-width: 0; }

/* ===== Filter panel ===== */
.filter-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; position: sticky; top: 104px; max-height: calc(100vh - 120px); overflow-y: auto;
}
.filter-bar { display: flex; gap: .4rem; margin-bottom: .8rem; }
.search { flex: 1; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: .85rem; }
.clear-btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 8px; padding: 0 .6rem; cursor: pointer; font-size: .8rem; }
.fgroup { margin-bottom: .9rem; }
.flabel { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .35rem; font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: .3rem; }
.fchip { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: .22rem .6rem; font-size: .78rem; cursor: pointer; }
.fchip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
/* Chip Phe: chấm màu trước nhãn + nền màu phe khi chọn */
.fchip[class*="f-"]::before { content: ""; display: inline-block; width: .55em; height: .55em; border-radius: 50%; margin-right: .35rem; vertical-align: baseline; }
.fchip.f-nguy::before { background: var(--f-nguy); }
.fchip.f-thuc::before { background: var(--f-thuc); }
.fchip.f-ngo::before { background: var(--f-ngo); }
.fchip.f-quan::before { background: var(--f-quan); }
.fchip.f-honhop::before { background: var(--f-honhop); }
.fchip.f-nguy.on { background: var(--f-nguy); border-color: transparent; color: #fff; }
.fchip.f-thuc.on { background: var(--f-thuc); border-color: transparent; color: #fff; }
.fchip.f-ngo.on { background: var(--f-ngo); border-color: transparent; color: #fff; }
.fchip.f-quan.on { background: var(--f-quan); border-color: transparent; color: #3a2c00; }
.fchip.f-honhop.on { background: var(--f-honhop); border-color: transparent; color: #fff; }
.fchip.on[class*="f-"]::before { background: #fff; }
.fchip.f-quan.on::before { background: #3a2c00; }
.combo-input { width: 100%; padding: .42rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font-size: .82rem; }
.combo-list { display: flex; flex-direction: column; gap: 1px; margin-top: .2rem; }
.combo-item { text-align: left; border: none; background: var(--panel-2); color: var(--ink); padding: .35rem .5rem; cursor: pointer; font-size: .8rem; border-radius: 4px; }
.combo-item:hover { background: var(--accent-soft); }
.combo-selected { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .4rem; }
.sel-tag { background: var(--accent); color: #fff; border: none; border-radius: 999px; padding: .2rem .55rem; font-size: .76rem; cursor: pointer; }

/* ===== Team grid ===== */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: .9rem; }
.team-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.team-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.team-card.dim { opacity: .82; }
.team-name { display: block; width: 100%; text-align: left; background: none; border: none; cursor: pointer; padding: 0 0 .4rem; margin-bottom: .5rem; color: var(--accent); font-size: 1rem; font-weight: 700; letter-spacing: .01em; }
.team-name:hover { text-decoration: underline; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; margin-bottom: .6rem; padding-bottom: .5rem; border-bottom: 1px dashed var(--line); }
.units { display: flex; gap: .25rem; flex-wrap: wrap; }
.head-right { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.badge { font-size: .72rem; padding: .15rem .5rem; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.badge.unit { color: #fff; }
.badge.unit.small { font-size: .62rem; padding: .05rem .3rem; }
.u-ky { background: var(--ky); } .u-cung { background: var(--cung); } .u-thuong { background: var(--thuong); } .u-khien { background: var(--khien); }
.badge.stars { background: #f5c542; color: #5a4500; }
.badge.faction { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
/* Phe: tô màu nhãn + viền trái card để quét nhanh */
.badge.faction.f-nguy { background: var(--f-nguy); color: #fff; border-color: transparent; }
.badge.faction.f-thuc { background: var(--f-thuc); color: #fff; border-color: transparent; }
.badge.faction.f-ngo { background: var(--f-ngo); color: #fff; border-color: transparent; }
.badge.faction.f-quan { background: var(--f-quan); color: #3a2c00; border-color: transparent; }
.badge.faction.f-honhop { background: var(--f-honhop); color: #fff; border-color: transparent; }
.team-card.fa-nguy { border-left: 4px solid var(--f-nguy); }
.team-card.fa-thuc { border-left: 4px solid var(--f-thuc); }
.team-card.fa-ngo { border-left: 4px solid var(--f-ngo); }
.team-card.fa-quan { border-left: 4px solid var(--f-quan); }
.team-card.fa-honhop { border-left: 4px solid var(--f-honhop); }
.badge.status { border: 1px solid var(--line); }
.status-out-meta { background: var(--panel-2); color: var(--muted); }
.status-youtuber-untested { background: #efe0fb; color: #6b2fb3; }
.status-situational { background: #fde9d6; color: #9a5a1a; }

.heroes { display: flex; flex-direction: column; gap: .5rem; }
.hero { padding: .35rem .45rem; background: var(--bg); border-radius: 8px; }
.hero-name { font-size: .92rem; margin-bottom: .2rem; display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.hn { font-weight: 700; }
.pre { font-size: .6rem; font-weight: 700; padding: .05rem .25rem; border-radius: 4px; color: #fff; }
.pre.sp { background: var(--accent); } .pre.co { background: var(--khien); }
.variant { font-size: .74rem; color: var(--muted); }
.line { display: flex; flex-wrap: wrap; gap: .25rem .15rem; align-items: center; margin-top: .15rem; }
.vg { display: inline-flex; align-items: center; gap: .1rem; }
.alt-sep { color: var(--muted); font-size: .7rem; }
.tag { border: none; cursor: pointer; font-size: .76rem; padding: .12rem .4rem; border-radius: 5px; }
.t-tactic { background: var(--accent-soft); color: var(--accent); }
.t-book { background: var(--panel-2); color: var(--muted); font-size: .72rem; }
.tag.alt { opacity: .75; font-style: italic; }

.counters { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--line); }
.chip { border: none; cursor: pointer; font-size: .73rem; padding: .15rem .45rem; border-radius: 999px; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.avoid { background: var(--avoid-bg); color: var(--avoid); }
.notes { margin-top: .5rem; font-size: .76rem; color: var(--muted); font-style: italic; }
.empty, .error { color: var(--muted); padding: 2rem; text-align: center; grid-column: 1 / -1; }
.error { color: var(--accent); }

/* ===== Sections ===== */
.section { display: none; }
.section.active { display: block; }

/* Coexist — card lồng, tái dùng kiểu .hero + tag */
.coexist-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.2rem; }
.coexist-group > h3 { margin: 0 0 .5rem; font-size: 1rem; color: var(--accent); }
.coexist-teams { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; }
.coexist-subteam { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .6rem; }
.coexist-subteam-title { margin: 0 0 .5rem; font-size: .88rem; padding-bottom: .35rem; border-bottom: 1px dashed var(--line); }
/* tag chiến pháp/binh thư ở Cùng Tồn chỉ hiển thị, không bấm */
.coexist-subteam .tag { cursor: default; }
.ct-meta { display: flex; flex-wrap: wrap; gap: .15rem .6rem; margin-top: .25rem; font-size: .72rem; color: var(--muted); }
.ct-meta-item b { color: var(--ink); font-weight: 600; }
/* Tổng quan combo — thu gọn được */
.coexist-summary-box { margin: 0 0 .8rem; font-size: .82rem; }
.coexist-summary-box > summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.coexist-summary { margin: .4rem 0 0; color: var(--muted); line-height: 1.5; }
.muted { color: var(--muted); } .stat { color: var(--ky); } .advisor { color: var(--khien); }

/* Khaihoang */
.mines { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.mine { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; }
.mine h3 { margin: 0 0 .6rem; color: var(--accent); }
.enemies { display: flex; flex-direction: column; gap: .35rem; }
.enemy { display: flex; justify-content: space-between; align-items: center; padding: .3rem .5rem; background: var(--bg); border-radius: 6px; border-left: 3px solid var(--line); font-size: .85rem; }
.enemy.u-ky { border-left-color: var(--ky); } .enemy.u-cung { border-left-color: var(--cung); }
.enemy.u-thuong { border-left-color: var(--thuong); } .enemy.u-khien { border-left-color: var(--khien); }

/* Khai hoang — đội hình đề xuất (tái dùng kiểu card Team PK) */
.kh-block { margin-bottom: 1.6rem; }
.kh-section-title { font-size: 1rem; color: var(--accent); margin: 0 0 .8rem; padding-bottom: .35rem; border-bottom: 2px solid var(--line); }
.kh-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.kh-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.kh-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.kh-title { margin: 0; font-size: .9rem; text-align: right; }
/* Nhãn Trước/Sau đứng đầu mỗi dòng chiến pháp. */
.kh-line .kh-label { font-size: .66rem; font-weight: 700; color: var(--muted); text-transform: uppercase; min-width: 2.6rem; }
.kh-note { font-size: .73rem; color: var(--muted); font-style: italic; margin-top: .15rem; }
/* Tag chiến pháp ở khai hoang chỉ để hiển thị, không bấm. */
.kh-card .tag, .kh-tf .tag { cursor: default; }
.kh-transforms { margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--line); }
.kh-tf-label { display: block; font-size: .73rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .35rem; }
.kh-tf { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; font-size: .8rem; margin-bottom: .2rem; }

/* Footer */
.site-footer { text-align: center; padding: 1.5rem; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--line); }
.site-footer .credit { margin-top: .4rem; }
.site-footer .credit strong { color: var(--text); }

/* ===== Tra cứu chiến pháp ===== */
.tac-toolbar { position: sticky; top: 96px; z-index: 5; background: var(--bg); padding: .4rem 0 .6rem; display: flex; flex-direction: column; gap: .5rem; }
.tac-search { width: 100%; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); font-size: .95rem; }
.tac-filter-row { display: flex; flex-wrap: wrap; gap: .8rem; }
.tac-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.tac-count { font-size: .78rem; color: var(--muted); }
.tac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .7rem; margin-top: .4rem; }
.tac-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); padding: .65rem .75rem; display: flex; flex-direction: column; gap: .35rem; }
.tac-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tac-viet { font-weight: 700; font-size: .98rem; color: var(--ink); }
.tac-q { font-weight: 700; font-size: .72rem; padding: .08rem .4rem; border-radius: 999px; color: #fff; }
.tac-q.q-S { background: var(--accent); }
.tac-q.q-A { background: var(--f-nguy); }
.tac-q.q-B { background: var(--muted); }
.tac-sub { display: flex; gap: .5rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.tac-cn { font-weight: 600; }
.tac-meta { display: flex; flex-wrap: wrap; gap: .3rem; }
.tac-type { font-size: .72rem; padding: .08rem .45rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tac-troop { font-size: .72rem; padding: .08rem .45rem; border-radius: 999px; background: var(--panel-2); color: var(--ink); }
.tac-desc { margin: 0; font-size: .82rem; line-height: 1.45; color: var(--ink); }
.tac-desc.pending { color: var(--muted); font-style: italic; }

/* ===== Soi đội từ ảnh ===== */
.ana-disclaimer { font-size: .8rem; color: var(--muted); background: var(--panel-2); border-radius: var(--radius); padding: .5rem .7rem; margin: 0 0 .8rem; }
.ana-setup { padding: 1.2rem; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; color: var(--muted); }
.ana-drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.4rem; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.ana-drop:hover, .ana-drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.ana-file { display: none; }
.ana-preview { display: none; max-width: 100%; max-height: 260px; margin: .7rem 0; border-radius: var(--radius); border: 1px solid var(--line); }
.ana-preview.on { display: block; }
.ana-turnstile { margin: .6rem 0; }
.ana-btn { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: .55rem 1.1rem; font-size: .95rem; font-weight: 600; cursor: pointer; }
.ana-btn:disabled { opacity: .5; cursor: not-allowed; }
.ana-status { font-size: .85rem; margin: .5rem 0; }
.ana-status.err { color: var(--avoid); }
.ana-results { margin-top: 1rem; }
.ana-rh { font-size: .95rem; margin: 1rem 0 .5rem; }
.ana-heroes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.ana-hero { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: .55rem .7rem; }
.ana-hero-head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .35rem; }
.ana-hero-name { font-weight: 700; }
.ana-stat { font-size: .72rem; padding: .06rem .4rem; border-radius: 999px; background: var(--f-nguy); color: #fff; }
.ana-flag { font-size: .7rem; color: var(--avoid); }
.ana-tactics { display: flex; flex-wrap: wrap; gap: .3rem; }
.ana-tac { font-size: .76rem; padding: .08rem .45rem; border-radius: 999px; background: var(--panel-2); }
.ana-tac.unsure { border: 1px dashed var(--avoid); color: var(--avoid); }
.ana-teams { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.ana-team-link { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem .6rem; cursor: pointer; text-align: left; color: var(--ink); }
.ana-team-link:hover { border-color: var(--accent); }
.ana-note { font-size: .82rem; color: var(--muted); }

/* ===== Responsive ===== */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .filter-toggle { display: inline-block; }
  .filter-panel { display: none; position: fixed; inset: 0 0 0 auto; width: min(86vw, 320px); z-index: 60; border-radius: 0; max-height: 100vh; }
  .filter-panel.open { display: block; }
  .section-nav { top: 52px; }
  .filter-panel { top: 0; }
  .tac-toolbar { top: 52px; }
}
