/* Layout: sticky tab bar, then per-tab work area (list | main | detail); columns stack on narrow screens. */
:root {
  --bg: #eef1ef; --panel: #ffffff; --sunk: #e3e8e5; --line: #cfd8d3;
  --fg: #1d2622; --muted: #5d6b64; --accent: #1f7a65; --accent-soft: #d5ece4;
  --gold: #b07a12; --gold-soft: #f6e7c6; --npc: #2463c9; --warn: #b4531c; --warn-soft: #f8e2d4; --ok: #2c7a3a; --ok-soft: #dcefdc;
  --mt: #7a4fc2; --mt-soft: #ece4f8;
  --f-display: "Lexend", "Be Vietnam Pro", system-ui, sans-serif;
  --f-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #141a18; --panel: #1c2421; --sunk: #232d29; --line: #33413b;
  --fg: #e3ebe7; --muted: #94a59d; --accent: #4fc2a3; --accent-soft: #1d3a32;
  --gold: #e3b452; --gold-soft: #3a2f17; --npc: #6fa4ff; --warn: #f0965f; --warn-soft: #3d2618; --ok: #7bcf87; --ok-soft: #1e3322;
  --mt: #b996f0; --mt-soft: #2d2440; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #141a18; --panel: #1c2421; --sunk: #232d29; --line: #33413b;
  --fg: #e3ebe7; --muted: #94a59d; --accent: #4fc2a3; --accent-soft: #1d3a32;
  --gold: #e3b452; --gold-soft: #3a2f17; --npc: #6fa4ff; --warn: #f0965f; --warn-soft: #3d2618; --ok: #7bcf87; --ok-soft: #1e3322;
  --mt: #b996f0; --mt-soft: #2d2440; color-scheme: dark }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 14px; line-height: 1.5; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--f-mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header.bar { position: sticky; top: 0; z-index: 9; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 18px; }
.brand .seal { font-family: var(--f-mono); font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }
nav.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
nav.tabs a { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
nav.tabs a[aria-current="page"] { color: var(--fg); background: var(--accent-soft); }
nav.tabs a:hover { color: var(--fg); text-decoration: none; }

main { padding: 16px 16px 40px; max-width: 1560px; margin: 0 auto; }
section.view { display: none; } section.view.on { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.panel > .hd { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel > .hd h2 { font-size: 15px; }
.pad { padding: 12px 14px; }
.field { background: var(--sunk); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; border-radius: 999px; padding: 1px 8px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.chip.npc { background: color-mix(in srgb, var(--npc) 16%, transparent); color: var(--npc); }
.chip.boss { background: var(--gold-soft); color: var(--gold); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
.chip.mt { background: var(--mt-soft); color: var(--mt); }
.mtb { font-size: 10px; color: var(--mt); background: var(--mt-soft); border-radius: 4px; padding: 0 4px; margin-left: 4px; vertical-align: 1px; white-space: nowrap; font-weight: 500; }
.mtx { border-bottom: 1px dotted var(--mt); cursor: help; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { min-width: 200px; flex: 1 1 220px; }
.filters label { font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 4px 10px; font-size: 12px; }
.seg button.on { background: var(--accent); color: var(--panel); }
.seg button:disabled { opacity: .4; cursor: default; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; }
.detail h3 { font-size: 16px; }
.zh { color: var(--muted); font-size: 12px; }
.sub { font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.desc { white-space: pre-line; font-size: 13px; background: var(--sunk); border-radius: 6px; padding: 8px 10px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.icon { width: 32px; height: 32px; flex: none; border-radius: 4px; background: #11181a; object-fit: contain; display: inline-grid; place-items: center; color: #6b7a74; font-size: 10px; }
.big { width: 64px; height: 64px; image-rendering: pixelated; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.it { display: inline-flex; align-items: center; gap: 6px; background: var(--sunk); border-radius: 6px; padding: 2px 8px 2px 2px; font-size: 12px; color: var(--fg); max-width: 100%; }
.it:hover { text-decoration: none; outline: 1px solid var(--accent); }
.it .icon { width: 24px; height: 24px; }
.it b { color: var(--accent); }
.tag { font-size: 12px; background: var(--sunk); border-radius: 4px; padding: 1px 6px; color: var(--fg); }
table.t { border-collapse: collapse; font-size: 13px; width: 100%; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
table.t th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); z-index: 1; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.on td { background: var(--accent-soft); }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--sunk); }
.tw { overflow: auto; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager .pg { display: flex; gap: 4px; flex-wrap: wrap; }
.pager button { background: var(--sunk); border: 1px solid var(--line); border-radius: 5px; min-width: 32px; padding: 3px 8px; }
.pager button.on { background: var(--accent); color: var(--panel); border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; align-items: start; }
.listdetail { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 14px; align-items: start; }
.sticky { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.scroll { max-height: 76vh; overflow: auto; }
.lrow { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 7px 12px; color: inherit; }
.lrow:hover, .lrow.on { background: var(--sunk); text-decoration: none; }
.lrow.on { background: var(--accent-soft); }
.lrow .nm { flex: 1; min-width: 0; }
.lrow .nm b { display: block; font-weight: 600; font-size: 13px; }
.lrow .nm small { display: block; font-size: 11px; color: var(--muted); }

/* ---------- Map ---------- */
.mapgrid { display: grid; grid-template-columns: 240px minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
.mapgrid.inst { grid-template-columns: 240px minmax(0, 1fr); }
.maptools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.maptools label { display: inline-flex; gap: 4px; align-items: center; font-size: 13px; }
.stage { overflow: auto; max-height: 80vh; background: var(--sunk); border-radius: 0 0 var(--r) var(--r); }
.canvas { position: relative; width: 100%; aspect-ratio: 1; margin: 0 auto; }
.canvas.z2 { width: 160%; } .canvas.z3 { width: 240%; }
.canvas img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.canvas.noimg { background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: 10% 10%; }
.noimg-note { position: absolute; left: 8px; top: 8px; font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 6px; padding: 2px 8px; }
.dot { position: absolute; transform: translate(-50%, -50%); border: 0; padding: 0; border-radius: 50%; }
.dot.mob { width: 9px; height: 9px; background: var(--c); box-shadow: 0 0 0 1.5px rgba(0,0,0,.55); }
.dot.mob.boss { width: 15px; height: 15px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); background: #f2c14e; box-shadow: none; }
.dot.npc { min-width: 18px; height: 18px; border-radius: 9px; background: #fff; color: #1d3f86; border: 2px solid #c8312f; font: 600 10px/14px var(--f-mono); padding: 0 3px; }
.dot.gate { width: auto; height: auto; border-radius: 4px; background: #c8312f; color: #fff; font-size: 11px; padding: 1px 6px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.dot.dim { opacity: .18; }
.dot.hl { outline: 3px solid #fff; outline-offset: 1px; z-index: 3; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: rgba(16,22,20,.92); color: #eef4f1; border-radius: 6px; padding: 6px 9px; font-size: 12px; line-height: 1.4; max-width: 260px; transform: translate(-50%, calc(-100% - 12px)); }
.side { display: grid; gap: 14px; }
.tabs2 { display: flex; border-bottom: 1px solid var(--line); }
.tabs2 button { flex: 1; background: none; border: 0; padding: 9px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs2 button.on { color: var(--fg); border-color: var(--accent); }
.rows { max-height: 44vh; overflow: auto; }
.row { display: flex; gap: 8px; align-items: center; padding: 6px 12px; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; background: none; width: 100%; text-align: left; }
.row:hover, .row.on { background: var(--sunk); }
.row .sw { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.row .no { font: 600 11px var(--f-mono); color: #c8312f; min-width: 22px; }
.row .nm { flex: 1; min-width: 0; }
.row .nm small { display: block; color: var(--muted); font-size: 11px; }

/* ---------- Items ---------- */
.igrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; padding: 12px; }
.icard { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px; text-align: left; min-width: 0; color: inherit; }
.icard:hover, .icard.on { border-color: var(--accent); text-decoration: none; }
.icard .icon { width: 40px; height: 40px; }
.icard .nm { min-width: 0; }
.icard .nm b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icard .nm span { font-size: 11px; color: var(--muted); }

/* ---------- Quests ---------- */
.qrow { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; color: inherit; }
.qrow:hover, .qrow.on { background: var(--sunk); text-decoration: none; }
.qrow.on { background: var(--accent-soft); }
.qrow .lv { font: 600 12px var(--f-mono); color: var(--accent); }
.qrow b { font-weight: 600; font-size: 13px; display: block; }
.qrow small { color: var(--muted); font-size: 11px; }
.qhead { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.qhead .t { flex: 1 1 320px; min-width: 0; }
.qhead h2 { font-size: 20px; }
.qmini { width: 240px; max-width: 100%; flex: none; }
.qmini .canvas { border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.qmini p { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps > li { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.steps .n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 600 12px/26px var(--f-mono); text-align: center; }
.steps .who { font-weight: 600; }
.say { margin-top: 8px; }
.say .lbl { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.say .pair { display: grid; gap: 6px; }
.bilingual .say .pair { grid-template-columns: 1fr 1fr; }
.say .orig { display: none; }
.bilingual .say .orig { display: block; }
.say .orig .desc { color: var(--muted); }
.say details summary { cursor: pointer; color: var(--mt); font-size: 12px; margin-top: 3px; }
.bilingual .say details { display: none; }
.srv { border: 1px dashed var(--line); border-radius: 6px; padding: 10px 12px; margin-top: 14px; }
.srv h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }

/* list | detail: both columns one viewport tall, each scrolls on its own */
.listdetail > .panel { height: calc(100vh - 96px); display: flex; flex-direction: column; }
.listdetail > .panel > .scroll { flex: 1; min-height: 0; max-height: none; }
.listdetail > .panel:last-child { overflow: auto; }
.listdetail > .panel:last-child > .hd { position: sticky; top: 0; background: var(--panel); z-index: 2; }
.listdetail > .panel:last-child table.t th { top: 0; }

/* quick tooltip (fixed, so overflow panels cannot clip it) */
#tipf { position: fixed; z-index: 60; white-space: nowrap; background: rgba(16,22,20,.94); color: #eef4f1; font-size: 12px; line-height: 1.4;
  padding: 3px 8px; border-radius: 5px; pointer-events: none; }

/* quick view popover */
a.ref { border-bottom: 1px dashed currentColor; }
a.ref:hover { text-decoration: none; }
#pop { position: fixed; z-index: 50; width: 320px; max-height: calc(100vh - 16px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 28px rgba(0,0,0,.28); padding: 10px; font-size: 12px; line-height: 1.45; }
#pop .ph { display: flex; gap: 10px; align-items: center; }
#pop .kv { font-size: 12px; }
#pop .desc.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; margin-top: 6px; font-size: 12px; }
img.model { width: 72px; height: 72px; object-fit: contain; flex: none; background: radial-gradient(circle at 50% 60%, var(--accent-soft), transparent 70%); border-radius: 8px; }
img.model.sm { width: 48px; height: 48px; }
img.model.big { width: 128px; height: 128px; float: right; margin: 0 0 6px 10px; }
.canvas .tip img.model { position: static; display: block; float: left; width: 56px; height: 56px; margin-right: 8px; background: none; }
.tip:has(img.model) { min-height: 56px; }
#pop .canvas { border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
#pop .dot.mob { width: 7px; height: 7px; }
#pop h4 { margin: 0 0 2px; font-size: 14px; font-family: var(--f-display); }
#pop .acts { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
#pop.pinned { outline: 2px solid var(--accent); }

/* kungfu: one row per manual (bí tịch), its skills after it, like the in-game skill window */
.kfwrap { padding: 12px 14px; display: grid; gap: 14px; }
.kfsec h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.kfrow { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; flex-wrap: wrap; }
.kfrow:nth-child(odd) { background: var(--sunk); }
.kfrow .lv { font: 600 11px var(--f-mono); color: var(--muted); width: 42px; text-align: right; }
.kfrow .sep { color: var(--muted); font-size: 12px; }
.kf { padding: 0; border: 2px solid transparent; border-radius: 6px; background: none; line-height: 0; }
.kf img, .kf .icon { width: 40px; height: 40px; border-radius: 4px; }
.kf.book img, .kf.book .icon { box-shadow: 0 0 0 2px var(--gold); }
.kf:hover { border-color: var(--accent); }
.kf.on { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 1180px) { .mapgrid { grid-template-columns: 210px minmax(0, 1fr); } .mapgrid .side { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) {
  .mapgrid, .mapgrid.inst, .two, .listdetail { grid-template-columns: minmax(0, 1fr); }
  .mapgrid .side { grid-template-columns: minmax(0, 1fr); }
  .scroll { max-height: 300px; }
  .sticky { position: static; max-height: none; }
  .listdetail > .panel { height: auto; }
  .listdetail > .panel > .scroll { max-height: 300px; }
  .bilingual .say .pair { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
