:root {
  color-scheme: dark;
  --ink: #0c0807;
  --panel: rgba(25, 15, 11, 0.9);
  --panel-strong: #1c100b;
  --line: rgba(255, 205, 100, 0.28);
  --gold: #ffc653;
  --gold-hot: #ffde82;
  --cyan: #69e5da;
  --paper: #fff8e8;
  --muted: #bda994;
  --danger: #ff725f;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button, input { font: inherit; }
button { color: inherit; cursor: pointer; }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 34px;
  background: #100b08;
}

.topbar {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 8, 6, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--paper);
  text-decoration: none;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: 23px;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.top-actions { display: flex; align-items: center; gap: 8px; }

.network {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(105, 229, 218, 0.4);
  color: var(--cyan);
  font: 700 11px/1 Consolas, monospace;
}

.network i {
  width: 7px;
  height: 7px;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.icon-button, .wallet-button {
  height: 36px;
  border: 1px solid var(--line);
  background: #1b110c;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  padding: 0;
  font-weight: 900;
  font-size: 17px;
  text-decoration: none;
}

.icon-button:hover, .icon-button:focus-visible { border-color: var(--gold); color: var(--gold); }

.wallet-button {
  min-width: 110px;
  padding: 0 15px;
  border-color: var(--gold);
  color: #201305;
  background: var(--gold);
  font-weight: 900;
}

.wallet-button:hover, .wallet-button:focus-visible { background: var(--gold-hot); }
.wallet-button.connected { color: var(--cyan); border-color: var(--cyan); background: transparent; }

.game-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 45%, rgba(151, 81, 30, 0.22), transparent 48%),
    #0d0907;
}

#game, #game canvas { width: 100%; height: 100%; display: block; }

.mission-panel, .stats, .message {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
}

.mission-panel {
  top: 18px;
  left: 18px;
  width: min(280px, calc(100% - 36px));
  padding: 13px 14px 12px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font: 700 10px/1.2 Consolas, monospace;
}

.mission-panel strong { display: block; font-size: 15px; }

.progress {
  height: 5px;
  margin-top: 11px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
}

.progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gold);
  box-shadow: 0 0 12px rgba(255, 198, 83, 0.75);
  transition: width .35s ease;
}

.mission-count {
  position: absolute;
  right: 13px;
  top: 13px;
  color: var(--muted);
  font: 700 12px/1 Consolas, monospace;
}

.stats {
  top: 18px;
  right: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
}

.stats div { min-width: 88px; padding: 11px 14px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats span { display: block; color: var(--muted); font-size: 10px; }
.stats b { display: block; margin-top: 3px; font: 700 16px/1 Consolas, monospace; color: var(--gold-hot); }

.message {
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 420px);
  min-height: 38px;
  padding: 10px 18px;
  transform: translateX(-50%);
  font-size: 13px;
  text-align: center;
  transition: opacity .2s ease, transform .2s ease;
}

.message.pop { transform: translateX(-50%) translateY(-5px); border-color: var(--gold); }

.mobile-controls {
  position: absolute;
  z-index: 12;
  inset: auto 18px 18px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  pointer-events: auto;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 5px;
  pointer-events: auto;
}

.dpad button, .mine-button {
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(17, 10, 7, .78);
  backdrop-filter: blur(6px);
  touch-action: none;
  user-select: none;
}

.dpad button { font-size: 17px; }
.dpad button[data-move="up"] { grid-column: 2; }
.dpad button[data-move="left"] { grid-column: 1; grid-row: 2; }
.dpad button[data-move="down"] { grid-column: 2; grid-row: 2; }
.dpad button[data-move="right"] { grid-column: 3; grid-row: 2; }
.dpad button.active, .dpad button:active { color: var(--gold); border-color: var(--gold); background: rgba(93, 53, 13, .75); }

.mine-button {
  width: 106px;
  height: 106px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  color: var(--gold-hot);
  font-weight: 900;
}

.mine-button span { display: block; margin-bottom: 4px; font-size: 28px; }
.mine-button.ready { animation: pulse 1.2s ease-in-out infinite; background: rgba(116, 64, 13, .82); }
.mine-button:active { transform: scale(.96); }

.footerbar {
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-top: 1px solid var(--line);
  background: #0b0705;
  color: var(--muted);
  font: 700 10px/1 Consolas, monospace;
}

.start-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px;
  overflow: hidden;
  background:
    linear-gradient(rgba(10, 6, 4, .36), rgba(10, 6, 4, .96)),
    url("assets/mine/floor.webp") center / 360px repeat,
    #100906;
  text-align: center;
  transition: opacity .5s ease, visibility .5s ease;
}

.start-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.start-screen img { position: relative; width: clamp(150px, 24vw, 250px); filter: drop-shadow(0 24px 40px rgba(0,0,0,.5)); }
.start-kicker { margin: 20px 0 4px; color: var(--cyan); font: 700 11px/1.4 Consolas, monospace; }
.start-screen h1 { margin: 0; color: var(--gold-hot); font: 900 76px/1 Impact, sans-serif; }
.start-copy { max-width: 520px; margin: 14px 0 22px; color: #e6d5bd; font-size: 15px; line-height: 1.8; }
.start-screen button, .result-modal button {
  min-width: 180px;
  height: 48px;
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #1c1006;
  font-weight: 900;
}
.start-screen button:hover, .result-modal button:hover { background: var(--gold-hot); }
.start-note { margin-top: 13px; color: var(--muted); font-size: 11px; }

.start-glow {
  position: absolute;
  pointer-events: none;
  width: min(680px, 90vw);
  height: min(680px, 90vw);
  border: 1px solid rgba(255,198,83,.18);
  border-radius: 50%;
  box-shadow: inset 0 0 120px rgba(255,177,48,.08), 0 0 90px rgba(255,177,48,.08);
}

.modal {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a100b;
  color: var(--paper);
  box-shadow: 0 30px 100px rgba(0,0,0,.7);
}
.modal::backdrop { background: rgba(5, 3, 2, .78); backdrop-filter: blur(5px); }
.modal form, .result-modal { padding: 28px; }
.modal h2 { margin: 5px 0 14px; font-size: 24px; }
.modal p { color: #d2c0ac; line-height: 1.8; }
.modal-close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border: 0; background: transparent; font-size: 24px; }
.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 22px; border: 1px solid var(--line); }
.rule-grid div { padding: 13px; border-left: 1px solid var(--line); }
.rule-grid div:first-child { border-left: 0; }
.rule-grid span { display: block; color: var(--muted); font-size: 10px; }
.rule-grid b { display: block; margin-top: 5px; color: var(--gold-hot); font-size: 12px; }
.result-modal { text-align: center; }
.result-mark { margin-bottom: 12px; color: var(--cyan); font: 700 12px/1 Consolas, monospace; }
.result-modal h2 { margin: 0 0 8px; color: var(--gold-hot); }
.result-modal button { margin-top: 12px; }

@keyframes pulse {
  50% { box-shadow: 0 0 0 10px rgba(255,198,83,0); }
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,198,83,.32); }
}

@media (pointer: fine) and (min-width: 900px) {
  .dpad { opacity: .28; }
  .dpad:hover { opacity: 1; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-rows: 56px minmax(0, 1fr) 28px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .brand { font-size: 19px; }
  .brand img { width: 34px; height: 34px; }
  .start-screen h1 { font-size: 52px; }
  .network { display: none; }
  .wallet-button { min-width: 92px; padding: 0 10px; font-size: 12px; }
  .mission-panel { top: 10px; left: 10px; width: 220px; }
  .stats { top: 10px; right: 10px; grid-template-columns: 1fr; }
  .stats div { display: none; min-width: 70px; padding: 9px 11px; border-left: 0; }
  .stats div:first-child { display: block; }
  .message { bottom: 135px; max-width: calc(100% - 30px); width: max-content; }
  .mobile-controls { inset: auto 12px 12px; }
  .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 46px); }
  .mine-button { width: 94px; height: 94px; }
  .footerbar { padding: 0 10px; }
  .rule-grid { grid-template-columns: 1fr; }
  .rule-grid div { border-left: 0; border-top: 1px solid var(--line); }
  .rule-grid div:first-child { border-top: 0; }
}

@media (max-width: 480px) {
  .brand span { display: none; }
}

@media (max-height: 620px) {
  .start-screen img { width: 115px; }
  .start-copy { margin: 8px 0 12px; line-height: 1.5; }
  .start-note { display: none; }
  .mobile-controls { bottom: 8px; }
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(2, 42px); }
  .mine-button { width: 82px; height: 82px; }
  .message { bottom: 98px; }
}
