* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg0: #1b1430;
    --bg1: #2a1f4a;
    --panel: #241d3a;
    --panel2: #2e2650;
    --ink: #ece8ff;
    --muted: #a99fd0;
    --accent: #ffb347;
    --green: #43d17a;
    --green-d: #2fa860;
    --line: #3a3160;
}

html, body { height: 100%; }
body {
    font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
    background: radial-gradient(120% 100% at 50% 0%, var(--bg1), var(--bg0));
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 12px;
    overflow: hidden;
}

.app {
    width: 100%;
    max-width: 760px;
    height: min(94vh, 860px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 30px 80px rgba(0,0,0,.45);
    overflow: hidden;
    position: relative;
}

.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ---------------- Dig screen ---------------- */
.topbar {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: linear-gradient(180deg, #322a55, #29224400);
}
.stat {
    flex: 1;
    background: rgba(255,255,255,.05);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 7px 10px;
    text-align: center;
}
.stat label { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat span { font-size: 18px; font-weight: 700; }

.stage {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    min-height: 0;
}
#gameCanvas {
    height: 100%;
    max-width: 100%;
    border-radius: 10px;
    image-rendering: pixelated;
    background: #000;
    box-shadow: 0 8px 28px rgba(0,0,0,.4), inset 0 0 0 2px rgba(255,255,255,.05);
    cursor: crosshair;
    touch-action: none;
}

.depth-meter {
    position: absolute;
    right: 20px; top: 12px; bottom: 12px;
    width: 14px;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.depth-track {
    flex: 1; width: 8px;
    background: linear-gradient(180deg,#6ab04c,#8e9aa6 25%,#5a7d9a 50%,#9a6f3a 75%,#7d4a55);
    border-radius: 6px; position: relative; opacity: .8;
    border: 1px solid rgba(0,0,0,.3);
}
.depth-mk {
    position: absolute; left: 50%; top: 0;
    width: 16px; height: 16px; margin-left: -8px; margin-top: -8px;
    background: #fff; border: 3px solid var(--accent);
    border-radius: 50%; box-shadow: 0 0 8px var(--accent);
    transition: top .12s linear;
}
.depth-meter small { font-size: 9px; color: var(--muted); }

.dig-footer {
    padding: 10px 14px 14px;
    display: flex; align-items: center; gap: 12px;
    background: linear-gradient(0deg, #322a55, transparent);
    flex-wrap: wrap;
}
.touch-controls { display: flex; gap: 8px; }
.tc {
    width: 50px; height: 46px;
    font-size: 20px; color: var(--ink);
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 10px; cursor: pointer; user-select: none;
    -webkit-user-select: none; touch-action: none;
}
.tc:active { background: var(--accent); color: #2a1f12; }
.hint { flex: 1; min-width: 160px; font-size: 11px; color: var(--muted); line-height: 1.5; }
.hint b { color: var(--ink); }
.footer-right { display: flex; align-items: center; gap: 10px; }
.pick-chip {
    font-size: 12px; color: var(--muted);
    background: rgba(255,255,255,.05); padding: 6px 10px; border-radius: 8px;
    border: 1px solid var(--line); white-space: nowrap;
}

.btn {
    background: var(--panel2); color: var(--ink);
    border: 1px solid var(--line); border-radius: 10px;
    padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
    transition: transform .08s, background .15s;
}
.btn:hover { background: #39306a; }
.btn:active { transform: scale(.96); }
.btn.big { padding: 13px 20px; font-size: 15px; }
.btn.go { background: linear-gradient(180deg, var(--green), var(--green-d)); border-color: var(--green-d); color: #06210f; }
.btn.go:hover { filter: brightness(1.08); }
.btn.sell { background: linear-gradient(180deg, var(--accent), #e6912a); border-color: #e6912a; color: #2a1a05; width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.icon { padding: 9px 11px; font-size: 15px; line-height: 1; }

/* tool belt (dig screen) */
.toolbelt-wrap {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 6px 14px 0;
}
.belt-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.toolbelt { display: flex; gap: 8px; }
.belt-slot {
    position: relative;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; line-height: 1;
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 9px;
}
.belt-slot.empty { border-style: dashed; opacity: .5; }
.belt-drop {
    position: absolute; top: -7px; right: -7px;
    width: 17px; height: 17px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; line-height: 1; font-weight: 700;
    color: #fff; background: var(--danger);
    border: 1px solid rgba(0,0,0,.3); border-radius: 50%;
    cursor: pointer;
}
.belt-drop:hover { filter: brightness(1.15); }

/* found-item modal */
.found-card { width: min(360px, 100%); text-align: center; border-color: #4a90e2; }
.found-icon {
    font-size: 56px; line-height: 1; margin: 6px auto 10px;
    width: 92px; height: 92px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle, rgba(74,144,226,.35), transparent 70%);
}
.found-card h2 { font-size: 20px; margin-bottom: 8px; }
.found-card .btn.big { width: 100%; margin-top: 4px; }

/* event modal two-button row + counter button */
.event-buttons { display: flex; gap: 10px; }
.event-buttons .btn { flex: 1; }
.btn.counter {
    background: linear-gradient(180deg, #4a90e2, #3a72b8);
    border-color: #3a72b8; color: #06182a;
}
.btn.counter:hover { filter: brightness(1.08); }

.belt-count { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------------- Surface screen ---------------- */
.surface-wrap {
    height: 100%; overflow-y: auto; padding: 22px;
    background: radial-gradient(120% 80% at 50% 0%, #3a2f63, var(--panel));
}
.surface-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px; flex-wrap: wrap; gap: 10px;
}
.surface-head h1 { font-size: 26px; }
.surface-stats { display: flex; gap: 16px; font-size: 15px; color: var(--muted); }
.surface-stats b { color: var(--ink); }

.surface-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 620px) { .surface-grid { grid-template-columns: 1fr; } }

.panel {
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 14px; padding: 16px;
}
.panel h2 { font-size: 15px; margin: 4px 0 12px; color: var(--accent); }
.panel h2 + h2 { margin-top: 18px; }

.inventory { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 240px; overflow-y: auto; }
.inv-item {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,.04); border-radius: 8px; padding: 8px 10px;
}
.gem { width: 14px; height: 14px; border-radius: 3px; transform: rotate(45deg); flex: none; }
.inv-name { flex: 1; font-size: 13px; }
.inv-x { color: var(--muted); font-size: 12px; }
.inv-val { color: var(--green); font-weight: 700; font-size: 13px; min-width: 64px; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 24px; font-size: 13px; }
.note { text-align: center; color: var(--green); font-size: 13px; margin-top: 8px; min-height: 16px; }

.shop-card {
    background: rgba(255,255,255,.04); border: 1px solid var(--line);
    border-radius: 10px; padding: 12px; margin-bottom: 10px;
    display: flex; flex-direction: column; gap: 4px;
}
.shop-card b { font-size: 14px; }
.shop-card small { color: var(--muted); font-weight: 400; }
.shop-card span { font-size: 12px; color: var(--muted); }
.shop-card.owned { align-items: center; text-align: center; color: var(--muted); }
.util-grid { display: grid; gap: 10px; }
.buy {
    margin-top: 6px; align-self: flex-start;
    background: linear-gradient(180deg, var(--green), var(--green-d));
    color: #06210f; border: none; border-radius: 8px;
    padding: 7px 14px; font-weight: 700; font-size: 13px; cursor: pointer;
}
.buy:hover { filter: brightness(1.08); }
.buy.disabled { background: #4a4470; color: #8c84b5; cursor: not-allowed; filter: none; }

.surface-actions { display: flex; gap: 12px; align-items: center; margin-top: 18px; }
.surface-actions .go { flex: 1; }

/* ---------------- Overlays (title + backpack) ---------------- */
.overlay {
    position: absolute; inset: 0;
    background: rgba(10,6,24,.82);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center;
    z-index: 50; padding: 20px;
}
.overlay.show { display: flex; }

.title-card {
    text-align: center; max-width: 430px;
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 18px; padding: 32px 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.title-logo { font-size: 54px; }
.title-card h1 { font-size: 38px; margin: 6px 0 10px; letter-spacing: .02em; }
.title-card p { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 22px; }
.title-card .btn.big { width: 100%; font-size: 17px; padding: 15px; }
.title-controls {
    display: flex; flex-wrap: wrap; gap: 8px 14px;
    justify-content: center; margin-top: 20px; font-size: 11px; color: var(--muted);
}
.title-controls b { color: var(--ink); }

.modal {
    width: min(560px, 100%);
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 16px; padding: 18px 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }
.modal-head .btn { padding: 6px 12px; }
.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 520px) { .modal-body { grid-template-columns: 1fr; } }
.modal-col h3 { font-size: 13px; color: var(--accent); margin-bottom: 10px; }
.modal-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }
.modal-foot b { color: var(--ink); }
.bp-row {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,.04); border-radius: 8px;
    padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
}
.bp-row .inv-val { margin-left: auto; }
.bp-empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; }

/* event modal */
.event-card { width: min(430px, 100%); text-align: center; border-color: var(--accent); }
.event-card .modal-head { justify-content: center; margin-bottom: 12px; }
.event-text { color: var(--ink); font-size: 15px; line-height: 1.6; margin-bottom: 20px; }
.event-card .btn.big { width: 100%; }

/* torch countdown chip */
.torch-chip {
    display: none;
    font-size: 12px; font-weight: 700; color: #2a1a05;
    background: linear-gradient(180deg, var(--accent), #e6912a);
    padding: 6px 10px; border-radius: 8px; white-space: nowrap;
    animation: torchpulse 1s ease-in-out infinite;
}
.torch-chip.show { display: inline-block; }
@keyframes torchpulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }

/* ---------------- Toast ---------------- */
.toast {
    position: fixed; top: 22px; left: 50%; transform: translateX(-50%) translateY(-20px);
    background: rgba(20,14,40,.96); color: var(--ink);
    border: 2px solid var(--green); border-radius: 10px;
    padding: 10px 18px; font-size: 14px; font-weight: 600;
    opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
    z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
