* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    font-family: system-ui, "Microsoft JhengHei", "PingFang TC", sans-serif;
    height: 100vh; height: 100dvh;
    background: #1a120c; color: #f4ece0;
    overflow: hidden; display: flex; flex-direction: column;
    user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; touch-action: manipulation; }
img { -webkit-user-drag: none; }

/* ── 頂列 ── */
.top {
    flex-shrink: 0; display: flex; align-items: center; gap: .5rem;
    padding: .45rem .7rem; background: linear-gradient(180deg, #2a1a10, #1c120a);
    border-bottom: 2px solid #5a3a1a; z-index: 5;
}
.back { color: #e8d8c0; text-decoration: none; font-size: 1.3rem; padding: .3rem .5rem; border-radius: 10px; }
.back:active { background: rgba(255,255,255,.12); }
.money { flex: 1; text-align: center; line-height: 1.15; min-width: 0; }
.coins { display: inline-flex; align-items: center; gap: .35rem; font-size: 1.55rem; font-weight: 800; color: #ffd23a; }
.coins img { width: 26px; height: 26px; }
.coins.bump { animation: bump .18s; }
@keyframes bump { 50% { transform: scale(1.08); } }
.rates { font-size: .8rem; color: #c8b8a0; display: flex; gap: .9rem; justify-content: center; flex-wrap: wrap; }
.rates b { color: #ffe9a0; }
.hbtns { display: flex; gap: .35rem; }
.hbtn { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,.1); display: grid; place-items: center; }
.hbtn:active { background: rgba(255,255,255,.25); }
.hbtn svg { width: 22px; height: 22px; }
.hbtn.off { opacity: .5; }

/* ── 版面 ── */
.game { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.mine { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: manipulation; }
#scene { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

.depth-chip {
    position: absolute; left: 10px; top: 10px; padding: .3rem .6rem; border-radius: 12px;
    background: rgba(0,0,0,.55); border: 1px solid rgba(255,220,150,.25); pointer-events: none;
    display: flex; flex-direction: column; line-height: 1.15;
}
.depth-chip b { font-size: 1.05rem; color: #ffe9a0; }
.depth-chip span { font-size: .75rem; color: #d8c8b0; }
.buffs { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; pointer-events: none; }
.buff { background: rgba(0,0,0,.6); border-radius: 10px; padding: .15rem .5rem; font-size: .78rem; color: #ffe9a0; border: 1px solid rgba(255,220,120,.3); }

.skills { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; }
.skill {
    position: relative; width: 56px; height: 56px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #5a4430, #2a1c10);
    border: 2px solid #c89a4a; display: grid; place-items: center;
    --p: 0;
}
.skill img { width: 34px; height: 34px; }
.skill::after {
    content: ""; position: absolute; inset: -2px; border-radius: 50%;
    background: conic-gradient(rgba(0,0,0,.7) calc(var(--p) * 1turn), transparent 0);
    pointer-events: none;
}
.skill .cd { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: .95rem; z-index: 1; text-shadow: 0 1px 2px #000; }
.skill .key { position: absolute; right: -4px; bottom: -4px; font-size: .62rem; background: #2a1c10; border: 1px solid #c89a4a; border-radius: 6px; padding: 0 4px; z-index: 1; }
.skill.ready { border-color: #ffd23a; animation: glow 1.6s infinite; }
@keyframes glow { 50% { border-color: #fff4b0; transform: scale(1.04); } }
.skill.locked { filter: grayscale(1); opacity: .45; }
.skill .name { position: absolute; right: 64px; top: 50%; transform: translateY(-50%); white-space: nowrap; font-size: .75rem; background: rgba(0,0,0,.6); padding: .1rem .4rem; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.skill:hover .name { opacity: 1; }

.toasts { position: absolute; left: 50%; top: 54px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(92%, 420px); z-index: 3; }
.toast {
    display: flex; align-items: center; gap: .5rem; padding: .45rem .8rem; border-radius: 14px;
    background: linear-gradient(180deg, rgba(60,40,20,.95), rgba(30,20,10,.95)); border: 1px solid #c89a4a;
    font-size: .9rem; box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: toastIn .3s ease-out;
}
.toast img { width: 30px; height: 30px; flex-shrink: 0; }
.toast b { color: #ffd23a; }
.toast.big { font-size: 1.05rem; border-color: #ffd23a; }
.toast.out { opacity: 0; transform: translateY(-8px); transition: all .4s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.95); } }

/* ── 面板 ── */
.panel {
    flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
    background: linear-gradient(180deg, #2c1e12, #1e140c); border-top: 2px solid #6a4a22;
    height: 44vh; height: 44dvh; transition: height .25s ease;
}
.panel.collapsed { height: 48px; }
.tabs { display: flex; overflow-x: auto; flex-shrink: 0; border-bottom: 1px solid #4a3218; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; padding: .7rem .75rem; font-size: .92rem; color: #c8b090; position: relative; white-space: nowrap; }
.tab.on { color: #ffd23a; font-weight: 700; background: rgba(255,210,58,.08); }
.tab.on::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: 0; height: 3px; border-radius: 3px; background: #ffd23a; }
.tab .dot { position: absolute; top: 6px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #5ad46a; }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; padding: .6rem; -webkit-overflow-scrolling: touch; }
.page { display: none; }
.page.on { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .55rem; flex-wrap: wrap; }
.page-head h3 { font-size: 1rem; color: #ffe9a0; }
.hint { font-size: .78rem; color: #b8a488; }
.qty { display: inline-flex; border: 1px solid #6a4a22; border-radius: 10px; overflow: hidden; }
.qty button { padding: .3rem .6rem; font-size: .82rem; color: #d8c8b0; }
.qty button.on { background: #6a4a22; color: #ffe9a0; font-weight: 700; }

.list { display: grid; grid-template-columns: 1fr; gap: .45rem; }
.card[hidden] { display: none; }
.shop-jump { margin-bottom: .55rem; }
.card {
    display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: 14px;
    background: rgba(255,255,255,.05); border: 2px solid transparent; text-align: left; width: 100%;
}
.card .ic { width: 46px; height: 46px; flex-shrink: 0; border-radius: 12px; background: rgba(0,0,0,.3); display: grid; place-items: center; }
.card .ic img { width: 40px; height: 40px; }
.card .info { flex: 1; min-width: 0; }
.card .nm { font-weight: 700; font-size: .95rem; }
.card .lv { font-size: .75rem; color: #b8a488; margin-left: .3rem; font-weight: 400; }
.card .ds { font-size: .78rem; color: #c8b8a0; }
.card .price { flex-shrink: 0; text-align: right; font-weight: 800; color: #ffd23a; font-size: .92rem; min-width: 74px; }
.card .price small { display: block; font-weight: 400; color: #b8a488; font-size: .7rem; }
.card.can { border-color: #5ad46a; background: rgba(90,212,106,.08); }
.card.can:active { transform: scale(.985); }
.card:disabled { cursor: default; }
.card.cant .price { color: #9a8a70; }
.card.max { border-color: #8b7650; background: rgba(214,176,91,.08); cursor: default; }
.card.max .price { color: #dcc79f; }
.card.locked { opacity: .5; }
.card.locked .ic img { filter: grayscale(1) brightness(.5); }

.btn {
    padding: .5rem .9rem; border-radius: 12px; font-weight: 700; font-size: .9rem;
    background: linear-gradient(180deg, #ffcf3a, #e09a14); color: #3a2208; border-bottom: 3px solid #a06a08;
}
.btn:active { transform: translateY(2px); border-bottom-width: 1px; }
.btn:disabled { filter: grayscale(1); opacity: .5; cursor: default; }
.btn.ghost { background: rgba(255,255,255,.1); color: #f4ece0; border-bottom-color: rgba(0,0,0,.3); }
.btn.red { background: linear-gradient(180deg, #ff7a5a, #d0402a); color: #fff; border-bottom-color: #8a2010; }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }

.ore-row .count { font-size: 1.05rem; font-weight: 800; color: #fff; }
.trend { font-size: .75rem; margin-left: .25rem; }
.trend.up { color: #5ad46a; }
.trend.down { color: #ff7a5a; }
.hot { display: inline-block; font-size: .7rem; background: #e0402a; color: #fff; border-radius: 6px; padding: 0 .3rem; margin-left: .3rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .45rem; }
.tile { background: rgba(255,255,255,.05); border-radius: 12px; padding: .45rem .3rem; text-align: center; border: 1px solid rgba(255,255,255,.06); }
.tile img { width: 44px; height: 44px; }
.tile .nm { font-size: .8rem; font-weight: 700; }
.tile .sub { font-size: .7rem; color: #b8a488; }
.tile.unknown img { filter: brightness(0) opacity(.45); }
.tile.unknown .nm { color: #7a6a58; }
.tile.got { border-color: rgba(255,210,58,.35); }

.ach { display: flex; gap: .55rem; align-items: center; padding: .45rem .55rem; border-radius: 12px; background: rgba(255,255,255,.04); margin-bottom: .35rem; }
.ach img { width: 34px; height: 34px; flex-shrink: 0; }
.ach.no img { filter: grayscale(1) opacity(.45); }
.ach .info { flex: 1; min-width: 0; }
.ach .nm { font-size: .9rem; font-weight: 700; }
.ach .ds { font-size: .75rem; color: #b8a488; }
.bar { height: 6px; border-radius: 3px; background: rgba(0,0,0,.4); margin-top: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #e09a14, #ffd23a); }
.ach.yes .nm { color: #ffd23a; }

.section { background: rgba(255,255,255,.04); border-radius: 14px; padding: .7rem; margin-bottom: .6rem; }
.section h3 { font-size: 1rem; color: #ffe9a0; margin-bottom: .35rem; }
.section p { font-size: .84rem; color: #d8c8b0; line-height: 1.5; margin-bottom: .4rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .8rem; font-size: .82rem; color: #c8b8a0; }
.stats b { color: #ffe9a0; float: right; }
.row { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; font-size: .88rem; flex-wrap: wrap; }
.row label { min-width: 4.5em; }
.row input[type=range] { flex: 1; min-width: 120px; accent-color: #ffcf3a; }
textarea { width: 100%; height: 70px; background: rgba(0,0,0,.35); color: #f4ece0; border: 1px solid #6a4a22; border-radius: 10px; padding: .4rem; font-size: .75rem; font-family: ui-monospace, monospace; user-select: text; -webkit-user-select: text; }

/* ── 對話框 ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal.on { display: flex; }
.modal-box {
    width: min(440px, 100%); max-height: 88vh; overflow-y: auto; border-radius: 20px; padding: 1.1rem 1.1rem .9rem;
    background: linear-gradient(180deg, #3a2814, #22160c); border: 2px solid #c89a4a; box-shadow: 0 12px 40px rgba(0,0,0,.6);
    animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal-box h2 { font-size: 1.25rem; color: #ffd23a; margin-bottom: .6rem; text-align: center; }
.modal-box .body { font-size: .92rem; line-height: 1.6; color: #f0e4d0; }
.modal-box .body ul { padding-left: 1.2rem; margin: .3rem 0; }
.modal-box .body .big { font-size: 1.5rem; font-weight: 800; color: #ffd23a; text-align: center; margin: .4rem 0; }
.modal-box .icons { display: flex; justify-content: center; gap: .5rem; margin: .4rem 0; flex-wrap: wrap; }
.modal-box .icons img { width: 48px; height: 48px; }
.modal-btns { display: flex; gap: .6rem; justify-content: center; margin-top: .9rem; flex-wrap: wrap; }

/* ── 橫向／寬螢幕 ── */
@media (min-width: 760px) and (orientation: landscape), (min-width: 1000px) {
    .game { flex-direction: row; }
    .panel { width: 400px; height: auto !important; border-top: none; border-left: 2px solid #6a4a22; }
    .panel.collapsed { height: auto; }
}
@media (min-width: 1300px) { .panel { width: 460px; } }
@media (max-height: 520px) and (orientation: landscape) {
    .panel { width: 330px; }
    .top { padding: .25rem .6rem; }
    .coins { font-size: 1.25rem; }
    .skill { width: 46px; height: 46px; }
    .skill img { width: 28px; height: 28px; }
    .skills { gap: 6px; }
}
@media (max-width: 380px) {
    .skill { width: 48px; height: 48px; }
    .skill img { width: 30px; height: 30px; }
    .rates { gap: .5rem; font-size: .72rem; }
}
@media (prefers-reduced-motion: reduce) {
    .skill.ready, .coins.bump { animation: none; }
}
.hbtn .slash { display: none; }
.hbtn.off .slash { display: inline; }
@media (max-width: 600px) {
    .toasts { top: 8px; left: auto; right: 72px; transform: none; width: calc(100% - 150px); align-items: flex-end; }
    .toast { font-size: .74rem; padding: .3rem .5rem; gap: .35rem; border-radius: 10px; }
    .toast img { width: 20px; height: 20px; }
    .toast.big { font-size: .8rem; }
}
.hot[hidden] { display: none; }

.depth-chip small { margin-top:5px; font-size:.65rem; color:#a9dce7; max-width:220px; }
#layerFilter { width:100%; padding:10px; border:1px solid #88703e; border-radius:8px; background:#171c2a; color:#fff0cd; font:inherit; }
.layer-note { margin-top:8px; }
#scene:focus-visible { outline:2px solid #ffd23a; outline-offset:-3px; }
