:root {
  --bg: #03040a; --panel: rgba(10, 16, 32, .82); --panel2: rgba(18, 28, 54, .78); --line: rgba(110, 160, 255, .22);
  --text: #dbe6ff; --dim: #8fa3c8; --accent: #66ccff; --good: #5be3a0; --bad: #ff6b7d; --warn: #ffd166;
  --ti: #b9c3d6; --qc: #7be0ff; --he3: #ffb86b; --am: #d98cff;
  --font: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overflow: hidden; }
#gl { position: fixed; inset: 0; width: 100%; height: 100vh; height: 100dvh; display: block; }
#app { position: fixed; inset: 0; height: 100vh; height: 100dvh; pointer-events: none; display: flex; flex-direction: column; }
#app > * { pointer-events: auto; }
#app > .body { pointer-events: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.dim { color: var(--dim); } .good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; }

/* ---- 頂欄 ---- */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: linear-gradient(180deg, rgba(5, 9, 20, .95), rgba(5, 9, 20, .7)); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); flex-wrap: wrap; }
.logo { font-weight: 800; letter-spacing: .12em; color: var(--accent); white-space: nowrap; }
.logo small { color: var(--dim); font-weight: 400; letter-spacing: .05em; margin-left: 6px; }
.res { display: flex; gap: 14px; flex-wrap: wrap; flex: 1; }
.res .r { display: flex; flex-direction: column; min-width: 92px; }
.res .r b { font-size: 15px; } .res .r span { font-size: 11px; color: var(--dim); }
.res .r .bar { height: 3px; background: rgba(255, 255, 255, .1); border-radius: 2px; margin-top: 2px; overflow: hidden; } .res .r .bar i { display: block; height: 100%; }
.sel { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.user { display: flex; gap: 8px; align-items: center; }
.pill { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; background: rgba(255, 255, 255, .04); }

/* ---- 主體 ---- */
.body { display: flex; flex: 1; min-height: 0; pointer-events: none; position: relative; }
.body > .nav { pointer-events: auto; }
.main { pointer-events: none; }
.main > * { pointer-events: auto; }
.nav { width: 132px; padding: 10px 6px; display: flex; flex-direction: column; gap: 4px; background: rgba(5, 9, 20, .72); border-right: 1px solid var(--line); overflow-y: auto; }
.nav button { text-align: left; background: none; border: 1px solid transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--dim); display: flex; justify-content: space-between; align-items: center; }
.nav button:hover { background: rgba(255, 255, 255, .05); color: var(--text); }
.nav button.on { background: rgba(102, 204, 255, .12); border-color: var(--accent); color: #fff; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; }
.main { flex: 1; min-width: 0; overflow-y: auto; padding: 14px 18px 60px; }
.main.map { padding: 0; overflow: visible; }
.wrap { max-width: 1100px; margin: 0 auto; }
.main.ov .wrap { max-width: 640px; margin: 0; }
h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: .06em; } h3 { margin: 16px 0 8px; font-size: 14px; color: var(--accent); letter-spacing: .08em; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; backdrop-filter: blur(8px); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.item { display: flex; flex-direction: column; gap: 6px; position: relative; }
.item-art { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 6px; background: rgba(0, 0, 0, .25); }
.item-art-compact { width: min(100%, 100px); }
.item-art-fallback { display: grid; place-items: center; background: radial-gradient(circle, #22344b, #101823 70%); }
.item-art-fallback::after { content: '✦'; color: #718ba5; font-size: clamp(24px, 5vw, 48px); }
.item .hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.item .hd b { font-size: 15px; } .item .lv { color: var(--accent); font-weight: 700; }
.item p { margin: 0; color: var(--dim); font-size: 12.5px; line-height: 1.5; }
.item.fac { border-color: color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: inset 0 0 22px rgba(102, 204, 255, .08); }
.item.locked { opacity: .62; }
.cost { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.cost span { padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, .06); }
.cost .lack { color: var(--bad); background: rgba(255, 107, 125, .12); }
.t-ti { color: var(--ti); } .t-qc { color: var(--qc); } .t-he3 { color: var(--he3); } .t-am { color: var(--am); }
.btn { background: linear-gradient(180deg, rgba(102, 204, 255, .25), rgba(102, 204, 255, .1)); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 12px; cursor: pointer; color: #fff; }
.btn:hover { background: rgba(102, 204, 255, .35); } .btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.sec { background: rgba(255, 255, 255, .05); border-color: var(--line); } .btn.danger { border-color: var(--bad); background: rgba(255, 107, 125, .15); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input[type=text], input[type=password], input[type=number], select, textarea { background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
input[type=number] { width: 90px; }
.bar { height: 6px; background: rgba(255, 255, 255, .1); border-radius: 3px; overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--accent); }
.q { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.q:last-child { border: 0; } .q .bar { flex: 1; }
table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 13px; } th { color: var(--dim); font-weight: 500; }
.alert { background: rgba(255, 70, 90, .18); border: 1px solid var(--bad); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; } .tabs button { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; cursor: pointer; color: var(--dim); } .tabs button.on { color: #fff; border-color: var(--accent); background: rgba(102, 204, 255, .15); }

/* ---- 星圖側欄 ---- */
.side { position: absolute; right: 14px; top: 12px; bottom: 44px; width: 340px; overflow-y: auto; }
.legend { position: absolute; left: 146px; bottom: 40px; font-size: 12px; color: var(--dim); display: flex; gap: 12px; flex-wrap: wrap; pointer-events: none; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.maptools { position: absolute; left: 146px; top: 12px; display: flex; gap: 6px; }
.tip { position: fixed; z-index: 30; pointer-events: none; background: rgba(5, 9, 20, .95); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 10px; font-size: 12px; max-width: 260px; }

/* ---- 底部事件列 ---- */
.ticker { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(4, 7, 16, .92); border-top: 1px solid var(--line); padding: 5px 14px; font-size: 12px; display: flex; gap: 18px; overflow: hidden; white-space: nowrap; z-index: 10; pointer-events: auto; }
.ticker .fx { color: var(--warn); }

/* ---- 登入 ---- */
.login { position: absolute; inset: 0; display: flex; padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; background: radial-gradient(ellipse at 30% 20%, rgba(40, 70, 140, .28), transparent 60%); }
.login .box { width: min(940px, 100%); margin: auto; }
.login h1 { font-size: 40px; letter-spacing: .3em; margin: 0; text-align: center; color: #fff; text-shadow: 0 0 24px var(--accent); }
.login .sub { text-align: center; color: var(--dim); margin: 6px 0 18px; letter-spacing: .12em; }
.facs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0; }
.fac-card { cursor: pointer; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--panel); transition: .15s; position: relative; }
.fac-card:hover { transform: translateY(-2px); } .fac-card.on { border-color: var(--fc); box-shadow: 0 0 0 1px var(--fc), 0 0 22px color-mix(in srgb, var(--fc) 40%, transparent); }
.fac-card h4 { margin: 0 0 2px; color: var(--fc); } .fac-card p { margin: 4px 0; font-size: 12px; color: var(--dim); } .fac-card ul { margin: 6px 0 0; padding-left: 16px; font-size: 12px; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; margin-top: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); animation: in .2s; }
.toast.err { border-left-color: var(--bad); } @keyframes in { from { transform: translateX(20px); opacity: 0; } }
#toast-box { position: fixed; right: 14px; top: 70px; z-index: 50; width: 300px; pointer-events: none; }
.msg { cursor: pointer; } .msg.unread b { color: #fff; } .msg .det { margin-top: 8px; font-size: 13px; }
.chatbox { height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 8px; background: rgba(0, 0, 0, .25); border-radius: 8px; }
.chatbox .c b { margin-right: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; } .kv > :nth-child(odd) { color: var(--dim); }
.planet-info { display: grid; gap: 4px; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line); margin-left: 4px; color: var(--dim); }
.tag.npc { color: var(--warn); border-color: rgba(255, 209, 102, .4); }
@media (max-width: 860px) {
  .top { gap: 6px 10px; padding: 6px 10px; }
  .logo { font-size: 12px; } .logo small { display: none; }
  .res { order: 3; flex: 1 0 100%; flex-wrap: nowrap; gap: 8px; overflow-x: auto; }
  .res .r { min-width: 64px; }
  .user { margin-left: auto; }
  .nav { width: 72px; flex: 0 0 72px; }
  .nav button { padding: 8px 4px; font-size: 12px; }
  .side { width: auto; left: 84px; top: auto; bottom: 40px; height: 42vh; } .legend, .maptools { left: 84px; }
  .main { padding: 12px 10px 60px; }
  .main.ov .wrap { max-width: none; }
}

/* ---- 旗艦庫 ---- */
.main.hg .wrap { max-width: 760px; margin: 0; }
.fcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin-top: 10px; }
.fcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; backdrop-filter: blur(8px); }
.fcard:hover { border-color: var(--accent); } .fcard.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(102, 204, 255, .25); } .fcard.add { border-style: dashed; opacity: .85; }
.statgrid { display: grid; grid-template-columns: repeat(4, auto 1fr); gap: 4px 10px; margin-top: 10px; font-size: 13px; } .statgrid span { color: var(--dim); } .statgrid b { font-variant-numeric: tabular-nums; }
.ability { margin-top: 8px; padding: 6px 10px; border-left: 3px solid var(--warn); background: rgba(255, 209, 102, .08); border-radius: 4px; font-size: 13px; }
.slot { background: rgba(0, 0, 0, .28); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.slot select { width: 100%; margin-top: 4px; }
.slot.W { border-left: 3px solid #ffd166; } .slot.D { border-left: 3px solid #6fe3a0; } .slot.E { border-left: 3px solid #66b8ff; } .slot.C { border-left: 3px solid #7be0ff; } .slot.U { border-left: 3px solid #ffa14a; }
.branches { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.node { background: rgba(0, 0, 0, .28); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.node.on { border-color: var(--accent); background: rgba(102, 204, 255, .08); } .node .lv { color: var(--accent); font-weight: 700; }
@media (max-width: 860px) { .statgrid { grid-template-columns: repeat(2, auto 1fr); } .main.hg .wrap { max-width: none; } }

/* ---- 手機版 ---- */
@media (max-width: 860px) {
  html, body { font-size: 15px; }
  input[type=text], input[type=password], input[type=number], select, textarea { font-size: 16px; min-height: 38px; }
  .btn { min-height: 36px; } .btn.sm { min-height: 30px; padding: 4px 10px; }
  .top { padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .user { flex-wrap: wrap; gap: 4px 6px; font-size: 12px; }
  .body { flex-direction: column-reverse; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
  .nav { width: 100%; flex: 0 0 auto; flex-direction: row; gap: 2px; padding: 4px 6px; overflow-x: auto; overflow-y: hidden; border-right: 0; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
  .nav button { flex: 0 0 auto; white-space: nowrap; gap: 6px; padding: 9px 12px; font-size: 13px; }
  .main { padding: 10px 10px 16px; }
  .side { left: 8px; right: 8px; top: auto; bottom: calc(96px + env(safe-area-inset-bottom)); width: auto; height: auto; max-height: 34vh; max-height: 34dvh; }
  .legend { display: none; }
  .maptools { left: 8px; top: 8px; right: 8px; flex-wrap: wrap; }
  #toast-box { left: 10px; right: 10px; width: auto; top: 60px; }
  .ticker { padding: 5px 10px calc(5px + env(safe-area-inset-bottom)); }
  .card table, .wrap table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .chatbox { height: 46vh; height: 46dvh; }
  .tabs button { padding: 6px 12px; }
  .row > input[type=text], .row > input[type=password], .row > select { flex: 1 1 140px; min-width: 0; }
  .q { flex-wrap: wrap; }
  .kv { grid-template-columns: auto minmax(0, 1fr); }
  .fcards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .branches { grid-template-columns: 1fr; }
  h2 { font-size: 17px; }
}
@media (max-width: 520px) {
  .login { padding: 12px 10px calc(24px + env(safe-area-inset-bottom)); }
  .login h1 { font-size: 28px; letter-spacing: .14em; }
  .login .sub { margin-bottom: 12px; letter-spacing: .06em; }
  #authf > input, #authf > .btn { flex: 1 1 100%; }
  .facs { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .statgrid { grid-template-columns: auto 1fr; }
  .card { padding: 10px 11px; }
  .res .r b { font-size: 14px; }
}
