/* Wanderia Wiki - bright pastel fantasy theme (light + dark) */
:root {
  --bg: #e9f5ff;
  --bg2: #fdf3ff;
  --card: #ffffff;
  --card2: #f5faff;
  --ink: #24324a;
  --muted: #6a7a93;
  --line: #d9e6f4;
  --accent: #3d9cf5;
  --accent-ink: #ffffff;
  --accent-soft: #dcefff;
  --pink: #ff8fb8;
  --gold: #f2b52f;
  --good: #2f9e44;
  --bad: #e03131;
  --shadow: 0 6px 20px rgba(60, 110, 170, .12);
  --r: 16px;
  --r-sm: 10px;
  --rar0: #24324a; --rar1: #2b8a3e; --rar2: #1c6fd1; --rar3: #9c36b5; --rar4: #d9480f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121a2c; --bg2: #1b1630; --card: #1c2640; --card2: #222e4c; --ink: #e5edf9; --muted: #9babc4; --line: #2e3c5c;
    --accent: #5aaeff; --accent-ink: #0c1424; --accent-soft: #233a5e; --shadow: 0 6px 20px rgba(0, 0, 0, .35);
    --rar0: #e5edf9; --rar1: #69db7c; --rar2: #74b9ff; --rar3: #d59bff; --rar4: #ffb347;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121a2c; --bg2: #1b1630; --card: #1c2640; --card2: #222e4c; --ink: #e5edf9; --muted: #9babc4; --line: #2e3c5c;
  --accent: #5aaeff; --accent-ink: #0c1424; --accent-soft: #233a5e; --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --rar0: #e5edf9; --rar1: #69db7c; --rar2: #74b9ff; --rar3: #d59bff; --rar4: #ffb347;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  background-color: var(--bg);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", "Leelawadee UI", Tahoma, Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px 4px; display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 1.25rem; letter-spacing: .2px; }
.logo:hover { text-decoration: none; }
.logo b { color: var(--accent); }
.logo-mark { width: 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 18%, #ffc8de 19% 45%, #ff8fb8 46% 100%); box-shadow: 0 2px 6px rgba(255, 120, 170, .5); flex: none; }
.top-tools { margin-left: auto; display: flex; gap: 8px; }
.pill { border: 1px solid var(--line); background: var(--card2); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 600; min-width: 40px; }
.pill:hover { border-color: var(--accent); }
.nav { max-width: 1180px; margin: 0 auto; padding: 4px 12px 8px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { white-space: nowrap; padding: 6px 12px; border-radius: 999px; color: var(--ink); font-weight: 600; font-size: .93rem; }
.nav a:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.on { background: var(--accent); color: var(--accent-ink); }

main.wrap { padding-top: 20px; padding-bottom: 30px; }
.foot { color: var(--muted); font-size: .85rem; padding-bottom: 30px; }

/* ---------- generic blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) { .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 14px; }
.note { background: var(--accent-soft); border-radius: var(--r-sm); padding: 8px 12px; font-size: .88rem; }
.warn { background: #fff1d6; color: #7a4b00; border-radius: var(--r-sm); padding: 8px 12px; font-size: .88rem; }
:root[data-theme="dark"] .warn { background: #3d2f12; color: #ffd98a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .warn { background: #3d2f12; color: #ffd98a; } }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--card2); border: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.chip.acc { background: var(--accent-soft); border-color: transparent; }
.chip.mvp { background: #ffe3a3; color: #7a4b00; border-color: transparent; }
.chip.mini { background: #ffd6e7; color: #8a1f4c; border-color: transparent; }
.chip.aggr { background: #ffe0e0; color: #a51d1d; border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.el { color: #fff; border: 0; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.el0 { background: #9aa3ad; } .el1 { background: #3d9cf5; } .el2 { background: #b0814a; } .el3 { background: #f2603c; } .el4 { background: #3fbf6a; }
.el5 { background: #9a5fd6; } .el6 { background: #e0a800; } .el7 { background: #574c6e; } .el8 { background: #a98cf0; } .el9 { background: #6f7f62; }
.r0 { color: var(--rar0); } .r1 { color: var(--rar1); } .r2 { color: var(--rar2); } .r3 { color: var(--rar3); } .r4 { color: var(--rar4); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.filters > * { min-width: 0; }
input[type="search"], input[type="number"], select, .inp {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 7px 10px; outline: none; max-width: 100%;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filters input[type="search"] { flex: 1 1 220px; }
.filters select { flex: 0 1 auto; }
.filters label { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; }
.filters input[type="number"] { width: 76px; }
.count { color: var(--muted); font-size: .88rem; margin: -6px 0 10px; }
.btn { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 8px 14px; font-weight: 700; cursor: pointer; }
.btn.ghost { background: var(--card2); color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.more { display: block; margin: 14px auto 0; }

/* ---------- list tiles ---------- */
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
@media (max-width: 560px) { .tiles { grid-template-columns: minmax(0, 1fr); } }
.tile { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); min-width: 0; transition: transform .12s, box-shadow .12s; }
.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.tile .tx { min-width: 0; flex: 1; }
.tile .nm { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .sub { display: block; color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ico { width: 44px; height: 44px; flex: none; border-radius: 12px; background: var(--card2); display: grid; place-items: center; overflow: hidden; }
.ico img { width: 100%; height: 100%; object-fit: contain; }
.ico.lg { width: 96px; height: 96px; border-radius: 18px; }
.ico.sm { width: 30px; height: 30px; border-radius: 8px; }
.ico.round { border-radius: 50%; }
.badge { width: 100%; height: 100%; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: .95em; text-shadow: 0 1px 2px rgba(0,0,0,.35); border-radius: inherit; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .row-link { display: flex; align-items: center; gap: 8px; color: var(--ink); min-width: 0; }
.tbl .row-link:hover { color: var(--accent); }
.tbl tr.hl td { background: var(--accent-soft); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

/* ---------- detail ---------- */
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: 10px; }
.head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.head h1 { margin: 0; }
.head .tx { min-width: 0; flex: 1; }
.cardart { width: 200px; max-width: 100%; border-radius: 14px; box-shadow: var(--shadow); display: block; }
.pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.pct.hi { color: var(--good); }
.pct.lo { color: var(--rar3); }
.pre { white-space: pre-line; }
.eltbl { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 560px) { .eltbl { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.eltbl div { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 10px; background: var(--card2); font-size: .86rem; }
.eltbl b.up { color: var(--good); } .eltbl b.down { color: var(--bad); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 26px 16px 22px; border-radius: 24px; background: radial-gradient(circle at 20% 0%, #fff7 0, transparent 50%), linear-gradient(135deg, #8fd0ff 0%, #b8a8ff 55%, #ffb3d1 100%); color: #10223c; box-shadow: var(--shadow); }
.hero h1 { font-size: 1.9rem; margin-bottom: 6px; }
.hero p { margin: 0 0 14px; }
.hero input { width: min(560px, 100%); padding: 11px 16px; border-radius: 999px; border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.12); background: #fff; color: #10223c; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.stat-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; color: var(--ink); }
.stat-box:hover { text-decoration: none; border-color: var(--accent); }
.stat-box b { display: block; font-size: 1.5rem; color: var(--accent); }

/* ---------- world map ---------- */
.wm { position: relative; border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); background: #8ec5e8; }
.wm img { display: block; width: 100%; height: auto; }
.pin { position: absolute; transform: translate(-50%, -50%); width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.4); padding: 0; cursor: pointer; }
.pin.town { border-color: #f2b52f; width: 18px; height: 18px; }
.pin.dun { border-color: #574c6e; }
.pin.here { border-color: var(--pink); width: 22px; height: 22px; animation: pulse 1.3s infinite; }
.pin span { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 3px; white-space: nowrap; font-size: 11px; font-weight: 700; background: rgba(255,255,255,.88); color: #10223c; padding: 0 5px; border-radius: 6px; pointer-events: none; display: none; }
.pin:hover span, .pin:focus span, .pin.here span, .pin.town span { display: block; }
@media (max-width: 700px) { .pin.town span { display: none; } .pin.here span { display: block; } .pin { width: 11px; height: 11px; border-width: 2px; } .pin.town { width: 13px; height: 13px; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(255,143,184,.35); } }
.region-h { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; }
.region-dot { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.mons-mini { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.mons-mini img { width: 22px; height: 22px; border-radius: 6px; background: var(--card2); }

/* ---------- NPC list ---------- */
.npc { border-top: 1px solid var(--line); padding: 10px 0; }
.npc:first-child { border-top: 0; padding-top: 0; }
.npc-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.shop-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.shop-items a { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); font-size: .84rem; color: var(--ink); max-width: 100%; }
.shop-items a:hover { border-color: var(--accent); text-decoration: none; }
.shop-items .ico { width: 24px; height: 24px; border-radius: 6px; }

/* ---------- simulators ---------- */
.sim { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .sim { grid-template-columns: minmax(0, 1fr); } }
.sticky { position: sticky; top: 104px; }
@media (max-width: 900px) { .sticky { position: static; } }
.ctl { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.ctl label { display: flex; flex-direction: column; gap: 3px; font-size: .82rem; color: var(--muted); font-weight: 600; min-width: 0; }
.ctl select, .ctl input { color: var(--ink); }
.statrow { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.statrow:last-child { border-bottom: 0; }
.statrow .sn { font-weight: 800; }
.statrow .sh { font-size: .78rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; font-weight: 800; padding: 0; }
.stepper button:hover:not(:disabled) { border-color: var(--accent); }
.stepper button:disabled { opacity: .35; cursor: not-allowed; }
.stepper input { width: 52px; text-align: center; padding: 5px 4px; }
.stepper .bonus { color: var(--good); font-weight: 700; font-size: .85rem; min-width: 26px; }
.cost { font-size: .75rem; color: var(--muted); text-align: right; }
.points { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.points .big { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.points .neg { color: var(--bad); }
.res { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; font-size: .94rem; }
.res dt { color: var(--muted); }
.res dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.res .sep { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 6px 0; }
.eqgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .eqgrid { grid-template-columns: minmax(0, 1fr); } }
.eqgrid label { display: flex; flex-direction: column; gap: 3px; font-size: .8rem; color: var(--muted); font-weight: 600; min-width: 0; }
.eqgrid select { width: 100%; color: var(--ink); }
.paslist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
@media (max-width: 560px) { .paslist { grid-template-columns: minmax(0, 1fr); } }
.paslist label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .88rem; min-width: 0; }
.paslist label span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* skill tree */
.tree { position: relative; margin-top: 8px; }
.tree svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.tree svg line { stroke: var(--line); stroke-width: 3; }
.tree svg line.ok { stroke: var(--accent); }
.tree-grid { position: relative; display: grid; gap: 10px; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
.sk { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; background: var(--card); border: 2px solid var(--line); border-radius: 14px; cursor: pointer; text-align: center; min-width: 0; user-select: none; }
.sk:hover { border-color: var(--accent); }
.sk.sel { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255,143,184,.3); }
.sk.locked { opacity: .5; }
.sk.learned { background: var(--accent-soft); }
.sk.innate { border-style: dashed; }
.sk img { width: 40px; height: 40px; border-radius: 10px; }
.sk .snm { font-size: .74rem; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.sk .slv { font-size: .78rem; font-weight: 800; color: var(--accent); }
.sk .sbtn { display: flex; gap: 4px; margin-top: 2px; }
.sk .sbtn button { width: 26px; height: 24px; border-radius: 8px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; font-weight: 800; padding: 0; line-height: 1; }
.sk .sbtn button:disabled { opacity: .3; cursor: not-allowed; }
.sk .pas { position: absolute; top: 4px; right: 6px; font-size: .62rem; color: var(--muted); font-weight: 700; }
.empty { min-height: 1px; }
@media (max-width: 560px) { .sk img { width: 32px; height: 32px; } .tree-grid { gap: 6px; } .sk .snm { font-size: .68rem; } }

.jobcard { display: flex; gap: 14px; align-items: flex-start; }
.jobcard img { width: 64px; height: 64px; border-radius: 16px; background: var(--card2); flex: none; }
.steps { counter-reset: st; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: st; position: relative; padding: 4px 0 10px 40px; }
.steps li::before { content: counter(st); position: absolute; left: 0; top: 2px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 8px 16px; border-radius: 999px; font-weight: 600; z-index: 50; }

/* วิธีเล่น / การควบคุม */
.home-link { text-decoration: none; color: inherit; white-space: nowrap; }
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.ctl-grid .card + .card { margin-top: 0; }
.ctl td.keys { text-align: right; white-space: normal; }
kbd { display: inline-block; padding: 1px 7px; margin: 1px 0; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--card2); font: 600 .82rem/1.5 inherit; white-space: nowrap; }
.tips { margin: 0; padding-left: 1.2em; line-height: 1.7; }
@media (max-width: 520px) { .ctl td.keys { text-align: left; } .ctl tr { display: grid; } .home-link { padding: 4px 8px; } }

/* รูป NPC เปลี่ยนอาชีพ */
.npc-cards { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.npc-card { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 150px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card2); text-decoration: none; color: inherit; text-align: center; }
.npc-card:hover { border-color: var(--accent); }
.npc-card img { width: 120px; height: 150px; object-fit: contain; }
.npc-card .nm { font-weight: 700; }
