* {
  box-sizing: border-box;
}

:root {
  --bg0: #140c08;
  --bg1: #1c100c;
  --panel: #241610;
  --ink: #f6ead4;
  --muted: #b89070;
  --accent: #f0c040;
  --accent2: #ff8a3a;
  --line: #5a3824;
  --sky: #7ec8e8;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 70% -8%, #c45a24 0%, transparent 52%),
    radial-gradient(ellipse 50% 36% at 10% 100%, #3a2018 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--ink);
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.15rem 0.85rem 1.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.top {
  text-align: center;
}

.top h1 {
  margin: 0;
  font-family: "ZCOOL KuaiLe", "Noto Sans SC", sans-serif;
  font-size: clamp(1.55rem, 4.4vw, 2.1rem);
  letter-spacing: 0.12em;
  font-weight: 400;
  color: var(--accent);
  text-shadow: 0 0 28px rgba(240, 192, 64, 0.28);
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

#stage {
  display: flex;
  gap: 0.8rem;
  align-items: stretch;
  width: 100%;
  justify-content: center;
}

.hud {
  width: 112px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.78rem;
  padding: 0.7rem 0.5rem;
  background: rgba(0, 0, 0, 0.42);
  border: 2px solid var(--line);
  border-radius: 6px;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.hud-label {
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.level-num,
.stat,
.score {
  font-size: 1.22rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.score {
  color: #ffe08a;
}

.cargo {
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink);
  word-break: break-all;
  min-height: 1.2em;
}

.canvas-wrap {
  position: relative;
  flex-shrink: 0;
  border: 3px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  background: #1a1008;
}

#game {
  display: block;
  width: 100%;
  max-width: 800px;
  height: auto;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 8, 6, 0.78);
  backdrop-filter: blur(4px);
  z-index: 5;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(90%, 360px);
  padding: 1.35rem 1.2rem 1.2rem;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  text-align: center;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-family: "ZCOOL KuaiLe", "Noto Sans SC", sans-serif;
  font-size: 1.45rem;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.panel-desc {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
  text-align: left;
}

.end-score {
  margin: 0.35rem 0 1rem;
  font-size: 1.05rem;
  color: #ffe08a;
  font-weight: 700;
}

.controls-help {
  margin-top: 1rem;
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
}

.controls-help p {
  margin: 0.25rem 0;
}

.controls-help strong {
  color: var(--ink);
}

.btn {
  display: inline-block;
  margin: 0.25rem 0.15rem;
  padding: 0.55rem 1.15rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #2a1808;
  border-color: var(--accent);
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.toast {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.9rem;
  background: rgba(28, 16, 10, 0.92);
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 6;
  pointer-events: none;
  animation: toast-in 0.25s ease;
}

.toast[hidden] {
  display: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hint {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.hint a {
  color: var(--sky);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 1rem;
  pointer-events: none;
  z-index: 20;
}

#touch-controls.is-active {
  display: flex;
}

.tc-dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
  pointer-events: auto;
}

.tc-btn {
  width: 56px;
  height: 56px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 14px;
  background: rgba(28, 16, 10, 0.72);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
}

.tc-empty {
  visibility: hidden;
  pointer-events: none;
}

.tc-act {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: rgba(240, 192, 64, 0.88);
  color: #2a1808;
  border-color: var(--accent);
  font-size: 1.35rem;
}

@media (max-width: 860px) {
  #stage {
    flex-direction: column;
    align-items: center;
  }

  .hud {
    width: 100%;
    max-width: 800px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    gap: 0.45rem 0.7rem;
  }

  .hud-block {
    min-width: 56px;
    align-items: center;
    text-align: center;
  }

  body.mobile-play #touch-controls.is-active {
    display: flex;
  }
}
