:root {
  --bg: #16110d;
  --panel: #251c15;
  --panel-border: #4a3525;
  --gold: #f5b935;
  --gold-bright: #ffe17d;
  --text: #f7efe5;
  --muted: #b8a391;
  --danger: #e74c3c;
  --success: #4cd137;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top, #2c2017 0%, #120d09 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.game-shell {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.controls-hint {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
}

kbd {
  background: #3a2b1f;
  border: 1px solid #5c4532;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
}

.icon-btn {
  background: #3a2b1f;
  border: 1px solid #5c4532;
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #4e3a2a;
  transform: scale(1.05);
}

.stage-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  background: #1f1712;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-drag: none;
}

.hud {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.hud-left,
.hud-center,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.money-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(24, 17, 12, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 225, 125, 0.25);
  border-radius: 10px;
  padding: 6px 12px 12px;
  position: relative;
}

.money-group .stat-pill {
  background: transparent;
  border: none;
  padding: 0;
  min-width: 0;
  backdrop-filter: none;
}

.progress-track {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 5px;
  height: 4px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #e6a312, #ffe17d);
  transition: width 0.2s ease;
}

.progress-fill.complete {
  background: linear-gradient(90deg, #3ecf2f, #a8ff7d);
}

.bp-wallet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}

.bp-wallet-row strong {
  color: #60a5fa;
  font-size: 18px;
}

.stat-pill {
  background: rgba(24, 17, 12, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 225, 125, 0.25);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  min-width: 88px;
}

.stat-pill .label {
  font-size: 11px;
  color: var(--muted);
}

.stat-pill .value {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-pill.money .value {
  color: var(--success);
}

.stat-pill.goal .value {
  color: var(--gold-bright);
}

.stat-pill.wallet .value {
  color: #60a5fa;
}

.backpack-btn {
  pointer-events: auto;
  white-space: nowrap;
  background: rgba(24, 17, 12, 0.85);
  border: 1px solid rgba(255, 225, 125, 0.35);
  color: var(--gold-bright);
  font-weight: 700;
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.backpack-btn:hover {
  background: rgba(58, 43, 31, 0.95);
  transform: translateY(-1px);
}

.backpack-card {
  max-width: 460px;
  text-align: left;
}

.backpack-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #473425;
  border-radius: 10px;
  padding: 10px 14px;
}

.bp-row-info h4 {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.bp-row-info p {
  font-size: 12px;
  color: var(--muted);
}

.bp-badge {
  background: rgba(245, 185, 53, 0.15);
  border: 1px solid rgba(245, 185, 53, 0.4);
  color: var(--gold-bright);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.bp-empty-state {
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
  font-size: 14px;
}

.stat-pill.timer.urgent {
  border-color: var(--danger);
  animation: pulse 0.6s infinite alternate;
}

.stat-pill.timer.urgent .value {
  color: #ff6b6b;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

.dynamite-btn {
  pointer-events: auto;
  white-space: nowrap;
  cursor: grab;
  touch-action: none;
  background: linear-gradient(135deg, #c0392b, #8e241a);
  border: 1px solid #ff7961;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.dynamite-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.dynamite-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dynamite-btn.armed {
  box-shadow: 0 0 0 2px #ffe17d, 0 0 18px rgba(255, 225, 125, 0.6);
  animation: bombPulse 0.9s infinite alternate;
}

.dynamite-btn:active {
  cursor: grabbing;
}

@keyframes bombPulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.bomb-ghost {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-50%, -55%) rotate(-12deg);
  font-size: 34px;
  line-height: 1;
  pointer-events: none;
  z-index: 9999;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(14, 10, 7, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.hidden {
  display: none !important;
}

.card {
  background: linear-gradient(180deg, #2d2118 0%, #1f1610 100%);
  border: 1px solid #5c4432;
  border-radius: 18px;
  padding: 28px 32px;
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--gold);
  background: rgba(245, 185, 53, 0.12);
  border: 1px solid rgba(245, 185, 53, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.start-card h1 {
  font-size: 40px;
  color: var(--gold-bright);
  margin-bottom: 10px;
  text-shadow: 0 3px 12px rgba(245, 185, 53, 0.3);
}

.subtitle {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 18px;
}

.high-score-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #473425;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 15px;
}

.high-score-box strong {
  color: var(--gold-bright);
  font-size: 18px;
}

.primary-btn {
  background: linear-gradient(180deg, #ffd452 0%, #e69d12 100%);
  color: #26180a;
  border: none;
  border-radius: 12px;
  padding: 13px 32px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(230, 157, 18, 0.35);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.primary-btn:active {
  transform: translateY(0);
}

.primary-btn.ghost-btn {
  background: transparent;
  color: var(--gold-bright);
  border: 1px solid rgba(245, 185, 53, 0.45);
  box-shadow: none;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 26px;
}

.save-info {
  margin: -6px 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.start-card #continueBtn {
  margin-bottom: 12px;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -6px 0 16px;
  flex-wrap: wrap;
}

.account-status {
  font-size: 12.5px;
  color: var(--muted);
}

.account-status.warn {
  color: #ffb4a2;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-bright);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link-btn:hover {
  filter: brightness(1.15);
}

.account-card {
  width: min(420px, 92vw);
}

.account-tabs {
  display: flex;
  gap: 8px;
  margin: 4px 0 14px;
}

.account-tab {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid #473425;
  border-radius: 10px;
  padding: 9px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.account-tab.active {
  background: rgba(245, 185, 53, 0.16);
  border-color: rgba(245, 185, 53, 0.55);
  color: var(--gold-bright);
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-form input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #473425;
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.account-form input:focus {
  border-color: rgba(245, 185, 53, 0.7);
}

.account-error {
  margin: 0;
  font-size: 13px;
  color: #ff8f7a;
}

.account-loggedin {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-loggedin .account-note {
  margin: 0;
}

.account-who {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}

.account-who strong {
  color: var(--gold-bright);
  font-size: 17px;
}

.account-note {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  opacity: 0.85;
}

.legend-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 7px 10px;
  border-radius: 8px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.gold { background: #f5b935; box-shadow: 0 0 8px #f5b935; }
.dot.diamond { background: #5eead4; box-shadow: 0 0 8px #5eead4; }
.dot.bag { background: #e879f9; box-shadow: 0 0 8px #e879f9; }
.dot.tnt { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.dot.bomb { background: #fbbf24; box-shadow: 0 0 8px #ff9f1c; }
.play-shop-card {
  max-width: 680px;
  max-height: 92%;
  overflow-y: auto;
}

.play-shop-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.play-shop-hint {
  font-size: 12px;
  color: #8a7666;
  line-height: 1.5;
  margin-top: 4px;
}

.shop-card {
  max-height: 92%;
  overflow-y: auto;
}

.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #473425;
}

.shop-header h2 {
  color: var(--gold-bright);
  font-size: 24px;
}

.shop-header p {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}

.shop-wallet {
  background: rgba(76, 209, 55, 0.12);
  border: 1px solid rgba(76, 209, 55, 0.35);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 15px;
}

.shop-wallet strong {
  color: var(--success);
  font-size: 20px;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.shop-item {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid #4a3525;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.shop-item-info h3 {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 3px;
}

.shop-item-info p {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.buy-btn {
  background: #3d2c1e;
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.buy-btn:hover:not(:disabled) {
  background: #573e2a;
}

.buy-btn:disabled {
  opacity: 0.4;
  border-color: #555;
  color: #999;
  cursor: not-allowed;
}

.shop-footer {
  display: flex;
  justify-content: flex-end;
}

.gameover-card h2 {
  font-size: 28px;
  color: #ff7675;
  margin-bottom: 18px;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.summary-stats > div {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid #473425;
  border-radius: 10px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-stats span {
  font-size: 12px;
  color: var(--muted);
}

.summary-stats strong {
  font-size: 20px;
  color: var(--gold-bright);
}

@media (max-width: 980px) {
  .controls-hint span {
    display: none;
  }
}

@media (max-width: 680px) {
  .shop-grid {
    grid-template-columns: 1fr;
  }
  .legend-grid {
    grid-template-columns: 1fr;
  }
  .hud {
    top: 8px;
    left: 8px;
    right: 8px;
  }
  .stat-pill {
    min-width: 70px;
    padding: 5px 9px;
  }
  .backpack-btn,
  .dynamite-btn {
    font-size: 13px;
    padding: 8px 9px;
  }
}
/* ---------- Touch input & small screens ---------- */
html {
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.mobile-hint {
  display: none;
}

@media (pointer: coarse) {
  .mobile-hint {
    display: block;
    margin: 10px 0 2px;
    padding: 8px 10px;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--gold-bright);
    background: rgba(245, 185, 53, 0.12);
    border: 1px solid rgba(245, 185, 53, 0.35);
    border-radius: 10px;
  }
}

@media (max-width: 820px), (max-height: 520px) {
  body {
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .game-shell {
    max-width: none;
    height: 100vh;
    height: 100dvh;
    gap: 0;
  }

  .top-bar {
    border-radius: 0;
    border-width: 0 0 1px;
    border-color: rgba(74, 53, 37, 0.9);
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
    background: rgba(37, 28, 21, 0.96);
  }

  .brand {
    font-size: 15px;
    gap: 6px;
  }

  .controls-hint {
    gap: 8px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  /* The stage becomes the whole screen; the 960x640 world is letterboxed inside it */
  .stage-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    display: grid;
    place-items: center;
    background:
      radial-gradient(circle at 50% 40%, rgba(255, 209, 102, 0.07), transparent 62%),
      #120d09;
    box-shadow: none;
  }

  #gameCanvas {
    grid-area: 1 / 1;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
  }

  .overlay {
    padding: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .card {
    padding: 18px 16px;
    max-width: 100%;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .hud {
    top: 6px;
    left: 6px;
    right: 6px;
  }

  .hud-left,
  .hud-center,
  .hud-right {
    gap: 6px;
  }

  .money-group {
    padding: 5px 9px 10px;
    gap: 6px;
  }

  .stat-pill {
    min-width: 58px;
    padding: 4px 8px;
  }

  .stat-pill .label {
    font-size: 9.5px;
  }

  .stat-pill .value {
    font-size: 14px;
  }

  .backpack-btn,
  .dynamite-btn {
    min-height: 38px;
    padding: 7px 9px;
    font-size: 12.5px;
    border-radius: 9px;
  }
}

@media (max-width: 560px) {
  .hud {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .hud-center {
    order: 3;
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* ---------- Portrait: tall native mine + thumb-friendly bars ---------- */
@media (max-width: 820px) and (orientation: portrait) {
  /* reserve a band above the mine for status and one below for the action bar */
  .stage-wrapper {
    padding: 58px 0 calc(76px + env(safe-area-inset-bottom));
    background:
      radial-gradient(circle at 50% 32%, rgba(255, 209, 102, 0.06), transparent 60%),
      #120d09;
  }

  .hud {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    align-items: stretch;
  }

  .hud-left {
    position: absolute;
    top: 8px;
    left: 8px;
  }

  .hud-center {
    position: absolute;
    top: 8px;
    right: 8px;
  }

  .hud-right {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 10px;
    display: flex;
    gap: 8px;
  }

  .hud-right .backpack-btn,
  .hud-right .dynamite-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 54px;
    font-size: 15px;
    border-radius: 13px;
  }

  .hud-right .dynamite-btn {
    flex: 0 0 auto;
    min-width: 86px;
    font-size: 16px;
  }

  .money-group {
    padding: 6px 12px 12px;
  }

  .stat-pill {
    min-width: 64px;
    padding: 3px 5px;
  }

  .stat-pill .label {
    font-size: 10px;
  }

  .stat-pill .value {
    font-size: 16px;
  }
}

/* Landscape phones: keep the top-centre (winch + hook origin) clear, stack level/time under the money */
@media (max-height: 520px) and (min-width: 561px) {
  .hud {
    align-items: flex-start;
  }

  .hud-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .hud-center {
    position: absolute;
    left: 0;
    top: 52px;
  }

  .money-group {
    padding: 4px 8px 9px;
  }

  .stat-pill {
    min-width: 54px;
    padding: 3px 7px;
  }

  .stat-pill .label {
    font-size: 9px;
  }

  .stat-pill .value {
    font-size: 13px;
  }

  .backpack-btn,
  .dynamite-btn {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 12px;
  }
}
