:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #dde2ea;
  --text: #1c2330;
  --muted: #5d6779;
  --accent: #2f7de1;
  --accent-soft: #e3eefc;
  --green: #2f9e57;
  --gold: #b7791f;
  --red: #d64545;
  --purple: #7c4dcc;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
  --radius: 12px;
  --topbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c;
    --surface: #171e29;
    --surface-2: #1f2835;
    --border: #2b3646;
    --text: #e6ebf2;
    --muted: #9aa6b8;
    --accent: #5aa2f5;
    --accent-soft: #1b2c44;
    --green: #4cc17a;
    --gold: #e0a63e;
    --red: #f07070;
    --purple: #a888ec;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #171e29; --surface-2: #1f2835; --border: #2b3646; --text: #e6ebf2;
  --muted: #9aa6b8; --accent: #5aa2f5; --accent-soft: #1b2c44; --green: #4cc17a; --gold: #e0a63e;
  --red: #f07070; --purple: #a888ec; --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 12px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 "Noto Sans TC", system-ui, -apple-system, "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; font-weight: 900; }
h2 { font-size: 1.25rem; font-weight: 700; margin-top: 1.6em; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .8em; }
code, .cmd {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}

/* ---------- 頂部列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 900; font-size: 1.1rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-size: .7rem; font-weight: 500; color: var(--muted); line-height: 1; }
.brand span { line-height: 1.2; }
.search { flex: 1; max-width: 440px; margin-left: auto; }
.search input {
  width: 100%; height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }
.lang-btn {
  flex-shrink: 0; height: 38px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.menu-btn { display: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 8px; width: 40px; height: 38px; font-size: 1.1rem; cursor: pointer; }

/* ---------- 版面 ---------- */
.layout { display: flex; max-width: 1280px; margin: 0 auto; }
.sidebar {
  position: sticky; top: var(--topbar-h);
  align-self: flex-start;
  width: 210px; flex-shrink: 0;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 20px 12px;
}
.sidebar a { display: block; padding: 7px 12px; border-radius: 8px; color: var(--text); }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-group { font-size: .75rem; font-weight: 700; color: var(--muted); letter-spacing: .08em; margin: 16px 12px 6px; }
.nav-group:first-child { margin-top: 0; }
main { flex: 1; min-width: 0; padding: 28px 28px 60px; outline: none; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px 16px 40px; border-top: 1px solid var(--border); }

/* ---------- 共用元件 ---------- */
.page-head { margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; line-height: 1.7;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.easy { color: var(--green); border-color: currentColor; background: transparent; }
.badge.normal { color: var(--gold); border-color: currentColor; background: transparent; }
.badge.hard { color: var(--red); border-color: currentColor; background: transparent; }
.badge.accent { color: var(--accent); border-color: currentColor; background: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 10px; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-weight: 700;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
.toolbar input { flex: 1; min-width: 180px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tab { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; color: var(--muted); font-weight: 400; }
th.sort-asc::after { content: " ↑"; color: var(--accent); }
th.sort-desc::after { content: " ↓"; color: var(--accent); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-buy { color: var(--red); }
.price-sell { color: var(--green); }

/* ---------- 首頁 ---------- */
.hero {
  position: relative; overflow: hidden;
  border-radius: 18px; padding: 36px 32px;
  background: linear-gradient(135deg, #1d4f91 0%, #2f7de1 55%, #5fc3e4 100%);
  color: #fff; margin-bottom: 24px;
}
.hero h1 { font-size: 2.2rem; margin-bottom: 6px; }
.hero h1 small { font-size: 1rem; font-weight: 500; opacity: .85; margin-left: 8px; }
.hero .motd { opacity: .92; margin-bottom: 20px; white-space: pre-line; }
.hero .btn { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .35); color: #fff; }
.hero .btn.primary { background: #fff; color: #1d4f91; border-color: #fff; }
.hero-islands { position: absolute; right: 24px; bottom: -6px; width: 180px; opacity: .9; pointer-events: none; }
.connect { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.connect .addr {
  background: rgba(0, 0, 0, .22); border-radius: 10px; padding: 8px 14px; min-width: 220px;
}
.connect .addr small { display: block; font-size: .72rem; opacity: .8; }
.connect .addr b { font-family: ui-monospace, Consolas, monospace; font-size: 1rem; }
.connect .addr button { margin-left: 8px; background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 6px; font: inherit; font-size: .75rem; padding: 0 8px; cursor: pointer; }
.steps { counter-reset: step; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.step { position: relative; padding-top: 44px; }
.step::before {
  counter-increment: step; content: counter(step);
  position: absolute; top: 14px; left: 20px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 900; font-size: .85rem;
  display: grid; place-items: center;
}
.feature { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
.feature:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.feature .icon { font-size: 1.6rem; line-height: 1; margin-bottom: 8px; }
.feature p { color: var(--muted); font-size: .9rem; margin: 0; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: .9rem; color: var(--muted); }
.stat-row b { color: var(--text); }

/* ---------- 指南 ---------- */
.guide-card h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.guide-card ul { margin: 6px 0 0; padding-left: 1.2em; }
.guide-card .body { white-space: pre-line; }

/* ---------- 寶箱 ---------- */
.reward { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: .92rem; }
.reward:last-child { border-bottom: 0; }
.bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.sources { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.sources ul { margin: 4px 0 0; padding-left: 1.2em; font-size: .9rem; }

/* ---------- 副本 ---------- */
.boss { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.boss + .boss { margin-top: 8px; }
.hp { color: var(--red); white-space: nowrap; }
.dmg { color: var(--gold); white-space: nowrap; }
details summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
details[open] summary { margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- 搜尋結果 ---------- */
.result-group h2 { margin-top: 1.2em; }
mark { background: #ffe58a; color: #1c2330; border-radius: 3px; padding: 0 2px; }

/* ---------- 手機 ---------- */
.show-sm { display: none; }
@media (max-width: 860px) {
  .hide-sm { display: none; }
  .show-sm { display: block; line-height: 1.3; }
  .menu-btn { display: block; }
  .topbar { padding: 0 16px; gap: 10px; }
  .brand small { display: none; }
  .search { max-width: none; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 15;
    width: 240px; height: auto;
    background: var(--surface); border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: 8px 0 24px rgba(0, 0, 0, .2); }
  main { padding: 20px 16px 48px; }
  .hero { padding: 26px 20px; }
  .hero h1 { font-size: 1.7rem; }
  .hero-islands { display: none; }
  .grid, .grid.wide { grid-template-columns: 1fr; }
  th, td { padding: 8px 10px; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
}
