:root {
  --bg: #0a1020;
  --ink: #f3ead8;
  --ink-dim: #9a8f7a;
  --gold: #f0b05a;
  --gold-2: #ffe0a6;
  --ember: #ff7a3a;
  --mist: #b8c4d8;
  --water: #132436;
  --danger: #e07050;
  --panel: rgba(10, 14, 28, 0.72);
  --line: rgba(240, 176, 90, 0.32);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  position: fixed;
  inset: 0;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
}

[hidden] {
  display: none !important;
}

#game-root {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  overflow: hidden;
  background: #070b16;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #0a1020;
}

/* ===== HUD ===== */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: calc(10px + var(--safe-t)) 58px 0 calc(14px + var(--safe-l));
  pointer-events: none;
}

.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.hud-right {
  align-items: flex-end;
  padding-right: 4px;
}

.hud-time-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hud-kicker, .flame-label, .progress-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--mist);
  text-shadow: 0 1px 2px #000, 0 0 10px rgba(0, 0, 0, 0.8);
}

.hud-time {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-shadow: 0 1px 3px #000, 0 0 16px rgba(240, 176, 90, 0.28);
  font-weight: 600;
  line-height: 1;
}

.hud-time.warn { color: #f3c27a; }
.hud-time.urgent { color: var(--danger); }

.flame-wrap, .progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
}

.flame-bar, .progress-bar {
  position: relative;
  height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(240, 176, 90, 0.28);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 0 8px rgba(0, 0, 0, 0.4);
}

.flame-bar { width: 132px; }

.flame-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  background: linear-gradient(180deg, #ffe9b0 0%, #f0b05a 45%, #c45a20 100%);
  box-shadow: 0 0 8px rgba(240, 176, 90, 0.55);
}

.flame-fill.low {
  background: linear-gradient(180deg, #f6c08a 0%, #e07050 55%, #7a2010 100%);
  box-shadow: 0 0 8px rgba(224, 112, 80, 0.5);
}

.flame-fill.empty {
  filter: grayscale(0.55) brightness(0.65);
}

.progress-bar {
  width: 168px;
  height: 6px;
  overflow: visible;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #3a4a6a, var(--gold));
  overflow: hidden;
}

.progress-mark {
  position: absolute;
  top: 50%;
  left: 0;
  width: 7px;
  height: 7px;
  margin: -4px 0 0 -3px;
  border-radius: 50%;
  background: var(--gold-2);
  box-shadow: 0 0 8px rgba(255, 210, 120, 0.85);
  pointer-events: none;
}

/* ===== Mute / wind hint ===== */
.btn-mute {
  position: absolute;
  top: calc(8px + var(--safe-t));
  right: calc(8px + var(--safe-r));
  z-index: 8;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(10, 14, 28, 0.62);
  color: var(--mist);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-mute:active { background: rgba(240, 176, 90, 0.16); }

.gust-warn {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  z-index: 5;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  color: #ffe0a6;
  text-shadow: 0 2px 8px #000, 0 0 22px rgba(240, 176, 90, 0.65);
  pointer-events: none;
  animation: gustpulse 0.9s ease-in-out infinite;
}

@keyframes gustpulse {
  0%, 100% { opacity: 0.75; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

/* ===== Controls ===== */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 18px calc(14px + var(--safe-b)) 18px;
  background: linear-gradient(180deg, rgba(7, 11, 22, 0) 0%, rgba(7, 11, 22, 0.92) 28%, #070b16 100%);
  z-index: 4;
}

.move-cluster, .act-cluster {
  display: flex;
  gap: 12px;
}

.act-btn {
  min-width: 86px;
  height: 72px;
  padding: 8px 12px 10px;
  border-radius: 16px;
  background: rgba(16, 22, 40, 0.88);
  color: var(--ink);
  border: 1px solid rgba(200, 180, 140, 0.28);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 230, 180, 0.08);
}

.act-btn:active, .act-btn.held {
  transform: translateY(1px);
  background: rgba(40, 48, 72, 0.95);
  border-color: rgba(240, 176, 90, 0.55);
}

.act-btn.shield {
  min-width: 132px;
  height: 84px;
  background: rgba(42, 28, 16, 0.92);
  border-color: rgba(240, 176, 90, 0.45);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45), 0 0 16px rgba(240, 176, 90, 0.12);
}

.act-btn.shield:active, .act-btn.shield.held {
  border-color: rgba(255, 224, 166, 0.85);
  background: rgba(72, 42, 16, 0.96);
  box-shadow: 0 0 22px rgba(240, 176, 90, 0.35);
}

.act-label {
  font-size: 20px;
  letter-spacing: 0.14em;
  font-weight: 600;
}

.act-key {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}

/* ===== Overlays ===== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px;
  pointer-events: auto;
}

#game-root > .overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
}

.view-title {
  background: linear-gradient(180deg, rgba(8, 12, 24, 0.28) 0%, rgba(8, 12, 24, 0.12) 40%, rgba(8, 12, 24, 0.55) 100%);
}

.title-wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(240, 176, 90, 0.10), transparent 55%),
    linear-gradient(180deg, rgba(8, 12, 24, 0.18), rgba(8, 12, 24, 0) 42%);
  pointer-events: none;
}

.title-kicker {
  position: relative;
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.42em;
  color: var(--mist);
  text-shadow: 0 1px 3px #000;
}

.title-main {
  position: relative;
  margin: 0 0 12px;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "SimSun", serif;
  font-size: clamp(48px, 9vw, 84px);
  font-weight: 700;
  letter-spacing: 0.28em;
  color: #f7eedc;
  text-indent: 0.28em;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.45),
    0 8px 28px rgba(0, 0, 0, 0.55),
    0 0 36px rgba(240, 176, 90, 0.28);
}

.title-sub {
  position: relative;
  margin: 0 0 10px;
  max-width: 28em;
  font-size: 14px;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-shadow: 0 1px 3px #000;
}

.title-hint {
  position: relative;
  margin: 0 0 28px;
  font-size: 14px;
  letter-spacing: 0.16em;
  color: var(--gold-2);
  text-shadow: 0 1px 3px #000, 0 0 14px rgba(240, 176, 90, 0.25);
}

.title-meta {
  position: relative;
  margin: 16px 0 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

.btn-start {
  position: relative;
  min-width: 200px;
  padding: 12px 28px;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(88, 58, 24, 0.95), rgba(42, 28, 14, 0.95));
  color: var(--ink);
  border: 1px solid rgba(240, 176, 90, 0.5);
  font-size: 18px;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35), 0 0 18px rgba(240, 176, 90, 0.14);
}

.btn-start:active {
  transform: translateY(1px);
  background: rgba(110, 70, 28, 0.95);
}

.view-result {
  justify-content: flex-end;
  padding-top: 18vh;
  padding-bottom: calc(28px + var(--safe-b));
  background: rgba(6, 8, 16, 0.28);
  backdrop-filter: blur(1px);
}

.card {
  position: relative;
  width: min(440px, 92vw);
  padding: 28px 28px 24px;
  background: linear-gradient(180deg, rgba(18, 22, 36, 0.92), rgba(8, 12, 22, 0.94));
  border: 1px solid rgba(240, 176, 90, 0.28);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.card-kicker {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--mist);
}

.card-title {
  margin: 0 0 12px;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "SimSun", serif;
  font-size: 36px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  font-weight: 700;
  color: #f7eedc;
}

.card-line {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.7;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}

.stats {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.stats li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--ink);
  border-bottom: 1px solid rgba(240, 176, 90, 0.12);
  padding-bottom: 6px;
}

.stats .k { color: var(--ink-dim); }
.stats .v.good { color: var(--gold-2); }
.stats .v.warn { color: var(--ember); }

@media (max-height: 640px) {
  .act-btn { min-width: 72px; height: 60px; border-radius: 14px; }
  .act-btn.shield { min-width: 110px; height: 70px; }
  .act-label { font-size: 16px; }
  .controls { padding: 4px 12px calc(8px + var(--safe-b)) 12px; }
  .title-main { font-size: clamp(36px, 8vw, 64px); }
  .card-title { font-size: 28px; }
  .gust-warn { font-size: 18px; }
}

@media (max-width: 480px) {
  .hud { padding-right: 52px; gap: 8px; }
  .flame-bar { width: 100px; }
  .progress-bar { width: 110px; }
  .hud-time { font-size: 22px; }
  .title-main {
    font-size: clamp(36px, 12vw, 56px);
    letter-spacing: 0.16em;
    text-indent: 0.16em;
  }
  .title-sub, .title-hint { font-size: 12px; padding: 0 18px; letter-spacing: 0.06em; }
  .title-meta { font-size: 11px; padding: 0 12px; }
  .act-key { display: none; }
  .controls { padding: 6px 8px calc(10px + var(--safe-b)) 8px; gap: 8px; }
  .move-cluster, .act-cluster { gap: 8px; }
  .move-cluster { flex: 1 1 0; }
  .act-btn {
    min-width: 0;
    flex: 1 1 0;
    height: 64px;
  }
  .act-btn.shield {
    min-width: 120px;
    flex: 0 0 auto;
    width: 42vw;
    max-width: 180px;
    height: 72px;
  }
  .gust-warn { font-size: 16px; letter-spacing: 0.2em; text-indent: 0.2em; }
}

@media (pointer: fine) {
  .act-btn { cursor: pointer; }
}
