/* =====================================================================
   像素礦工 Idle — 介面樣式
   設計原則：一套色票、一套間距、一套元件（卡片、按鈕、標籤、格子、選擇器），
   每個抽屜都由「卡片」組成，次要說明用淡色小字，不擠在一起。
   ===================================================================== */
:root {
  /* 色票 */
  --bg: #0b0910;
  --panel: #191422;      /* 抽屜、對話框底色 */
  --panel2: #221b2e;     /* 卡片 */
  --well: #120e19;       /* 凹下去的區域（格子、輸入框） */
  --edge: #3a3149;       /* 內框線 */
  --edge2: #54476d;      /* 滑過、強調框線 */
  --text: #ece6f5;
  --dim: #a59cb8;
  --mute: #6f6782;
  --accent: #f2c230;     /* 主色：標題、重點數字 */
  --cyan: #7df9ff;
  --good: #7fe07f;
  --bad: #ff8080;
  --warn: #ff9f43;
  --btn: #3b3150;
  --btn-hi: #4a3e64;
  --primary: #2c6a46;
  --primary-hi: #30764e;   /* 滑過：字色對比仍 ≥ 4.5 */
  /* 尺寸 */
  --gap: 8px;
  --gap-l: 12px;
  /* 字級只有三級：標題、內文（含按鈕）、輔助小字 */
  --fs-title: 15px;
  --fs: 14px;
  --fs-s: 12px;
  --fs-xs: 12px;
  --drawer: 400px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: var(--fs);
  overflow: hidden;
}
#app { position: relative; height: 100vh; }
#view { position: absolute; inset: 0; }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

/* ---------- 基本元件 ---------- */
.panel {
  background: rgba(20, 16, 28, 0.88);
  border: 3px solid #000;
  box-shadow: inset 0 0 0 2px var(--edge);
  padding: 6px 10px;
  font-size: var(--fs);
}
.gold { color: var(--accent); font-weight: bold; }
.dim { color: var(--dim); }
.ok { color: var(--good); }
.bad { color: var(--bad); }
.hot { color: var(--accent); }
small { font-size: var(--fs-s); }

button {
  font-family: inherit; font-size: var(--fs); color: var(--text);
  background: var(--btn); border: 2px solid #000;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.1);
  padding: 6px 10px; cursor: pointer; line-height: 1.2;
}
button:hover:not(:disabled) { background: var(--btn-hi); color: var(--text); }
button:active:not(:disabled) { box-shadow: inset 0 3px 0 rgba(0,0,0,.35); }
button:disabled { opacity: .5; filter: grayscale(1); cursor: default; }   /* 不能按：去色，和綠色主要按鈕分得開 */
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary, .tabs button.on { background: var(--primary); }
button.primary:hover:not(:disabled) { background: var(--primary-hi); }
button.sm, .sm button { font-size: var(--fs-s); padding: 3px 8px; }
button.ghost, .link { background: none; border: 0; box-shadow: none; color: var(--dim); }
.link { font-size: var(--fs-s); text-decoration: underline; }

input, select {
  font-family: inherit; font-size: var(--fs); color: var(--text);
  background: var(--well); border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge);
  padding: 4px 6px;
}
input[type=number] { width: 80px; }
input[type=checkbox] { accent-color: var(--accent); vertical-align: -2px; }
label { cursor: pointer; }

/* 開關／分段選擇：取代下拉選單 */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button { font-size: var(--fs-s); padding: 4px 9px; }
.seg button.on { background: var(--primary); box-shadow: inset 0 0 0 2px var(--good); }
.chip { padding: 3px 9px; font-size: var(--fs-s); }
.chip.on { background: var(--primary); }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs); color: var(--dim); }
.toggle.on { color: var(--text); }

.bar { height: 10px; background: #0e0b14; border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge); margin: 4px 0; }
.bar > div, .bar > span { display: block; height: 100%; width: 0; background: var(--good); transition: width .15s; }
#xpbar { background: var(--cyan); }

.hint { font-size: var(--fs-s); color: var(--dim); margin: 0 0 var(--gap); line-height: 1.55; }
.empty { grid-column: 1 / -1; color: var(--dim); font-size: var(--fs-s); padding: 10px 0; text-align: center; }
.row { display: flex; align-items: center; gap: var(--gap); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: var(--gap); font-size: var(--fs); }

/* 卡片：抽屜裡的每一塊內容 */
.card, .project-box, .mine-prefs, .drawer-details, .mine-card, .contract, .plan-goal {
  background: var(--panel2);
  border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge);
  padding: 10px 12px; margin-top: var(--gap);
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-weight: bold; color: var(--accent); font-size: var(--fs-title); }
.card-h small { color: var(--dim); font-weight: normal; }

/* 可展開的卡片 */
.drawer-details { padding: 0 12px; }
.drawer-details > summary {
  cursor: pointer; list-style: none; padding: 9px 0; color: var(--accent); font-size: var(--fs-title); font-weight: bold;
  display: flex; align-items: center; gap: 6px;
}
.drawer-details > summary::-webkit-details-marker { display: none; }
.drawer-details > summary::after { content: '▸'; margin-left: auto; color: var(--dim); transition: transform .15s; }
.drawer-details[open] > summary::after { transform: rotate(90deg); }
.drawer-details[open] { padding-bottom: 10px; }
.drawer-details .mine-prefs, .drawer-details .card { border: 0; box-shadow: none; padding: 0; margin: 0; background: none; }

/* ---------- 格子（物品、裝備、藥水欄）---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 5px; }
.slot {
  position: relative; aspect-ratio: 1;
  background: var(--well); border: 2px solid #4a4058;
  display: flex; align-items: center; justify-content: center;
}
.slot img { width: 76%; height: 76%; image-rendering: pixelated; }
.slot .cnt, .slot .q {
  position: absolute; font-size: var(--fs-xs); font-weight: bold;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}
.slot .cnt { right: 3px; bottom: 1px; }
.slot .q { left: 3px; top: 1px; font-size: var(--fs-s); }
.slot.blank { border-color: #2c2537; background: #110d17; }
.slot.over { opacity: .55; border-style: dashed; }
.slot.pickable { cursor: pointer; }
.slot.pickable:hover { border-color: var(--accent); }
.slot.add::after { content: '+'; color: var(--mute); font-size: 20px; }

/* ---------- 選擇器（點格子跳出你有的東西）---------- */
.picker {
  position: fixed; z-index: 40; width: 300px; max-height: min(420px, 70vh); overflow-y: auto;
  background: var(--panel); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge2), 0 8px 0 rgba(0,0,0,.4);
  padding: 10px;
}
.picker-h { display: flex; justify-content: space-between; align-items: center; color: var(--accent); font-weight: bold; margin-bottom: 8px; }
.picker-list { display: flex; flex-direction: column; gap: 4px; }
.picker-opt {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; text-align: left;
  background: var(--well); padding: 5px 8px;
}
.picker-opt img { width: 30px; height: 30px; image-rendering: pixelated; }
.picker-opt b { display: block; font-size: var(--fs); }
.picker-opt small { color: var(--dim); }
.picker-opt .n { color: var(--accent); font-weight: bold; font-size: var(--fs); }
.picker-opt.on { box-shadow: inset 0 0 0 2px var(--accent); }
.picker-opt.off { opacity: .5; }
.picker-sec { color: var(--mute); font-size: var(--fs-xs); margin: 8px 0 2px; }
.picker-none { color: var(--dim); font-size: var(--fs-s); padding: 8px 0; text-align: center; }

/* ---------- HUD 與下方按鈕列 ---------- */
#hud {
  position: absolute; left: 10px; top: 10px;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none; min-width: 220px;
}
#hud .row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 2px; }
#hud .sub { font-size: var(--fs-s); color: var(--dim); margin-top: 3px; line-height: 1.5; }
.hud-status, #status { color: #c9f2ff; }
.hud-status, .hud-hazard { pointer-events: auto; }
.hud-hazard.bad { color: #ff9f8a; }
.hud-hazard.ok { color: var(--good); }
#mineshape { color: var(--dim); }
.panel.warn { color: var(--warn); font-weight: bold; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.panel.surge { color: #ffd84a; font-weight: bold; }
#quake { pointer-events: auto; }
#quake button { margin-left: 6px; font-size: var(--fs-s); padding: 3px 8px; animation: none; }
.panel.buffs { display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-s); }
.panel.buffs[hidden] { display: none; }
.buff { display: flex; align-items: center; gap: 5px; }
.buff img { width: 16px; height: 16px; image-rendering: pixelated; }
.buff small { color: var(--accent); margin-left: auto; padding-left: 10px; }

#log {
  position: absolute; left: 10px; bottom: 84px;
  display: flex; flex-direction: column; gap: 3px;
  pointer-events: none; font-size: 14px; font-weight: bold;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}
.logline { transition: opacity 1s; }
.logline.fade { opacity: 0; }
#hint { position: absolute; right: 10px; bottom: 84px; font-size: var(--fs-s); color: var(--dim); pointer-events: none; }
#conn {
  position: absolute; right: 10px; top: 10px;
  font-size: var(--fs-s); padding: 3px 8px; border: 2px solid #000;
  background: rgba(20, 16, 28, 0.85); pointer-events: none;
}
#conn.ok { color: var(--good); }
#conn.bad { color: var(--bad); }

#dock {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 6px; padding: 6px;
  background: rgba(20, 16, 28, 0.92); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge);
}
#dock button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 60px; padding: 6px 8px; font-size: var(--fs-s); }
#dock button .ui-icon { width: 24px; height: 24px; }
#dock button.on { background: #5a4a20; box-shadow: inset 0 0 0 2px var(--accent); }
#dock button small { position: absolute; right: 3px; top: 1px; font-size: var(--fs-s); color: var(--accent); text-shadow: 1px 1px 0 #000; }
.tip-hint { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 7; max-width: min(520px, calc(100% - 32px));
  font-size: 14px; color: #fff2a0; cursor: pointer; animation: hintIn .3s ease-out; }
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 側邊抽屜 ---------- */
#side {
  position: absolute; right: 10px; top: 10px; bottom: 84px; width: var(--drawer); z-index: 5;
  background: var(--panel);
  border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge), 0 6px 0 rgba(0,0,0,.35);
  overflow-y: auto; padding: 12px 14px 16px;
}
#side[hidden] { display: none; }
#side section { display: none; margin: 0; border: 0; box-shadow: none; background: none; padding: 0; }
#side section.on { display: block; }
.side-close { position: sticky; top: 0; float: right; z-index: 2; margin: -4px -6px 0 0; }
.side-tabs { margin: 0 36px var(--gap-l) 0; display: flex; gap: 4px; }
.side-tabs[hidden] { display: none; }
.side-tabs button { flex: 1; padding: 7px 4px; font-size: var(--fs); }
.side-tabs button.on { background: #5a4a20; box-shadow: inset 0 0 0 2px var(--accent); }
h3 {
  margin: 0 0 var(--gap); font-size: var(--fs-title); color: var(--accent);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
h3 span { font-size: var(--fs-s); color: var(--dim); font-weight: normal; }
.sub-h { margin-top: 18px; }
section { padding: 0; }

@media (max-width: 760px) {
  :root { --drawer: auto; }
  #side { left: 10px; width: auto; top: auto; height: 58vh; }
  #dock button { min-width: 50px; }
}

/* ---------- 對話框 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(5, 3, 10, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal[hidden] { display: none; }
.modal .box {
  width: min(440px, 100%);
  background: var(--panel); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge);
  padding: 16px 18px; display: flex; flex-direction: column; gap: var(--gap-l);
}
.modal .box.wide { width: min(620px, 100%); max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0; color: var(--accent); font-size: 20px; display: flex; justify-content: space-between; align-items: center; }
.modal p { margin: 0; font-size: 14px; line-height: 1.6; }
.modal .err { color: var(--bad); font-size: var(--fs); min-height: 1em; }
.close { padding: 3px 9px; }
.close .ui-icon { width: 12px; height: 12px; vertical-align: -1px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
#loginForm .tabs button { flex: 1; }
#loginForm input { width: 100%; padding: 8px 10px; }
#loginHint:empty { display: none; }
#offlineXp { white-space: pre-line; }
.craft-note { color: #f2a03a; }
.craft-note:empty, #offline p:empty { display: none; }

/* 清單列（商店、配方、市場、交貨…） */
.shop-list { display: flex; flex-direction: column; gap: 6px; }
.shop-item, .recipe, .src-row {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  background: var(--panel2); border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge); padding: 8px 10px;
}
.shop-item > img, .recipe .out { width: 36px; height: 36px; image-rendering: pixelated; }
.shop-item small, .recipe small { color: var(--dim); }
.shop-item .locked { color: var(--bad); }
.shop-item .bad, .recipe .bad { color: var(--bad); }
.recipe.locked { opacity: .55; }
.recipe .ins, .recipe-ins { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--fs-s); margin-top: 4px; align-items: center; }
.recipe .ins span, .recipe-ins span { display: inline-flex; align-items: center; gap: 3px; }
.recipe .ins img, .recipe-ins img { width: 16px; height: 16px; image-rendering: pixelated; }
.recipe .ins .short, .recipe-ins .short { color: var(--bad); }
.recipe-ins small { color: var(--dim); }
.recipe .buy-n { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
.recipe .buy-n button { padding: 4px 8px; font-size: var(--fs-s); white-space: nowrap; }
.buy-n { display: flex; flex-direction: column; gap: 4px; }
.recipe.flash { animation: flash .4s steps(2) 4; }
@keyframes flash { 50% { background: var(--btn-hi); } }

/* ---------- 角色、裝備、外觀 ---------- */
#statline { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs); color: var(--dim); margin-bottom: var(--gap); line-height: 1.5; }
#statline .stat { white-space: nowrap; }
#statline .stat b { color: var(--accent); }
.equip-slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.eslot {
  position: relative; aspect-ratio: 1; padding: 0;
  background: var(--well); border: 2px solid #4a4058;
  display: flex; align-items: center; justify-content: center;
}
.eslot img { width: 70%; height: 70%; image-rendering: pixelated; }
.eslot .lbl { position: absolute; left: 3px; top: 1px; font-size: var(--fs-s); color: var(--dim); }
.eslot.vacant { opacity: .6; }
.look-layout { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
#lookPreview { image-rendering: pixelated; background: var(--well); border: 2px solid #000; width: 240px; height: 120px; }
#lookOptions { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 8px; font-size: var(--fs); }
.opt-row { display: flex; flex-direction: column; gap: 4px; }
.opt-row .choices { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch { width: 24px; height: 24px; padding: 0; border: 2px solid #000; }
.swatch.on, .chip.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.supply-icon { font-size: 26px; text-align: center; }
.loadout-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: var(--fs); }
.loadout-row span { margin-left: auto; display: flex; gap: 4px; }
.loadout-row button, .mod-sel { font-size: var(--fs-s); padding: 3px 8px; }
.mod-sel { max-width: 160px; }
.ach-box { font-size: var(--fs); }
#achList { margin-top: 6px; max-height: 240px; overflow-y: auto; }
.ach { padding: 3px 0; color: var(--dim); }
.ach.done { color: var(--text); }
.ach.done b { color: #ffd84a; }

/* ---------- 藥水欄、便當 ---------- */
.belt { margin-top: var(--gap-l); }
.supply-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.supply-slot { display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; }
.supply-slot .slot { width: 52px; }
.supply-slot .lbl { font-size: var(--fs-xs); color: var(--dim); line-height: 1.3; }
.supply-slot .nm { font-size: var(--fs-s); line-height: 1.3; }
.supply-slot.lunch .slot { border-color: #6a5a2a; }
.offline-use { display: flex; gap: 14px; font-size: var(--fs-s); color: var(--dim); flex-wrap: wrap; margin-top: 10px; }

/* ---------- 縫製工坊 ---------- */
.tiers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.tier { display: flex; gap: 8px; align-items: center; text-align: left; background: var(--well); }
.tier img { width: 32px; height: 32px; image-rendering: pixelated; }
.tier small { color: var(--dim); }
.tier.on { background: var(--primary); }
.sew-alloc { display: flex; flex-direction: column; gap: 8px; background: var(--well); border: 2px solid #000; padding: 10px; }
.sew-alloc .row { display: flex; justify-content: space-between; align-items: center; }
.alloc-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.alloc-row small { color: var(--dim); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper b { min-width: 24px; text-align: center; font-size: 16px; }
.stepper button { padding: 2px 10px; }
.sew-preview { border-top: 1px solid var(--edge); padding-top: 8px; font-size: 14px; }
.sew-preview small { color: var(--dim); }
#sewOwned .row { display: flex; justify-content: space-between; }

/* ---------- 生活技能、工作站 ---------- */
.skill-row { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; margin-bottom: 6px; padding: 8px 10px; }
.skill-row small { color: var(--dim); }
.skill-xp { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 100px; }
.skill-xp .bar { width: 100px; height: 8px; margin: 0; display: block; }
.skill-xp .bar > span { background: var(--cyan); }
.craft-activity { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.craft-activity small { font-size: var(--fs-s); line-height: 1.5; }
.craft-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; flex-basis: 100%; width: 100%; }
.craft-opts span { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.craft-opts small { color: var(--dim); margin-right: 2px; }
.craft-opts button { font-size: var(--fs-s); padding: 3px 8px; }
.craft-opts button { white-space: nowrap; }
.craft-opts .tool-slot img { vertical-align: middle; }
.craft-queue { display: flex; flex-direction: column; gap: 8px; background: var(--well); border: 2px solid #000; padding: 10px; }
.craft-queue .row { display: flex; justify-content: space-between; }
.queue-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; }
.queue-item img { width: 28px; height: 28px; image-rendering: pixelated; }
.queue-item .bar { margin: 4px 0 0; display: block; }
.queue-item .bar > span { background: #f2a03a; transition: width .15s linear; }
.queue-item small { color: var(--dim); }
.build-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; }
.build-head small { color: var(--dim); }

/* ---------- 強化、附魔 ---------- */
.enh-body { display: flex; flex-direction: column; gap: 10px; }
.enh-head { display: flex; gap: 10px; align-items: center; background: var(--well); border: 2px solid #4a4058; padding: 8px; }
.enh-head img { width: 36px; height: 36px; image-rendering: pixelated; }
.enh-head small, .enh-rate small, .enh-cost small { color: var(--dim); }
.enh-rate { font-size: 15px; }
.enh-rate b { font-size: 20px; }
.enh-rate .bad { color: var(--warn); }
.enh-cost { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: var(--fs); }
.enh-cost span, .enh-cost label { display: inline-flex; align-items: center; gap: 3px; }
.enh-cost img { width: 16px; height: 16px; image-rendering: pixelated; }
.enh-cost .short { color: var(--bad); }
.ench-slots { display: flex; flex-direction: column; gap: 4px; background: var(--well); border: 2px solid #000; padding: 8px; font-size: var(--fs); }
.ench-slot.off { opacity: .5; }
.ench-slot small, .ench-opt span { color: var(--dim); }
.stat { color: var(--cyan); }
.mech { color: #ff9ff0; }
.affix { margin-right: 6px; }
.affix.off { opacity: .45; text-decoration: line-through; }
.ench-scrolls { display: flex; flex-direction: column; gap: 4px; }
.scroll-btn { display: flex; gap: 8px; align-items: center; text-align: left; background: var(--well); }
.scroll-btn.on { background: #3a2a5a; outline: 2px solid var(--accent); }
.scroll-btn img { width: 24px; height: 24px; image-rendering: pixelated; }
.scroll-btn small { color: var(--dim); }
.ench-opts { display: flex; flex-direction: column; gap: 6px; }
.ench-opt { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: var(--fs); }
.ench-opt select { max-width: 70%; }

/* ---------- 交易市場 ---------- */
.market-search { display: flex; gap: 6px; }
.market-search input { flex: 1; }
.sell-form { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: var(--fs-s); justify-content: flex-end; }
.sell-form input { width: 72px; }
.sell-form .net { color: var(--accent); width: 100%; text-align: right; }
.buy-n .qty { width: 64px; }
.trade-log { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs); }
#marketModal .shop-item { grid-template-columns: 40px 1fr auto; }
.order-form { margin-top: 10px; }
.order-form select { max-width: 150px; }

/* ---------- 取得方式、懸停資訊 ---------- */
.src-link { cursor: pointer; }
.recipe .ins .src-link:hover, .recipe-ins .src-link:hover { text-decoration: underline; color: var(--accent); }
.slot.src-link:hover { outline: 2px solid var(--accent); }
.src-row { font-size: var(--fs); grid-template-columns: 1fr auto; }
.ui-icon { width: 16px; height: 16px; image-rendering: pixelated; vertical-align: -3px; }
.ui-icon.tiny { width: 11px; height: 11px; vertical-align: -1px; }
.ui-icon.icon-slot { width: 30px; height: 30px; }
.ui-icon.icon-slot.out, .shop-item .ui-icon.icon-slot { width: 36px; height: 36px; }
.tip { position: fixed; z-index: 50; pointer-events: none; max-width: 300px; padding: 9px 11px; background: rgba(20, 16, 30, 0.97);
  border: 2px solid var(--edge2); box-shadow: 0 4px 0 rgba(0,0,0,0.4); font-size: var(--fs-s); line-height: 1.55; }
.tip hr { border: 0; border-top: 1px dashed var(--edge2); margin: 6px 0; }
.tip-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.tip-head img { width: 32px; height: 32px; image-rendering: pixelated; }
.tip-head small { color: var(--dim); }
.tip-row { display: flex; gap: 6px; align-items: flex-start; }
.tip-row .ui-icon { flex: none; margin-top: 1px; }
.tip-row.ok { color: var(--good); }
.tip-row.bad { color: #ff8a8a; }
.tip-row.dim { color: var(--dim); }

/* ---------- 礦區 ---------- */
.mine-card.current { box-shadow: inset 0 0 0 2px var(--accent); }
.mine-card.locked { opacity: 0.55; }
.mine-card small { display: block; line-height: 1.55; }
.mine-card .floors { display: flex; gap: 4px; margin: 8px 0 4px; }
.mine-card .floor { flex: 1; min-height: 34px; padding: 3px 0; font-size: var(--fs-s); display: flex; align-items: center; justify-content: center; gap: 2px; }
.mine-card .floor.on { outline: 2px solid var(--accent); }
.mine-card .mastery { margin-top: 4px; }
.mine-card .mastery .bar { height: 6px; margin: 2px 0 0; }
.mine-card .project-box, .mine-card .mine-prefs { background: var(--well); }
.mine { width: 100%; display: block; text-align: left; margin-bottom: 6px; }
.mine small { color: var(--dim); }
.mine.current { background: #24503a; }
.mine-prefs { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs); }
.mine-prefs .actions { justify-content: flex-start; }
.mine-prefs.helper .bad { color: #ff8a8a; }
.project-box { font-size: var(--fs); }
.project-box .need, .project .need { display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: var(--fs-s); margin: 5px 0; }
.project-box .actions { margin-top: 6px; }
.project { margin: 4px 0; padding: 6px 8px; border: 1px dashed var(--edge2); }
.project .need .ok { color: var(--good); }
.project .need .bad { color: #ff9f8a; }
.project button { width: 100%; font-size: var(--fs-s); padding: 4px; }
.deep-run .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 6px 0; text-align: center; }
.deep-run .stats div { background: var(--panel); padding: 4px; }
.deep-run .stats b { display: block; font-size: 16px; }
.deep-run .stats small { color: var(--dim); font-size: var(--fs-xs); }
.opt-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.opt-line > small { min-width: 56px; color: var(--dim); }

/* ---------- 圖鑑 ---------- */
.collect-group { margin-top: 10px; }
.collect-group .row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.collect-group .ok { color: var(--good); }
.slot.collect.t0 img { filter: brightness(0) opacity(0.5); }
.slot.collect.t0 { border-color: #2a2433; }
.slot.collect.t2 { border-color: #c87a3a; }
.slot.collect.t3 { border-color: #c8d0dc; }
.slot.collect.t4 { border-color: #ffd84a; box-shadow: 0 0 6px rgba(255, 216, 74, 0.5); }

/* ---------- 交貨板 ---------- */
.contract { display: flex; gap: 10px; align-items: center; }
.contract .c-body { flex: 1; min-width: 0; font-size: var(--fs); }
.contract .c-body b { display: block; }
.contract .bar { margin: 5px 0 3px; }
.contract.done { box-shadow: inset 0 0 0 2px var(--accent); }
.contract.claimed { opacity: 0.5; }
.contract .claim { background: #6b5a1c; }
.contract .c-act { display: flex; flex-direction: column; gap: 4px; }
.contract.choose { flex-direction: column; align-items: stretch; }
.c-choice { display: flex; align-items: center; gap: 8px; margin: 4px 0; padding: 6px 8px; background: var(--well); }
.c-choice .c-body { flex: 1; }
.c-higher { display: block; font-size: var(--fs-xs); color: var(--dim); margin-top: 2px; }

/* ---------- 工作計畫、保留量 ---------- */
.plan-goal { border-color: #000; box-shadow: inset 0 0 0 2px #6a5a2a; background: #2a2210; font-size: var(--fs); line-height: 1.55; margin-top: 0; margin-bottom: var(--gap); }
.plan-head { font-size: var(--fs); margin-bottom: 8px; line-height: 1.55; }
.plan-head .bad { color: #ff8a8a; }
.plan-steps { display: flex; flex-direction: column; gap: 4px; }
.plan-step { display: flex; gap: 8px; align-items: center; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--edge); font-size: var(--fs); }
.plan-step .n { width: 18px; color: var(--dim); }
.plan-step .t { flex: 1; min-width: 0; }
.plan-step .bar { height: 4px; margin: 4px 0 0; }
.plan-step.now { border-color: var(--accent); background: rgba(242, 194, 48, 0.08); }
.plan-step.past { opacity: 0.5; }
.plan-step button { padding: 2px 6px; }
.plan-act { justify-content: flex-start; }
.plan-add { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; padding: 10px; border: 2px dashed var(--edge2); font-size: var(--fs); }
.keep-row { display: flex; gap: 8px; align-items: center; margin: 4px 0; font-size: var(--fs); }
.keep-row img { width: 20px; height: 20px; image-rendering: pixelated; }
.keep-row input { width: 80px; margin-left: auto; }

/* ---------- 隊伍、登入 ---------- */
#party .row { display: flex; justify-content: space-between; align-items: center; }
#partyCode { width: 70px; text-transform: uppercase; margin-right: 4px; }
.code { color: var(--accent); letter-spacing: 2px; font-size: 16px; }
.members { list-style: none; padding: 0; margin: 6px 0 8px; font-size: 14px; }
.members li { padding: 3px 0; }
.members small { color: var(--dim); }

/* 捲軸：跟介面同色系 */
* { scrollbar-width: thin; scrollbar-color: var(--edge2) var(--well); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--well); }
::-webkit-scrollbar-thumb { background: var(--edge2); border: 1px solid #000; }

/* 清單列右側的按鈕：橫排、可換行（不要一顆一顆疊高） */
.shop-item .buy-n { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; max-width: 210px; }
.shop-item .buy-n button { padding: 4px 9px; font-size: var(--fs-s); }
.shop-item.equipped { outline: 2px solid var(--accent); outline-offset: -2px; }
.wh-cats { margin-bottom: 8px; }
.ench-opt { flex-direction: column; align-items: flex-start; }

/* 提示框：失敗、沒送出 */
#toasts { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { padding: 8px 14px; font-size: 14px; background: rgba(40, 12, 16, 0.95); color: #ffd0d0; border: 2px solid #000; box-shadow: inset 0 0 0 2px #a83a3a; transition: opacity .5s; max-width: min(520px, 90vw); }
.toast.ok { background: rgba(12, 36, 20, 0.95); color: #d0ffd8; box-shadow: inset 0 0 0 2px #3aa85a; }
.toast.fade { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .panel.warn { animation: none; } .tip-hint { animation: none; } }
button.danger { background: #7a2a2a; }
button.danger:hover:not(:disabled) { background: #943434; }
.modal.confirm { z-index: 70; }
.modal.confirm .actions { justify-content: flex-end; }

/* ---------- 小螢幕 ---------- */
#app { height: 100dvh; }
@media (max-width: 760px) {
  #side { left: 8px; right: 8px; width: auto; top: auto; bottom: 78px; height: 44dvh; max-height: none; padding: 10px 12px; }
  #dock { bottom: max(6px, env(safe-area-inset-bottom)); gap: 4px; padding: 4px; }
  #dock button { min-width: 54px; }
  #hud { left: 6px; top: 6px; min-width: 0; }
  .hud-main { min-width: 180px; padding: 5px 8px; }
  #log, #hint { bottom: 78px; }
  #hint { display: none; }
  .picker { width: min(320px, calc(100vw - 16px)); }
}
/* 橫向、很矮的畫面：窄側欄，不吃掉高度 */
@media (max-height: 500px) and (orientation: landscape) {
  #side { left: auto; right: 8px; top: 8px; bottom: 8px; width: 300px; height: auto; }
  #dock { left: 8px; transform: none; flex-direction: column; bottom: 8px; }
  #dock button span { display: none; }
  #log { bottom: 8px; left: 90px; }
}
/* 觸控：按得到 */
@media (pointer: coarse) {
  button { min-height: 40px; }
  .seg button, button.sm { min-height: 36px; }
  .slot.pickable, .eslot { min-width: 44px; }
}

.sub-tabs { display: flex; margin-bottom: 4px; }
.sub-tabs button { flex: 1; font-size: var(--fs); padding: 6px 4px; }
.dot { display: inline-block; width: 7px; height: 7px; background: var(--accent); vertical-align: 1px; }

.hud-link { pointer-events: auto; cursor: pointer; }
.hud-link:hover { color: var(--text); }
.hud-link.bad, .hud-alert.bad { color: #ff9f8a; }
.hud-alert.warn { color: var(--warn); }
.hud-alert.info { color: var(--cyan); }
#hudAlerts .hud-alert { margin-top: 3px; }

.project-box > small, .card > small { display: block; margin-top: 3px; line-height: 1.55; }

.item-info { width: 280px; }
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: var(--fs); margin: 4px 0 8px; }
.info-grid small { color: var(--dim); }

/* 主次：一般標題用正文色，金色只留給選取與重要數字 */
h3, .card-h, .drawer-details > summary, .picker-h { color: var(--text); }
.card-h { font-size: 15px; }

.eslot.on { box-shadow: inset 0 0 0 2px var(--accent); }
.slot-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--edge); }
.slot-row img { width: 30px; height: 30px; image-rendering: pixelated; }
.slot-row b { display: block; font-size: var(--fs); }
.slot-row small { color: var(--dim); }
.slot-row.using b::after { content: ''; }

.view-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.view-head h3 { margin: 0; font-size: 15px; }
#craftSkillTabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
#craftSkillTabs button { flex: 0 0 auto; padding: 6px 10px; white-space: nowrap; }
#craftView .craft-queue, #craftView .shop-list, #craftView .craft-activity, #craftView #craftInfo { margin-top: 10px; }
#craftView .recipe { grid-template-columns: 36px 1fr; }
#craftView .recipe .buy-n { grid-column: 1 / -1; justify-content: flex-end; }

.cert-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--edge); }
.cert-row small { display: block; line-height: 1.5; }

.hud-alert.goal { color: var(--gold); }

#recenter { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 30; }
#game canvas, #view { touch-action: none; }

.helper-eq { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
.helper-eq > small { min-width: 32px; color: var(--dim); }
.helper-eq .slot { width: 44px; height: 44px; flex: 0 0 44px; cursor: pointer; }

/* 助手面板 */
.helper-panel { display: flex; flex-direction: column; gap: 6px; }
.helper-panel .opt-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 30px; }
.helper-panel .opt-line > small:first-child { min-width: 40px; color: var(--dim); }
.helper-panel .info-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.helper-panel .info-grid > div { background: var(--well); padding: 4px 6px; border: 1px solid var(--edge); display: flex; flex-direction: column; }
.hp-slots { display: flex; gap: 4px; }
.hp-slots .slot { width: 36px; height: 36px; }
.hp-cost { flex: 1; font-size: var(--fs-s); }
.num-s { width: 64px; }

/* ---------- 勾選框：像素風（取代瀏覽器原生樣式） ---------- */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; margin: 0; padding: 0;
  width: 16px; height: 16px; flex: 0 0 16px;
  background: var(--well); border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge2);
  cursor: pointer; position: relative; vertical-align: middle;
}
input[type="checkbox"]:checked { background: var(--primary-hi); box-shadow: inset 0 0 0 1px var(--good); }
input[type="checkbox"]:checked::after {
  content: ''; position: absolute; left: 3px; top: 0px; width: 4px; height: 8px;
  border: solid var(--text); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
input[type="checkbox"]:disabled { opacity: .4; cursor: default; }
label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
/* 數字輸入：去掉上下箭頭、固定寬度 */
input[type="number"] { -moz-appearance: textfield; text-align: right; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* 委託券兌換 */
.ticket-shop { display: flex; flex-direction: column; gap: 6px; }
.ticket-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; border-top: 1px solid var(--edge); }
.ticket-row small { display: block; color: var(--dim); }
.ticket-row button { white-space: nowrap; }

/* 迷你地圖（地表） */
#minimap { position: fixed; top: 10px; right: 10px; z-index: 5; width: 240px; height: auto; image-rendering: pixelated; border: 2px solid #000; box-shadow: inset 0 0 0 1px var(--edge); cursor: pointer; background: #141018; }
@media (max-width: 760px) { #minimap { width: 150px; top: 6px; right: 6px; } }
.trade-away { background: var(--panel2); border: 1px solid var(--warn); padding: 6px 8px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- 目前目標卡（下一步做什麼）---------- */
.goal-card {
  pointer-events: auto; margin-top: 6px; padding: 8px 10px;
  background: #2a2236; border: 2px solid #000; box-shadow: inset 0 0 0 2px var(--accent);
}
#workGoal .goal-card { margin: 0 0 var(--gap-l); }
.goal-head { display: flex; align-items: center; gap: 6px; font-size: var(--fs-title); color: var(--accent); }
.goal-head b { font-weight: bold; }
.goal-detail { font-size: var(--fs-s); color: var(--dim); margin-top: 2px; }
.goal-needs { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.goal-need { display: inline-flex; align-items: center; gap: 4px; background: var(--well); padding: 2px 6px; font-size: var(--fs-s); color: var(--bad); }
.goal-need.ok { color: var(--good); }
.goal-need img { width: 16px; height: 16px; image-rendering: pixelated; }
.goal-need .nm { color: var(--text); }
.goal-btn { width: 100%; margin-top: 4px; padding: 7px 10px; }
.goal-card.compact { max-width: 260px; }
.goal-card.compact .goal-btn { padding: 5px 8px; }
.reason { display: block; font-size: var(--fs-s); color: var(--warn); margin-top: 4px; }

/* ---------- 「?」說明：規則說明點了才看 ---------- */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: 1px;
  width: 20px; height: 20px; padding: 0; margin-left: 4px; border-radius: 50%;
  font-size: var(--fs-s); font-weight: bold; color: var(--dim); background: var(--well);
  box-shadow: inset 0 0 0 1px var(--edge2);
}
.info-pop {
  position: fixed; z-index: 45; max-width: 280px; padding: 10px 12px;
  background: var(--panel); border: 3px solid #000; box-shadow: inset 0 0 0 2px var(--edge2), 0 6px 0 rgba(0,0,0,.4);
  font-size: var(--fs-s); line-height: 1.6; color: var(--text); white-space: pre-line;
}

/* ===== 標籤、目標配方、工作台設定 ===== */
.badge { display: inline-block; padding: 0 6px; font-size: var(--fs-s); line-height: 18px; border-radius: 2px; background: var(--well); color: var(--dim); box-shadow: inset 0 0 0 1px var(--edge); vertical-align: 1px; }
.badge.ok { color: var(--good); box-shadow: inset 0 0 0 1px #3d6b3d; }
.badge.goal { color: var(--bg); background: var(--accent); box-shadow: none; font-weight: bold; }
.recipe.goal { background: color-mix(in srgb, var(--accent) 8%, var(--panel2)); }
.skill-row.on { box-shadow: inset 3px 0 0 var(--good), inset 0 0 0 1px var(--edge); }
.skill-main { min-width: 0; }
.craft-set { margin-top: 6px; }
.craft-set > summary small { font-weight: normal; margin-left: 4px; }
.craft-set .craft-opts { margin: 6px 0; }
.name-input { width: 9em; padding: 3px 6px; font-size: var(--fs-s); }
.collect-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; font-size: var(--fs-s); color: var(--dim); }
.collect-legend span { padding: 1px 6px; border: 2px solid var(--edge); background: var(--well); }
.collect-legend .t2 { border-color: #c87a3a; }
.collect-legend .t3 { border-color: #c8d0dc; }
.collect-legend .t4 { border-color: #ffd84a; }
.mine-row { padding: 8px 10px; margin: 6px 0; background: var(--panel2); box-shadow: inset 0 0 0 1px var(--edge); }
.mine-row.locked { opacity: 0.55; }
.mine-row .floors { display: flex; gap: 4px; margin: 6px 0 0; }
.mine-row .floor { flex: 1; min-height: 30px; padding: 2px 0; font-size: var(--fs-s); display: flex; align-items: center; justify-content: center; gap: 2px; }
.mine-row .project { margin-top: 6px; }
.mine-card .floor:disabled:not(.on), .mine-row .floor:disabled { opacity: .45; }
.mine-card .floor.on:disabled { opacity: 1; filter: none; background: color-mix(in srgb, var(--accent) 22%, var(--btn)); color: var(--text); }
.item-uses { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 8px; }
.item-uses > small { width: 100%; }
.item-uses .use { font-size: var(--fs-s); padding: 2px 6px; }
