:root {
  --bg: #0b0812;
  --panel: #171125;
  --panel2: #221a36;
  --line: #4a3a70;
  --line2: #6a5aa0;
  --text: #ece6ff;
  --dim: #a89cc8;
  --gold: #ffd24a;
  --good: #5aff7a;
  --bad: #ff6a6a;
  --accent: #9ff0ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif; }
#stage { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #0b0812; font-size: 18px; letter-spacing: 2px; }

/* 選單列 */
#menu { position: absolute; right: 0.6%; bottom: 1.2%; display: flex; flex-direction: column; gap: 3px; }
#menu button { font: inherit; font-size: clamp(10px, 1.25vmin, 15px); padding: 0.35em 0.7em; color: var(--text); background: rgba(20, 12, 34, 0.82);
  border: 2px solid var(--line2); border-radius: 0; cursor: pointer; box-shadow: 2px 2px 0 #000; min-width: 4.8em; text-align: left; }
#menu button small { float: right; margin-left: 0.6em; color: var(--dim); font-size: 0.75em; line-height: 1.8; }
#menu button:hover { background: #3a2a60; border-color: var(--accent); }

/* 戰鬥紀錄 */
#log { position: absolute; left: 0.8%; bottom: 11%; width: 28%; max-height: 30%; overflow: hidden; pointer-events: none;
  display: flex; flex-direction: column; justify-content: flex-end; font-size: clamp(9px, 1.15vmin, 14px); line-height: 1.35; }
#log div { background: rgba(10, 6, 20, 0.55); padding: 1px 6px; margin-top: 1px; text-shadow: 1px 1px 0 #000; animation: logfade 9s forwards; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes logfade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* 面板 */
#panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 86%; height: 84%;
  background: var(--panel); border: 3px solid var(--line2); box-shadow: 0 0 0 3px #000, 6px 6px 0 rgba(0,0,0,0.6);
  display: flex; flex-direction: column; font-size: clamp(11px, 1.4vmin, 16px); }
#panel.hidden, .hidden { display: none !important; }
#panel header { display: flex; align-items: center; gap: 12px; padding: 6px 10px; background: var(--panel2); border-bottom: 2px solid var(--line); }
#panel h2 { margin: 0; font-size: 1.25em; letter-spacing: 2px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
#ptabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#ptabs button, .btn { font: inherit; color: var(--text); background: #2a2044; border: 2px solid var(--line); padding: 2px 10px; cursor: pointer; border-radius: 0; }
#ptabs button.on { background: var(--line2); border-color: var(--accent); }
.btn:hover:not(:disabled), #ptabs button:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.gold { border-color: #b08a20; background: #3a2c10; }
.btn.red { border-color: #a03030; background: #3a1418; }
.btn.small { padding: 0 6px; font-size: 0.9em; }
#pclose { font: inherit; background: none; border: none; color: var(--text); font-size: 1.3em; cursor: pointer; }
#pbody { flex: 1; overflow: auto; padding: 10px 12px; }
#pbody::-webkit-scrollbar { width: 10px; } #pbody::-webkit-scrollbar-thumb { background: var(--line); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.box { background: #120d1e; border: 2px solid var(--line); padding: 8px; }
.box h3 { margin: 0 0 6px; font-size: 1em; color: var(--accent); letter-spacing: 1px; }
.dim { color: var(--dim); } .gold { color: var(--gold); } .good { color: var(--good); } .bad { color: var(--bad); }
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 2px 4px; border-bottom: 1px dashed #2e2448; }
table.kv td:last-child { text-align: right; }

/* 能力 */
.stat { display: grid; grid-template-columns: 5.5em 4em 1fr auto; gap: 6px; align-items: center; padding: 2px 0; }

/* 技能 */
.skill { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 6px; border-bottom: 1px solid #2e2448; }
.skill img, .icon { width: 24px; height: 24px; image-rendering: pixelated; }
.skill .nm { font-weight: bold; }
.skill .desc { color: var(--dim); font-size: 0.88em; }
.skill.locked .nm { color: #8a80a8; }
.tag { display: inline-block; padding: 0 5px; margin-left: 4px; font-size: 0.8em; border: 1px solid var(--line); color: var(--dim); }
.auto-on { background: #1a4a24 !important; border-color: #5aff7a !important; }

/* 物品 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.cell { position: relative; aspect-ratio: 1; background: #0e0a18; border: 2px solid #444; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.05em; }
.cell img { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; }
.cell .enh { position: absolute; right: 1px; top: -1px; font-size: 0.72em; color: var(--gold); text-shadow: 1px 1px 0 #000; }
.cell .cnt { position: absolute; right: 2px; bottom: 0; font-size: 0.72em; text-shadow: 1px 1px 0 #000; }
.cell .new { position: absolute; left: 1px; top: -2px; font-size: 0.65em; color: var(--good); }
.cell .lock { position: absolute; left: 2px; bottom: 0; font-size: 0.65em; }
.cell.sel { outline: 2px solid #fff; }
.cell:hover { filter: brightness(1.3); }
.itemcard { min-width: 220px; }
.itemcard .title { font-weight: bold; font-size: 1.1em; }
.itemcard .line { font-size: 0.92em; }
.legend-desc { color: #ffb060; margin-top: 4px; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.slotbox { border: 2px solid var(--line); background: #0e0a18; padding: 4px; min-height: 52px; cursor: pointer; font-size: 0.9em; }
.slotbox:hover { border-color: var(--accent); }
.shopitem { display: grid; grid-template-columns: 30px 1fr auto auto; gap: 8px; align-items: center; padding: 4px; border-bottom: 1px solid #2e2448; }

#toast { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); background: var(--panel); border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px #000; padding: 14px 22px; font-size: clamp(12px, 1.6vmin, 18px); text-align: center; line-height: 1.7; }

/* 天賦樹 */
#treewrap { position: relative; height: calc(100% - 64px); min-height: 300px; background: radial-gradient(circle at 50% 50%, #1e1636 0%, #0c0816 70%); border: 2px solid var(--line); overflow: hidden; }
#treesvg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
#treesvg:active { cursor: grabbing; }
#treesvg line.eoff { stroke: #3a3056; stroke-width: 4; }
#treesvg line.eon { stroke: #ffd24a; stroke-width: 6; }
#treesvg .node { stroke-width: 3; cursor: pointer; }
#treesvg .node.nlock { fill: #1a1428; stroke: #4a3e68; }
#treesvg .node.navail { fill: #221a36; stroke: var(--c); stroke-opacity: 0.6; }
#treesvg .node.ncan { fill: #2a2040; stroke: var(--c); stroke-width: 4; animation: nodepulse 1.2s infinite; }
#treesvg .node.nalloc { fill: var(--c); stroke: #fff6c8; stroke-width: 4; }
#treesvg .kring { fill: none; stroke-width: 3; stroke-dasharray: 6 5; opacity: 0.45; pointer-events: none; }
#treesvg .kring.nalloc { opacity: 1; stroke-dasharray: none; }
#treesvg .nlabel { fill: #a89cc8; font-size: 15px; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: #0c0816; stroke-width: 4px; }
#treesvg .nlabel.on { fill: #ffe89a; }
#treesvg .brlabel { font-size: 30px; font-weight: bold; text-anchor: middle; letter-spacing: 6px; opacity: 0.8; pointer-events: none; }
@keyframes nodepulse { 50% { stroke: #ffffff; } }
#treetip { position: absolute; width: 220px; background: rgba(12, 8, 22, 0.95); border: 2px solid var(--line2); padding: 6px 8px; pointer-events: none; font-size: 0.92em; line-height: 1.45; z-index: 5; }
.tt-title { font-weight: bold; font-size: 1.08em; }

/* 轉生結算 */
#rebirth { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 42%; background: var(--panel); border: 3px solid #ff9a2a;
  box-shadow: 0 0 0 3px #000, 0 0 40px rgba(255, 120, 40, 0.35); padding: 16px 24px; text-align: center; font-size: clamp(12px, 1.6vmin, 18px); line-height: 1.8; z-index: 10; }
#rebirth h2 { margin: 0 0 6px; color: #ff9a2a; letter-spacing: 6px; text-shadow: 2px 2px 0 #000; }
#rebirth .big { font-size: 2em; color: var(--gold); font-weight: bold; text-shadow: 2px 2px 0 #000; }
#rebirth .row { justify-content: center; margin-top: 10px; }

/* 登入 */
#authbox { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20;
  background: radial-gradient(circle at 50% 40%, rgba(40, 24, 70, 0.92), rgba(8, 5, 14, 0.97)); font-size: clamp(12px, 1.7vmin, 18px); }
.authcard { width: min(92%, 26em); background: var(--panel); border: 3px solid var(--line2); box-shadow: 0 0 0 3px #000, 6px 6px 0 rgba(0,0,0,0.6); padding: 18px 22px; display: flex; flex-direction: column; gap: 10px; }
.authcard h1 { margin: 0; font-size: 1.6em; color: var(--gold); letter-spacing: 4px; text-shadow: 2px 2px 0 #000; text-align: center; }
.authcard label { display: flex; flex-direction: column; gap: 3px; color: var(--dim); }
.authcard input { font: inherit; color: var(--text); background: #0e0a18; border: 2px solid var(--line); padding: 5px 8px; outline: none; }
.authcard input:focus { border-color: var(--accent); }
.authcard .row { justify-content: center; }
#amsg { min-height: 1.2em; text-align: center; }

/* ---------- 裝備紙娃娃 ---------- */
.doll-box { background: linear-gradient(180deg, #1a1330 0%, #120d1e 100%); }
.doll { display: grid; grid-template-columns: 1fr 9.5em 1fr; gap: 10px; align-items: stretch; }
.dcol { display: flex; flex-direction: column; gap: 8px; }
.eslot { display: flex; gap: 8px; align-items: center; padding: 6px; background: #0e0a18; border: 2px solid var(--rc, #3a3050); cursor: pointer; position: relative; min-height: 58px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.6); transition: transform 0.08s, filter 0.08s; }
.eslot:hover { transform: translateY(-1px); filter: brightness(1.2); }
.eslot.empty { border-style: dashed; border-color: #3a3050; cursor: default; }
.eslot.empty:hover { transform: none; filter: none; }
.eicon { position: relative; width: 44px; height: 44px; flex: 0 0 44px; display: flex; align-items: center; justify-content: center; font-size: 1.4em;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--rc, #555) 45%, #1a1428) 0%, #0b0814 80%); border: 1px solid rgba(255,255,255,0.08); }
.eicon img { width: 34px; height: 34px; object-fit: contain; image-rendering: pixelated; }
.eicon .ghost { opacity: 0.25; filter: grayscale(1); }
.eenh { position: absolute; right: -4px; top: -6px; font-size: 0.72em; background: #2a1c06; color: var(--gold); border: 1px solid #b08a20; padding: 0 3px; }
.estar { position: absolute; left: -4px; top: -7px; color: #ff9a2a; text-shadow: 0 0 4px #ff6a00; font-size: 0.9em; }
.etext { min-width: 0; line-height: 1.25; }
.elabel { font-size: 0.75em; color: var(--dim); }
.ename { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 1px 1px 0 #000; }
.estat { font-size: 0.8em; color: #e8e0ff; }
.eslot.r2 { box-shadow: 0 0 8px rgba(79,184,255,0.35), inset 0 0 0 1px rgba(0,0,0,0.6); }
.eslot.r3 { box-shadow: 0 0 10px rgba(208,112,255,0.45), inset 0 0 0 1px rgba(0,0,0,0.6); }
.eslot.r4 { box-shadow: 0 0 12px rgba(255,154,42,0.6), inset 0 0 0 1px rgba(0,0,0,0.6); animation: legendglow 1.8s infinite; }
@keyframes legendglow { 50% { box-shadow: 0 0 20px rgba(255,154,42,0.9), inset 0 0 0 1px rgba(0,0,0,0.6); } }
.dcenter { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: radial-gradient(ellipse at 50% 70%, rgba(159,240,255,0.14) 0%, rgba(0,0,0,0) 65%); border: 1px solid #2e2448; }
.dfig { width: 100%; display: flex; justify-content: center; position: relative; }
.dfig::after { content: ''; position: absolute; bottom: 4px; width: 60%; height: 8px; background: radial-gradient(ellipse, rgba(0,0,0,0.55), transparent 70%); }
.dfig img { width: 180px; height: 220px; image-rendering: pixelated; position: relative; z-index: 1; margin-top: -20px; }
.dname { font-weight: bold; letter-spacing: 2px; }
.dscore { font-size: 0.85em; color: var(--dim); } .dscore b { color: var(--accent); }
.gearsum { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; margin-top: 8px; padding-top: 6px; border-top: 1px dashed #2e2448; font-size: 0.9em; color: var(--dim); }
.gearsum b { color: #fff; }

/* 背包格：稀有度底色 */
.cell { border-color: var(--rc, #444); background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--rc, #444) 28%, #120d1e) 0%, #0b0814 85%); }
.cell.r3 { box-shadow: 0 0 6px rgba(208,112,255,0.5); }
.cell.r4 { box-shadow: 0 0 8px rgba(255,154,42,0.7); }

/* 物品懸浮說明 */
#itemtip { position: absolute; z-index: 30; width: 250px; background: rgba(12, 8, 22, 0.97); border: 2px solid var(--line2); box-shadow: 0 0 0 2px #000; padding: 8px 10px;
  pointer-events: none; font-size: clamp(11px, 1.35vmin, 15px); line-height: 1.45; }

/* ---------- 技能系統 ---------- */
.schools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 8px; }
.school { position: relative; padding: 6px 8px; background: #120d1e; border: 2px solid #2e2448; border-top: 3px solid var(--c); cursor: pointer; }
.school:hover { filter: brightness(1.25); }
.school.on { background: color-mix(in srgb, var(--c) 18%, #120d1e); border-color: var(--c); }
.sname { font-weight: bold; color: var(--c); display: flex; align-items: center; gap: 4px; }
.major { font-size: 0.7em; background: var(--gold); color: #2a1800; padding: 0 4px; font-weight: bold; }
.updot { width: 7px; height: 7px; background: #ffd24a; border-radius: 50%; box-shadow: 0 0 6px #ffd24a; margin-left: auto; }
.sbar { height: 5px; background: #0b0814; border: 1px solid #2e2448; margin: 4px 0 2px; }
.sbar i { display: block; height: 100%; background: var(--c); }
.slv { font-size: 0.75em; color: var(--dim); }
.schoolinfo { padding: 8px 10px; margin-bottom: 6px; background: #120d1e; border-left: 4px solid var(--c); line-height: 1.6; }

/* ---------- 世界地圖 ---------- */
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(19em, 1fr)); gap: 10px; }
.mapcard { background: linear-gradient(180deg, #1c1532, #120d1e); border: 2px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.mapcard.here { border-color: var(--gold); box-shadow: 0 0 10px rgba(255, 210, 74, 0.35); }
.mapcard.locked { opacity: 0.55; filter: grayscale(0.6); }
.mhead { display: flex; align-items: center; gap: 6px; }
.mname { font-weight: bold; font-size: 1.12em; color: var(--accent); letter-spacing: 1px; }
.mdesc { font-size: 0.85em; }
.mrow { display: flex; flex-wrap: wrap; gap: 4px; }
.mrow .tag { margin-left: 0; }
.mmobs { font-size: 0.85em; color: #e0d8f8; }
.mboss { background: rgba(80, 16, 24, 0.35); border-left: 3px solid #ff5050; padding: 3px 6px; }
.mfoot { margin-top: auto; justify-content: flex-end; }

/* ---------- 大地圖 ---------- */
.wmtop { margin-bottom: 6px; font-size: 0.92em; }
.wmwrap { display: flex; gap: 10px; align-items: flex-start; }
.wmap { position: relative; flex: 0 0 auto; aspect-ratio: 723 / 530; margin: 0; border: 3px solid #6a5030; box-shadow: 0 0 0 2px #000, 0 6px 18px rgba(0,0,0,0.6); overflow: hidden; }
.wmap img { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
.wmsvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.wmr { stroke: rgba(40, 30, 20, 0.55); stroke-width: 3; stroke-dasharray: 6 6; }
.wmr.on { stroke: #ffd24a; stroke-width: 4; stroke-dasharray: 8 5; filter: drop-shadow(0 0 2px #000); animation: wmflow 1.2s linear infinite; }
@keyframes wmflow { to { stroke-dashoffset: -26; } }
.wmnode { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; cursor: pointer; z-index: 2; }
.wmnode .dot { width: 1.6em; height: 1.6em; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85em;
  background: radial-gradient(circle at 40% 35%, #fff6c0, #e8a820 60%, #8a5a10); color: #2a1800; border: 2px solid #2a1800; box-shadow: 0 0 0 2px #fff4c0, 0 2px 4px rgba(0,0,0,0.6); }
.wmnode .nlab { display: none; position: absolute; top: 1.9em; margin-top: 2px; font-size: 0.78em; font-weight: bold; color: #fff; white-space: nowrap; padding: 0 5px; background: rgba(20, 12, 34, 0.85); border: 1px solid #6a5aa0; text-shadow: 1px 1px 0 #000; }
.wmnode:hover .dot { transform: scale(1.2); }
.wmnode.locked .dot { background: radial-gradient(circle, #8a8a98, #50505e); color: #fff; box-shadow: 0 0 0 2px #333; font-size: 0.7em; }
.wmnode.locked .nlab { color: #a8a0c0; border-color: #3a3050; }
.wmnode.clear .dot { background: radial-gradient(circle at 40% 35%, #e8fff0, #40c870 60%, #10602a); }
.wmnode.sel .dot { box-shadow: 0 0 0 3px #9ff0ff, 0 0 12px #9ff0ff; }
.wmnode.sel .nlab { border-color: #9ff0ff; }
.wmnode.here .dot { animation: wmpulse 1.1s infinite; }
@keyframes wmpulse { 50% { box-shadow: 0 0 0 5px rgba(255, 90, 90, 0.9), 0 0 16px #ff5050; } }
.wmnode .you { position: absolute; top: -1.35em; color: #ff5050; font-size: 0.9em; text-shadow: 0 0 3px #000, 1px 1px 0 #000; animation: wmbob 0.8s infinite alternate; }
@keyframes wmbob { to { transform: translateY(-3px); } }
.wmnode.town .dot { width: 1.3em; height: 1.3em; background: radial-gradient(circle at 40% 35%, #e0f0ff, #4fa8ff 60%, #1c3fa8); border-radius: 3px; }
.wmside { width: 19em; flex: 0 0 19em; }
.wmnode:hover .nlab, .wmnode.sel .nlab, .wmnode.here .nlab { display: block; }
.wmnode:hover, .wmnode.sel { z-index: 5; }
.wmwrap { justify-content: center; }
