:root {
  --bg: #1a120c;
  --panel: rgba(28, 18, 12, 0.9);
  --line: rgba(212, 168, 75, 0.35);
  --accent: #e8b84a;
  --accent-dim: #a67c2d;
  --warn: #c84b3a;
  --text: #f3e6d0;
  --muted: #b9a48a;
  --font-display: "Ma Shan Zheng", "Noto Sans SC", serif;
  --font-body: "Noto Sans SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 28% 18%, rgba(232, 184, 74, 0.14), transparent 48%),
    radial-gradient(ellipse at 78% 82%, rgba(160, 48, 40, 0.12), transparent 46%),
    linear-gradient(165deg, #140e0a 0%, #24180f 42%, #1a120c 100%);
}

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

.hidden { display: none !important; }

#hud {
  position: absolute;
  inset: 0 0 auto 0;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    0
    max(14px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.stat {
  min-width: 72px;
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.stat span:last-child {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 26px;
  color: var(--accent);
  line-height: 1.1;
}

.bars { display: grid; gap: 6px; }

.bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(232, 184, 74, 0.15);
}

.bar > div {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  border-radius: inherit;
  transition: transform 0.12s linear;
}

.bar.hp > div {
  background: linear-gradient(90deg, #8f2a22, #d45a3c);
}

.bar.xp > div {
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

#joystick {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  pointer-events: none;
}

#joy-base {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 1px solid rgba(232, 184, 74, 0.3);
  background:
    radial-gradient(circle, rgba(232, 184, 74, 0.12) 0 38%, transparent 40%),
    rgba(20, 12, 8, 0.36);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.28);
  position: relative;
}

#joy-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(232, 184, 74, 0.55);
  box-shadow: 0 0 18px rgba(232, 184, 74, 0.25);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 28%, rgba(232, 184, 74, 0.14), transparent 55%),
    rgba(12, 8, 5, 0.76);
  backdrop-filter: blur(6px);
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.panel-inner {
  width: min(420px, 100%);
  text-align: center;
  padding: 36px 28px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.brand {
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.28em;
  color: var(--accent);
  margin-bottom: 10px;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.15;
}

h1 { font-size: clamp(40px, 10vw, 56px); margin-bottom: 12px; }
h2 { font-size: clamp(28px, 7vw, 36px); margin-bottom: 18px; }

.sub, .hint, .result {
  color: var(--muted);
  line-height: 1.7;
}

.sub { margin-bottom: 28px; }
.hint { margin-top: 18px; font-size: 13px; }
.result { margin-bottom: 24px; font-size: 15px; }

button {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.12em;
  font-size: 22px;
  color: #2a1808;
  background: linear-gradient(135deg, #f0d078, var(--accent));
  padding: 12px 28px;
  min-width: 180px;
  min-height: 48px;
  transition: transform 0.15s ease, filter 0.15s ease;
}

button:active { transform: scale(0.97); }
button:hover { filter: brightness(1.05); }

.levelup-inner { width: min(520px, 100%); }

#upgrade-cards {
  display: grid;
  gap: 10px;
}

.upgrade-card {
  text-align: left;
  border: 1px solid rgba(232, 184, 74, 0.3);
  background: rgba(36, 24, 14, 0.92);
  color: var(--text);
  padding: 14px 16px;
  min-width: 0;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  font-family: var(--font-body);
  font-size: 14px;
  letter-spacing: 0;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  border-color: var(--accent);
  background: rgba(48, 32, 18, 0.96);
  outline: none;
}

.upgrade-card .title {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 4px;
}

.upgrade-card .desc {
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
}

@media (max-width: 520px) {
  .hud-top { gap: 6px; margin-bottom: 7px; }
  .stat { min-width: 60px; }
  .stat .label { font-size: 10px; }
  .stat span:last-child { font-size: 22px; }
  .bars { gap: 4px; }
  .bar { height: 7px; }
  .panel-inner { padding: 28px 20px; }
  .sub { margin-bottom: 22px; }
  #upgrade-cards { gap: 8px; }
  .upgrade-card { padding: 12px 14px; min-height: 64px; }
}

/* Desktop QA uses a realistic portrait phone viewport; actual phones remain edge-to-edge. */
@media (min-width: 700px) and (pointer: fine) {
  body {
    padding: 22px;
    background:
      radial-gradient(circle at 50% 40%, #4b4037 0, #201914 48%, #100d0b 100%);
  }

  #app {
    width: min(390px, calc(100vw - 44px));
    height: min(844px, calc(100dvh - 44px));
    border: 8px solid #0c0b0a;
    border-radius: 42px;
    box-shadow:
      0 34px 90px rgba(0, 0, 0, 0.72),
      0 0 0 1px #655c54,
      inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }

  #app::before {
    content: "";
    position: absolute;
    z-index: 30;
    top: 9px;
    left: 50%;
    width: 104px;
    height: 25px;
    transform: translateX(-50%);
    border-radius: 16px;
    background: #080706;
    box-shadow: inset 0 -1px rgba(255, 255, 255, 0.06);
    pointer-events: none;
  }

  #hud { padding-top: 40px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  #joy-base { width: 88px; height: 88px; }
  #joy-knob { width: 40px; height: 40px; }
  .panel-inner { padding: 18px; }
  .hint { display: none; }
}
