:root {
  --bg: #07080c;
  --panel: #101319;
  --panel-2: #0b0d12;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9eef6;
  --muted: #8b95a6;
  --amber: #ffb03a;
  --amber-2: #ff7a1f;
  --danger: #ff5747;
  --green: #4fd18b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ================================ HUD ================================ */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 0;
}

.depth-label {
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--muted);
  font-weight: 700;
}

.depth-value {
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

.depth-value .unit {
  font-size: 15px;
  font-weight: 700;
  color: var(--amber);
  margin-left: 2px;
}

.depth-best {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 700;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.hud-money {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background: rgba(8, 10, 14, 0.55);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 999px;
}

.ore-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe6a0, #ffb03a 55%, #b46a10);
  box-shadow: 0 0 8px rgba(255, 176, 58, 0.6);
}

.btn-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.6);
  color: var(--text);
  font: 800 13px/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  backdrop-filter: blur(6px);
}

.bars {
  margin: 12px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 320px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-tag {
  width: 34px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.bar {
  position: relative;
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.fill {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  transition: width 0.12s linear, background 0.2s linear;
}

.fill.hull {
  background: linear-gradient(90deg, #3fbf7f, #6ee7a8);
}

.fill.hull.low {
  background: linear-gradient(90deg, #e0a53a, #ffd166);
}

.fill.hull.crit {
  background: linear-gradient(90deg, #e3392c, #ff6a4d);
  animation: pulse 0.8s infinite alternate;
}

.fill.heat {
  background: linear-gradient(90deg, #f0b23a, #ff6a1a);
  width: 0%;
}

.fill.heat.hot {
  box-shadow: 0 0 12px rgba(255, 106, 26, 0.9);
}

.bar-num {
  width: 30px;
  text-align: right;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@keyframes pulse {
  from {
    filter: brightness(0.9);
  }
  to {
    filter: brightness(1.35);
  }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 24%;
  transform: translate(-50%, 12px);
  background: rgba(12, 14, 19, 0.92);
  border: 1px solid rgba(255, 176, 58, 0.4);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(12% + var(--safe-bottom));
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
  transition: opacity 0.6s;
}

.hint.fade {
  opacity: 0;
}

/* ============================== SCREENS ============================== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  background: rgba(4, 5, 8, 0.78);
  backdrop-filter: blur(7px);
  overflow-y: auto;
}

.menu-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(255, 140, 40, 0.16), transparent 55%),
    radial-gradient(ellipse at 50% 100%, rgba(120, 40, 10, 0.22), transparent 60%);
  pointer-events: none;
}

.menu-inner {
  position: relative;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  text-align: center;
}

.logo {
  font-weight: 900;
  font-size: clamp(46px, 14vw, 68px);
  line-height: 0.82;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  margin: 0 0 6px;
}

.logo span {
  display: block;
}

.logo span:nth-child(1) {
  color: #d7e2f0;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}

.logo span:nth-child(2) {
  color: var(--amber);
  text-shadow: 0 4px 0 #8a4a08, 0 0 40px rgba(255, 160, 60, 0.35);
}

.logo span.logo-accent {
  font-size: 0.42em;
  letter-spacing: 0.5em;
  color: var(--muted);
  margin-top: 8px;
  padding-left: 0.5em;
}

.tagline {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.menu-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}

.menu-stats > div {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-stats span {
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.menu-stats small {
  font-size: 8px;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 800;
}

.menu-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.version {
  margin-top: 10px;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.25);
}

/* =============================== PANELS =============================== */
.panel {
  width: min(100%, 400px);
  background: linear-gradient(180deg, rgba(20, 23, 31, 0.98), rgba(10, 12, 17, 0.98));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 18px calc(18px + var(--safe-bottom) * 0.2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-wide {
  width: min(100%, 480px);
}

.panel h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-weight: 900;
}

.kicker {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.28em;
  color: var(--amber);
}

.danger-text {
  color: var(--danger);
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tiny {
  font-size: 10px;
  opacity: 0.7;
}

/* =============================== BUTTONS ============================== */
.btn {
  width: 100%;
  min-height: 54px;
  padding: 15px 16px;
  border-radius: 13px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
  touch-action: manipulation;
}

.btn:active {
  transform: translateY(2px) scale(0.995);
  filter: brightness(1.08);
}

.btn-primary {
  background: linear-gradient(180deg, #ffc558, #f08a1f);
  color: #1b1004;
  border-color: #ffd98c;
  box-shadow: 0 5px 0 #9c550d, 0 14px 28px rgba(255, 140, 30, 0.22);
}

.btn-secondary {
  background: rgba(255, 176, 58, 0.1);
  color: var(--amber);
  border-color: rgba(255, 176, 58, 0.45);
}

.btn-secondary small {
  color: rgba(255, 255, 255, 0.55);
  font-size: 10px;
  margin-left: 6px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: #cfd8e6;
  border-color: var(--line);
}

.btn-danger {
  background: rgba(255, 87, 71, 0.1);
  color: var(--danger);
  border-color: rgba(255, 87, 71, 0.4);
}

.btn:disabled {
  opacity: 0.45;
  filter: grayscale(0.4);
}

/* ============================ MODE CARDS ============================= */
.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}

.mode-card:active {
  transform: scale(0.99);
}

.mode-card.selected {
  border-color: var(--amber);
  background: rgba(255, 176, 58, 0.1);
  box-shadow: 0 0 0 1px rgba(255, 176, 58, 0.35) inset;
}

.mode-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-size: 18px;
  color: var(--amber);
  flex: 0 0 auto;
}

.mode-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mode-copy b {
  font-size: 14px;
  letter-spacing: 0.04em;
}

.mode-copy small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

/* ============================== CONTROLS ============================= */
.seed-box {
  background: #050609;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.seed-label {
  font-size: 8px;
  letter-spacing: 0.28em;
  color: var(--muted);
  font-weight: 900;
}

.seed-box code {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--amber);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  margin: 2px 0;
}

.seed-hint {
  font-size: 10px;
  color: var(--muted);
}

.pause-depth {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 800;
}

.pause-depth b {
  color: var(--text);
  font-size: 16px;
}

.field-label {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--muted);
  font-weight: 900;
  margin-top: 4px;
}

.seg {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 4px;
}

.seg button {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.seg button.active {
  background: linear-gradient(180deg, #ffc558, #f08a1f);
  color: #1b1004;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.toggle-row input {
  width: 44px;
  height: 26px;
  accent-color: var(--amber);
}

/* ============================== UPGRADES ============================= */
.cards {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 4px;
}

.upgrade-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  padding: 14px 15px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s;
  overflow: hidden;
}

.upgrade-card:active {
  transform: scale(0.99);
}

.upgrade-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--rarity, #9fb4c7);
}

.upgrade-card:hover {
  border-color: rgba(255, 176, 58, 0.5);
}

.upgrade-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.upgrade-name {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.upgrade-rarity {
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.18em;
  color: var(--rarity, #9fb4c7);
  text-transform: uppercase;
  white-space: nowrap;
}

.upgrade-desc {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
}

/* =============================== DEATH =============================== */
.death-depth {
  text-align: center;
  font-size: 58px;
  font-weight: 900;
  line-height: 1;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(255, 160, 60, 0.25);
}

.death-depth small {
  font-size: 18px;
  color: var(--muted);
  margin-left: 4px;
}

.death-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.death-grid > div {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.death-grid small {
  font-size: 8px;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 900;
}

.death-grid b {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.best-line {
  display: none;
  text-align: center;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.24em;
  color: var(--amber);
}

.best-line.show {
  display: block;
}

.levelup {
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--green);
  background: rgba(79, 209, 139, 0.08);
  border: 1px solid rgba(79, 209, 139, 0.3);
  border-radius: 10px;
  padding: 9px;
}

/* ============================== WORKSHOP ============================= */
.hub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wallet {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
}

.hub-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.hub-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}

.hub-item.maxed {
  opacity: 0.6;
}

.hub-name {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.03em;
}

.hub-desc {
  grid-column: 1 / -1;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.3;
}

.pips {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}

.pip {
  width: 9px;
  height: 5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
}

.pip.on {
  background: var(--amber);
}

.hub-buy {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid rgba(255, 176, 58, 0.4);
  background: rgba(255, 176, 58, 0.12);
  color: var(--amber);
  font-family: inherit;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  white-space: nowrap;
  cursor: pointer;
}

.hub-buy:disabled {
  opacity: 0.35;
  border-color: var(--line);
  color: var(--muted);
  background: transparent;
}

/* =============================== FLASH =============================== */
.flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 240, 200, 0.85), rgba(255, 160, 60, 0.15) 55%, transparent 70%);
  z-index: 25;
  transition: opacity 0.35s ease-out;
}

.flash.on {
  opacity: 1;
  transition: opacity 0.05s;
}

@media (max-height: 720px) {
  .logo {
    font-size: 44px;
  }
  .menu-inner {
    gap: 9px;
  }
  .panel {
    padding: 16px 14px;
    gap: 9px;
  }
  .panel h2 {
    font-size: 20px;
  }
  .btn {
    min-height: 48px;
    padding: 12px 14px;
  }
  .depth-value {
    font-size: 28px;
  }
  .death-depth {
    font-size: 46px;
  }
  .hub-list {
    max-height: 40vh;
  }
}
