:root {
  --bg: #120e0a;
  --bg-2: #1a140e;
  --panel: #221a12ee;
  --ink: #f0e6d4;
  --muted: #b8a58a;
  --gold: #d4a056;
  --gold-dim: #a67832;
  --copper: #c4723a;
  --lamp: #ffcc66;
  --stone: #3a3228;
  --green: #7a9e6a;
  --shadow: 0 18px 50px #0008;
  --border: 1px solid #d4a05644;
  --font-display: "Oswald", Impact, sans-serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --font-ui: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  max-width: 100%;
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: radial-gradient(1100px 640px at 70% -8%, #5a3a18 0%, transparent 52%),
              radial-gradient(800px 480px at 0% 100%, #2a1810 0%, transparent 50%),
              var(--bg);
  overflow: hidden;
  overflow-x: hidden;
  overscroll-behavior: none;
}

button {
  font-family: var(--font-ui);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

#dust, #sparks {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
}
.mote {
  position: absolute; width: 2px; height: 2px; background: #ffcc6644;
  border-radius: 50%; animation: drift 9s linear infinite;
}
.spark {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #d4a05688; animation: rise 8s linear infinite;
}

@keyframes drift {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  12% { opacity: .7; }
  100% { transform: translateY(-100vh) translateX(18px); opacity: 0; }
}
@keyframes rise {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: .65; }
  100% { transform: translateY(-110vh); opacity: 0; }
}

.screen {
  position: relative; z-index: 1;
  display: none; height: 100%;
  height: 100dvh;
}
.screen.active { display: flex; flex-direction: column; }

.title-veil {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 82%, #c4723a33, transparent 48%),
    linear-gradient(#0000, #120e0a);
  pointer-events: none;
}
.title-content {
  margin: auto; text-align: center; max-width: 640px; padding: 32px;
  position: relative; z-index: 2;
}
.title-kicker {
  letter-spacing: .32em; text-transform: uppercase;
  color: var(--gold); font-size: 12px; font-family: var(--font-ui); margin-bottom: 12px;
}
h1 {
  font-family: var(--font-display);
  font-size: clamp(46px, 9vw, 84px);
  letter-spacing: .04em;
  line-height: 1.02;
  text-transform: uppercase;
  background: linear-gradient(#fff4d0, #d4a056);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 8px 18px #000a);
}
.title-sub {
  font-family: var(--font-display); color: var(--lamp);
  letter-spacing: .12em; text-transform: uppercase;
  font-size: 20px; margin: 8px 0 18px;
}
.title-lead {
  font-size: 19px; color: var(--muted); line-height: 1.45; margin-bottom: 28px;
}
.title-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.title-shaft {
  position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%);
  width: 260px; height: 150px;
  background: radial-gradient(ellipse at 50% 0%, #1a120c, #050403 70%);
  border-radius: 50% 50% 0 0;
  box-shadow: 0 -24px 70px #d4a05633;
  overflow: hidden;
}
.title-shaft::before {
  content: ""; position: absolute; left: 18%; right: 18%; top: 18px; bottom: 0;
  background: linear-gradient(#0000, #000c);
  border-radius: 40% 40% 0 0;
  box-shadow: inset 0 0 40px #000a;
}
.title-lamp {
  position: absolute; left: 50%; top: 28px; width: 28px; height: 44px;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 70%, #ffe8a0, #d4a056 55%, #6a4018);
  border-radius: 6px 6px 10px 10px;
  box-shadow: 0 0 28px #ffcc66aa;
  animation: lamp 2.6s ease-in-out infinite;
}
@keyframes lamp {
  0%, 100% { opacity: .75; filter: brightness(1); }
  50% { opacity: 1; filter: brightness(1.25); }
}

.btn {
  border: var(--border); background: #3a2a1c; color: var(--ink);
  padding: 10px 22px; border-radius: 8px; font-size: 16px;
  transition: transform .15s, background .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px #0006; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-gold {
  background: linear-gradient(#f0d078, #b8862a); color: #2a1608;
  border-color: #ffe9a8; font-weight: 700;
}
.btn-ghost { background: transparent; }
.btn-slim { padding: 7px 14px; font-size: 14px; }
.btn-tiny { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: var(--border); background: #2a1c14; color: var(--gold);
}

.hud {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px; background: #140f0bcc; border-bottom: var(--border);
  backdrop-filter: blur(8px);
}
.hud-brand { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.hud-mark { font-size: 26px; }
.hud-brand strong { display: block; font-family: var(--font-display); letter-spacing: .04em; text-transform: uppercase; }
.hud-brand small { color: var(--gold); font-style: italic; }
.hud-stats {
  display: flex; gap: 16px; list-style: none; margin-right: auto;
}
.hud-stats li {
  display: flex; align-items: center; gap: 6px;
  background: #0004; padding: 6px 12px; border-radius: 999px; border: var(--border);
}
.hud-stats span { color: var(--gold); }
.hud-stats i { color: var(--muted); font-style: normal; }
.hud-actions { display: flex; gap: 8px; align-items: center; }

.tabs {
  display: flex; gap: 4px; padding: 8px 12px 0; background: #120e0a;
}
.tab {
  flex: 1; border: none; background: #24180f; color: var(--muted);
  padding: 10px 8px; border-radius: 10px 10px 0 0; font-size: 15px;
}
.tab.active {
  background: #2e2218; color: var(--gold);
  box-shadow: inset 0 2px 0 var(--gold);
}
#game-screen.in-mine .tabs { display: none; }

.stage { flex: 1; min-height: 0; position: relative; }
.location {
  display: none; height: 100%; padding: 14px; gap: 14px;
}
.location.active { display: flex; }

.panel {
  background: var(--panel); border: var(--border); border-radius: 16px;
  padding: 16px; box-shadow: var(--shadow); overflow: auto;
}
.panel h2 {
  font-family: var(--font-display); font-size: 20px; color: var(--gold);
  letter-spacing: .04em; text-transform: uppercase; margin-bottom: 8px;
}
.flavor { color: var(--muted); font-style: italic; margin-bottom: 10px; line-height: 1.4; }
.hint { font-size: 14px; color: #bba88a; margin: 8px 0 12px; }
.hint b { color: var(--gold); }

.camp-layout, .gear-layout, .journal-layout, .mine-layout {
  display: flex; gap: 14px; width: 100%; height: 100%;
}
.camp-layout aside, .gear-layout aside, .journal-layout aside, .mine-side {
  width: 340px; flex-shrink: 0;
}

.camp-scene {
  flex: 1; position: relative; overflow: hidden; border-radius: 16px;
  border: var(--border);
  background: linear-gradient(#1c2838 0%, #1a140e 42%, #0c0a08 100%);
}
.camp-sky {
  position: absolute; inset: 0 0 48% 0;
  background:
    radial-gradient(circle at 78% 28%, #f0d8a0 0 8px, transparent 9px),
    linear-gradient(#243044, #1a140e);
}
.camp-ridge {
  position: absolute; left: 0; right: 0; bottom: 28%; height: 34%;
  background:
    linear-gradient(#0000, #120e0a),
    repeating-linear-gradient(90deg, #2a2218 0 18px, #1c1610 18px 36px);
  clip-path: polygon(0 55%, 12% 30%, 28% 48%, 46% 18%, 68% 40%, 86% 12%, 100% 36%, 100% 100%, 0 100%);
}
.camp-mouth {
  position: absolute; left: 50%; bottom: 8%; width: 180px; height: 120px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 100%, #050403, #1a120c 70%);
  border-radius: 90px 90px 8px 8px;
  box-shadow: inset 0 -20px 40px #000a, 0 0 40px #d4a05622;
}
.camp-fire {
  position: absolute; left: 18%; bottom: 10%; width: 22px; height: 28px;
  border-radius: 50% 50% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #ffe8a0, #c4723a);
  box-shadow: 0 0 24px #d4a056aa;
  animation: lamp 1.6s ease-in-out infinite;
}
.camp-copy {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  background: #120e0acc; border: var(--border); border-radius: 14px; padding: 14px;
}

.inv-grid { display: grid; gap: 8px; grid-template-columns: 1fr; }
.inv-item, .gear-card, .stat-card {
  border: var(--border); border-radius: 12px; background: #0004;
  padding: 8px 10px;
}
.inv-item {
  display: flex; align-items: center; gap: 8px;
  text-align: left; color: inherit; width: 100%;
}
.inv-item .icon { font-size: 22px; }
.inv-item .meta { flex: 1; }
.inv-item .name { display: block; font-size: 14px; }
.inv-item .qty { color: var(--gold); font-size: 13px; }
.inv-item .ops { display: flex; gap: 4px; }
.inv-mini { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
#btn-sell-all { margin-top: 10px; width: 100%; }
.chip {
  background: #0005; border: var(--border); border-radius: 999px;
  padding: 4px 8px; font-size: 13px;
}

.gear-grid {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start;
  overflow: auto;
}
.gear-card {
  padding: 16px; min-height: 160px; display: flex; flex-direction: column; gap: 8px;
}
.gear-card .icon { font-size: 32px; }
.gear-card h3 { font-family: var(--font-display); color: var(--gold); letter-spacing: .04em; text-transform: uppercase; font-size: 18px; }
.gear-card p { color: var(--muted); font-size: 14px; flex: 1; }
.gear-card .lvl { color: var(--lamp); font-size: 13px; font-family: var(--font-ui); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card b { display: block; font-size: 22px; color: var(--gold); font-family: var(--font-display); }
.stat-card span { color: var(--muted); font-size: 13px; }

.log { list-style: none; font-size: 15px; line-height: 1.45; }
.log li { padding: 6px 0; border-bottom: 1px solid #d4a05622; color: var(--muted); }

#loc-mine { padding: 0; }
.chamber {
  flex: 1; position: relative; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 28%, #4a3218 0%, transparent 42%),
    linear-gradient(#2a1c12, #0c0a08 58%, #080604);
  transition: filter .35s, background .35s;
}
.chamber.deep {
  background:
    radial-gradient(ellipse at 50% 40%, #2a1a10 0%, transparent 40%),
    linear-gradient(#1a120c, #050403);
}
.chamber.dark { filter: brightness(.62); }
.chamber-fog {
  position: absolute; inset: 0;
  background: linear-gradient(#0000 40%, #d4a05612 100%);
  animation: fog 8s ease-in-out infinite;
}
@keyframes fog {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
.chamber-lamp {
  position: absolute; left: 50%; top: 36%; width: 90px; height: 90px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, #ffe8a0cc, #d4a05655 45%, transparent 70%);
  box-shadow: 0 0 80px #d4a05666;
  animation: lamp 2.4s ease-in-out infinite;
}
.depth-tag {
  position: absolute; top: 14px; left: 14px;
  background: #0007; border: var(--border); border-radius: 999px;
  padding: 6px 12px; font-family: var(--font-ui); font-size: 13px; color: var(--gold);
}
.vein-spot, .event-spot {
  position: absolute; width: 54px; height: 54px; border: none;
  border-radius: 50%; background: #d4a05622;
  box-shadow: 0 0 18px currentColor;
  font-size: 24px; transform: translate(-50%, -50%);
  animation: pulse 2.4s ease-in-out infinite;
}
.vein-spot.gone, .event-spot.gone { opacity: 0; pointer-events: none; }
@keyframes pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.08); }
}
.mine-side { margin: 14px; }
.energy-bar {
  height: 10px; background: #0006; border-radius: 99px; overflow: hidden; margin: 8px 0 12px;
}
.energy-bar span {
  display: block; height: 100%; width: 50%;
  background: linear-gradient(90deg, #c4723a, #d4a056);
  transition: width .25s;
}
.exit-list { display: grid; gap: 8px; margin: 10px 0; }
.exit-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; color: inherit;
  border: var(--border); background: #0005; border-radius: 12px; padding: 12px;
  font-family: var(--font-ui); font-size: 15px;
}
.exit-btn:hover { background: #3a2a1c; }
.exit-btn small { color: var(--gold); font-size: 12px; }

.foreman-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: #100c08; border-top: var(--border);
  font-style: italic; color: var(--muted);
}
.foreman { font-size: 22px; }

.modal {
  position: fixed; inset: 0; z-index: 20;
  background: #0a0805cc; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: linear-gradient(#2a2016, #1a140e); border: var(--border);
  border-radius: 18px; padding: 24px; max-width: 480px; width: 100%;
  box-shadow: var(--shadow); text-align: center;
}
.modal-card h2 { font-family: var(--font-display); color: var(--gold); margin-bottom: 10px; letter-spacing: .04em; text-transform: uppercase; }
.modal-card p { font-size: 18px; line-height: 1.4; margin-bottom: 12px; }
.modal-card .big { font-size: 48px; margin: 8px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

.toast {
  position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%);
  background: #2a2016ee; border: var(--border); padding: 10px 16px;
  border-radius: 999px; z-index: 15; font-size: 16px;
}

@media (max-width: 900px) {
  body { overflow: hidden; }

  .screen.active {
    height: 100dvh;
    max-height: 100dvh;
  }

  .title-content {
    margin: 0;
    padding: max(28px, env(safe-area-inset-top)) 18px 150px;
    max-width: none;
  }
  h1 { font-size: clamp(36px, 12vw, 62px); }
  .title-sub { font-size: 16px; }
  .title-lead { font-size: 16px; }
  .title-actions {
    flex-direction: column;
    align-items: stretch;
    max-width: 280px;
    margin: 0 auto;
  }
  .title-actions .btn { width: 100%; min-height: 48px; }
  .title-shaft { transform: translateX(-50%) scale(.86); bottom: -16px; }

  .hud {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "stats stats";
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  }
  .hud-brand { grid-area: brand; min-width: 0; }
  .hud-brand strong { font-size: 15px; }
  .hud-brand small { font-size: 12px; }
  .hud-actions { grid-area: actions; }
  .hud-stats {
    grid-area: stats;
    margin: 0;
    width: 100%;
    gap: 6px;
    justify-content: stretch;
  }
  .hud-stats li {
    flex: 1;
    justify-content: center;
    padding: 8px 6px;
    min-height: 40px;
  }
  .icon-btn { width: 44px; height: 44px; }

  .tabs {
    flex-wrap: nowrap;
    gap: 4px;
    padding: 6px 8px;
  }
  .tab {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 6px;
    border-radius: 10px;
  }
  .tab.active { border-radius: 10px; }

  .stage {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .location {
    height: auto;
    min-height: 100%;
    padding: 8px;
    flex-direction: column;
  }
  .location.active,
  .camp-layout, .gear-layout, .journal-layout, .mine-layout {
    flex-direction: column;
  }
  .camp-layout, .gear-layout, .journal-layout, .mine-layout {
    height: auto;
    min-height: 0;
  }
  .camp-layout aside, .gear-layout aside, .journal-layout aside, .mine-side {
    width: auto;
    flex: none;
    max-height: none;
  }

  #loc-mine { padding: 0; }
  .chamber { min-height: 48svh; flex: 1 0 auto; }
  .mine-side { margin: 8px; }
  .camp-scene { min-height: 42svh; }
  .gear-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .btn-gold { min-height: 48px; padding: 12px 22px; }
  .exit-btn { min-height: 48px; }

  .foreman-bar {
    padding: 8px 12px max(10px, env(safe-area-inset-bottom));
    font-size: 14px;
    align-items: flex-start;
  }

  .modal { padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-card {
    max-height: min(88dvh, 640px);
    overflow: auto;
    padding: 18px 16px;
    text-align: left;
  }
  .modal-card h2, .modal-card .big { text-align: center; }
  .modal-card .btn { min-height: 48px; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    transform: none;
    text-align: center;
    max-width: none;
  }
}

@media (max-width: 900px) and (max-height: 500px) {
  .title-shaft { display: none; }
  .title-content { padding-bottom: 24px; }
  .chamber { min-height: 36svh; }
  .hud-mark { font-size: 20px; }
}

@media (max-width: 380px) {
  .hud-stats li { font-size: 13px; gap: 4px; padding: 6px 4px; }
  .tab { font-size: 13px; padding: 10px 4px; }
  .stat-grid { grid-template-columns: 1fr; }
}
