/* 天書奇談 外傳 — 可愛武俠 RPG 樣式
   配色：宣紙米白 / 玉綠 / 竹青 / 硃砂紅 / 暖金 / 水墨深墨 */
:root {
  --paper: #F5ECD7;
  --paper2: #EFE3C8;
  --ink: #2B2B2B;
  --jade: #3DA67E;
  --bamboo: #6FB98F;
  --cinnabar: #D9483B;
  --gold: #E8B04B;
  --shadow: rgba(43, 43, 43, .18);
  --r-0: #9CA3AF; --r-1: #E5E7EB; --r-2: #4ADE80; --r-3: #3B82F6;
  --r-4: #A855F7; --r-5: #F59E0B; --r-6: #EF4444;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; background: #1c2620; color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  overflow: hidden; user-select: none;
}
body { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }

#stage {
  position: relative; width: min(96vw, 960px); aspect-ratio: 960 / 640;
  max-height: 88vh; border-radius: 16px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.5), 0 0 0 6px #3a2f1e, 0 0 0 8px var(--gold);
  background: var(--paper);
}
#game { display: block; width: 100%; height: 100%; image-rendering: auto; cursor: crosshair; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui .btn, #ui button, #ui .lvl, #ui .bag-cell, #ui .equip-slot, #ui .skill-slot,
#ui .filt, #ui .sk-pick, #ui .clr-item, #ui canvas { pointer-events: auto; }
#hint {
  margin-top: 12px; color: #c7d6c9; font-size: 13px; letter-spacing: .5px; text-align: center;
  opacity: .8; padding: 0 12px;
}

/* ── 載入畫面 ── */
#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #fdf6e6, #e7dabf); z-index: 50;
}
.load-box { text-align: center; }
.load-logo { font-family: "Ma Shan Zheng", serif; font-size: 56px; color: var(--jade); text-shadow: 3px 3px 0 var(--gold); margin-bottom: 18px; }
.load-spinner {
  width: 44px; height: 44px; margin: 0 auto 16px; border: 4px solid rgba(61,166,126,.25);
  border-top-color: var(--jade); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-status { color: var(--ink); font-size: 15px; opacity: .8; }

/* ── 通用按鈕 ── */
.btn {
  font-family: inherit; font-size: 15px; font-weight: 700; color: var(--ink);
  background: var(--paper2); border: 2px solid #cbb88c; border-radius: 12px;
  padding: 10px 20px; cursor: pointer; transition: all .18s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px var(--shadow); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--jade); color: #fff; border-color: #2d8a66; }
.btn.primary:hover { background: #45b88c; }
.btn.ghost { background: transparent; border-color: #b6a888; color: #5c5340; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Overlay 與面板 ── */
.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(28,38,32,.55); backdrop-filter: blur(3px); z-index: 30; padding: 20px;
}
.overlay.show { display: flex; }
.panel {
  background: var(--paper); border-radius: 18px; border: 3px solid var(--gold);
  box-shadow: 0 20px 50px rgba(0,0,0,.4); padding: 22px 26px;
  max-width: 92%; max-height: 88%; overflow: auto; animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.panel-head h2, .panel-head h3 { color: var(--jade); }

/* ── 主選單 ── */
.menu { text-align: center; min-width: 340px; }
.title { font-family: "Ma Shan Zheng", serif; font-size: 52px; color: var(--jade); text-shadow: 3px 3px 0 var(--gold); }
.title .sub { font-size: 24px; color: var(--cinnabar); }
.tagline { color: #6b6048; margin: 6px 0 22px; font-size: 15px; }
.menu-btns { display: flex; flex-direction: column; gap: 12px; max-width: 240px; margin: 0 auto; }
.acct { display: flex; gap: 16px; justify-content: center; margin-top: 20px; color: #6b6048; font-size: 13px; flex-wrap: wrap; }

/* ── 地圖選擇 ── */
.mapselect { width: min(760px, 90vw); }
.maps { display: flex; flex-direction: column; gap: 18px; }
.map-block { background: var(--paper2); border-radius: 14px; padding: 14px; border: 2px solid #d8c9a0; }
.map-block.map-locked { opacity: .55; }
.map-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.map-head h3 { color: var(--ink); border-left: 5px solid var(--accent); padding-left: 10px; }
.map-head span { font-size: 12px; color: #8a7c5e; }
.lvl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.lvl {
  position: relative; display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  background: var(--paper); border: 2px solid #cbb88c; border-radius: 10px; padding: 10px 12px;
  cursor: pointer; transition: all .15s; font-family: inherit; text-align: left;
}
.lvl:hover:not(.locked) { transform: translateY(-2px); border-color: var(--jade); box-shadow: 0 4px 12px var(--shadow); }
.lvl.major { border-color: var(--cinnabar); background: linear-gradient(135deg, #fff, #fde8e6); }
.lvl.cleared { border-color: var(--jade); }
.lvl.locked { opacity: .4; cursor: not-allowed; }
.lvl-idx { font-size: 18px; font-weight: 900; color: var(--cinnabar); }
.lvl-name { font-size: 13px; color: var(--ink); }
.lvl .chk { position: absolute; top: 6px; right: 8px; color: var(--jade); font-weight: 900; }

/* ── 背包/裝備 ── */
.inventory { width: min(860px, 94vw); }
.inv-body { display: grid; grid-template-columns: 260px 1fr; gap: 18px; }
.equip-col h3 { color: var(--jade); font-size: 15px; margin: 4px 0 8px; }
.equip-slot {
  display: flex; align-items: center; gap: 10px; background: var(--paper2);
  border: 2px solid #cbb88c; border-radius: 10px; padding: 8px; margin-bottom: 8px; cursor: pointer;
  transition: all .15s;
}
.equip-slot:hover { box-shadow: 0 3px 10px var(--shadow); }
.equip-slot.empty { opacity: .7; cursor: default; }
.eq-empty { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; font-size: 28px; color: #b3a382; }
.eq-info { display: flex; flex-direction: column; gap: 1px; }
.eq-slot { font-size: 11px; color: #8a7c5e; }
.eq-name { font-size: 14px; font-weight: 700; }
.eq-name.dim { color: #a89876; font-weight: 400; }
.eq-rar { font-size: 11px; }
.char-stats { background: var(--paper2); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.stat { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; color: #5c5340; }
.stat b { color: var(--ink); }
.eff-list { margin-top: 8px; font-size: 12px; color: #8a7c5e; line-height: 1.8; }
.eff-tag { display: inline-block; background: var(--jade); color: #fff; border-radius: 6px; padding: 1px 7px; margin: 2px; font-size: 11px; }
.skill-row { display: flex; flex-direction: column; gap: 6px; }
.skill-slot {
  display: flex; align-items: center; gap: 8px; background: var(--paper2); border: 2px solid #cbb88c;
  border-radius: 9px; padding: 8px 10px; cursor: pointer; transition: all .15s;
}
.skill-slot:hover { border-color: var(--jade); }
.skill-slot.empty { opacity: .7; }
.sk-key { width: 22px; height: 22px; background: var(--ink); color: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.sk-name { font-size: 13px; font-weight: 700; }
.dim { color: #a89876; }
.bag-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.filt { font-family: inherit; font-size: 13px; background: var(--paper2); border: 2px solid #cbb88c; border-radius: 8px; padding: 5px 12px; cursor: pointer; transition: all .15s; }
.filt:hover { border-color: var(--jade); }
.filt.on { background: var(--jade); color: #fff; border-color: #2d8a66; }
.bag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; max-height: 380px; overflow-y: auto; padding: 4px; }
.bag-cell {
  position: relative; aspect-ratio: 1; background: var(--paper2); border: 2px solid #cbb88c;
  border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: all .15s; box-shadow: inset 0 0 0 0 var(--rar);
}
.bag-cell:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 6px 14px var(--shadow), inset 0 0 12px -4px var(--rar); }
.bag-cell .cnt { position: absolute; bottom: 2px; right: 4px; font-size: 11px; font-weight: 700; color: var(--ink); background: rgba(245,236,215,.9); border-radius: 5px; padding: 0 4px; }
.empty-bag { grid-column: 1/-1; text-align: center; color: #a89876; padding: 40px; }

/* ── 道具詳情 / 技能挑選 modal ── */
.modal { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(28,38,32,.5); z-index: 40; padding: 20px; }
.modal.show { display: flex; }
.modal-box { background: var(--paper); border-radius: 16px; border: 3px solid var(--gold); padding: 18px 22px; max-width: 420px; width: 92%; max-height: 86%; overflow: auto; animation: pop .2s ease; }
.item-detail { border-color: var(--rar); }
.it-top { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.it-rar { font-size: 13px; font-weight: 700; }
.it-val { font-size: 13px; color: #8a7c5e; }
.d-stats { background: var(--paper2); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.d-stat { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.d-stat b { color: var(--jade); }
.d-effs { margin-bottom: 10px; }
.d-eff { background: linear-gradient(135deg, #f3ecfb, #fdf6e6); border-left: 3px solid var(--r-4); border-radius: 6px; padding: 7px 10px; margin-bottom: 6px; font-size: 13px; }
.d-eff b { color: var(--r-4); }
.it-flavor { font-style: italic; color: #6b6048; font-size: 13px; margin-bottom: 14px; line-height: 1.6; }
.it-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sk-list { display: flex; flex-direction: column; gap: 8px; }
.sk-pick { position: relative; text-align: left; display: flex; flex-direction: column; gap: 2px; background: var(--paper2); border: 2px solid #cbb88c; border-radius: 10px; padding: 10px 12px; cursor: pointer; font-family: inherit; transition: all .15s; }
.sk-pick:hover { border-color: var(--jade); transform: translateX(3px); }
.sk-pick b { color: var(--ink); font-size: 15px; }
.sk-desc { font-size: 12px; color: #6b6048; margin-top: 3px; }
.eq-badge { position: absolute; top: 8px; right: 10px; background: var(--jade); color: #fff; border-radius: 6px; padding: 1px 8px; font-size: 11px; }

/* ── 過關 / 死亡 ── */
.clear, .death { text-align: center; min-width: 320px; max-width: 460px; }
.clr-title { font-family: "Ma Shan Zheng", serif; font-size: 44px; color: var(--jade); text-shadow: 2px 2px 0 var(--gold); }
.clr-rewards { display: flex; gap: 24px; justify-content: center; margin: 14px 0; font-size: 15px; color: #5c5340; }
.clr-rewards b { color: var(--cinnabar); font-size: 18px; }
.clr-items h4 { color: var(--jade); margin-bottom: 8px; }
.clr-item-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; }
.clr-item { border: 2px solid; border-radius: 8px; padding: 4px 10px; font-size: 13px; font-weight: 700; background: var(--paper2); }
.clr-btns { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.clr-btns .btn { min-width: 180px; }
.ending { color: var(--cinnabar); font-weight: 700; font-size: 15px; padding: 10px; line-height: 1.6; }
.death-title { font-family: "Ma Shan Zheng", serif; font-size: 40px; color: var(--cinnabar); }

/* ── HUD ── */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 16px; gap: 12px; }
.hud-left { display: flex; flex-direction: column; gap: 6px; width: 220px; }
.bar { position: relative; height: 22px; background: rgba(43,43,43,.35); border-radius: 11px; overflow: hidden; border: 2px solid rgba(255,255,255,.3); }
.bar .fill { height: 100%; transition: width .2s ease; }
.bar.hp .fill { background: linear-gradient(90deg, #e85d4f, #ff7d6e); }
.bar.xp { height: 14px; }
.bar.xp .fill { background: linear-gradient(90deg, #d99a2b, #f5c451); }
.bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.hud-mid { text-align: center; flex: 1; }
.lvl-title { font-weight: 700; color: var(--ink); background: rgba(245,236,215,.8); border-radius: 8px; padding: 3px 12px; display: inline-block; font-size: 14px; }
.enemy-count { font-size: 12px; color: #fff; background: rgba(217,72,59,.85); border-radius: 7px; padding: 2px 10px; display: inline-block; margin-top: 5px; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.gold { background: rgba(232,176,75,.92); color: #4a3a12; font-weight: 700; border-radius: 8px; padding: 4px 12px; font-size: 14px; }
.hud-skills { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.hud-skill { position: relative; min-width: 64px; background: rgba(43,43,43,.6); border: 2px solid rgba(255,255,255,.25); border-radius: 10px; padding: 6px 8px; text-align: center; opacity: .6; }
.hud-skill.ready { opacity: 1; border-color: var(--gold); background: rgba(61,166,126,.75); }
.hud-skill .hk { display: block; font-size: 11px; color: var(--gold); font-weight: 700; }
.hud-skill .sn { display: block; font-size: 12px; color: #fff; font-weight: 700; }
.hud-skill .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 900; color: #fff; background: rgba(0,0,0,.4); border-radius: 8px; }
.paused { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); background: rgba(43,43,43,.85); color: #fff; padding: 14px 28px; border-radius: 12px; font-size: 18px; font-weight: 700; }

/* ── RWD ── */
@media (max-width: 680px) {
  .inv-body { grid-template-columns: 1fr; }
  .title { font-size: 40px; }
  .hud-left { width: 150px; }
  .hud-mid .lvl-title { font-size: 12px; }
  #hint { font-size: 11px; }
  .hud-skill { min-width: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
