:root {
  --deep: #061a3a;
  --deep2: #0b2a58;
  --blue: #4aa8ff;
  --blue-soft: #9fd4ff;
  --cream: #fff6e6;
  --rice: #ffffff;
  --gold: #ffd166;
  --pink: #ff8fb1;
  --bad: #ff6b6b;
}

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

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #04122a;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  color: var(--cream);
  user-select: none;
}

#app { position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; }

#stage { position: absolute; inset: 0; display: block; touch-action: none; cursor: grab; }
#stage:active { cursor: grabbing; }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(4, 16, 36, .82), rgba(4, 16, 36, 0));
  pointer-events: none;
  font-size: 13px;
  flex-wrap: wrap;
}

.hud-item { display: flex; align-items: center; gap: 6px; }
.hud-label { color: #8fb6dd; letter-spacing: .5px; white-space: nowrap; }
.hud-val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 26px; }
.hud-val.money { color: var(--gold); }
.hud-val.rice { color: var(--blue-soft); }

.bar {
  width: 120px; height: 9px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5);
}
.bar-fill { height: 100%; width: 100%; border-radius: 99px; transition: width .12s linear, background .2s; }
.bar-fill.energy { background: linear-gradient(90deg, #4aa8ff, #8ce0ff); }
.bar-fill.energy.low { background: linear-gradient(90deg, #ff6b6b, #ffb46b); }
.bar-fill.slack { background: linear-gradient(90deg, #9b8cff, #ff8fb1); width: 0%; }

.hud-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.clock {
  margin-left: 10px;
  padding: 2px 10px;
  border-radius: 99px;
  background: rgba(74, 168, 255, .18);
  border: 1px solid rgba(74, 168, 255, .4);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--blue-soft);
}

/* ---------------- 连击 / toast ---------------- */
.combo {
  position: absolute;
  top: 78px; left: 50%;
  transform: translateX(-50%) scale(1);
  font-size: 34px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 209, 102, .8), 0 3px 0 #b26a00;
  pointer-events: none;
  transition: transform .1s ease-out, opacity .3s;
}
.combo.pop { transform: translateX(-50%) scale(1.35); }
.combo.fade { opacity: 0; }

.toast {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border-radius: 99px;
  background: rgba(6, 26, 58, .9);
  border: 1px solid rgba(74, 168, 255, .5);
  font-size: 15px;
  font-weight: 700;
  color: var(--blue-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; }

/* ---------------- 界面 ---------------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 40%, rgba(11, 42, 88, .55), rgba(4, 12, 28, .93));
  backdrop-filter: blur(3px);
  z-index: 5;
}
.screen.hidden { display: none; }

.panel {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 28px 22px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(12, 40, 80, .96), rgba(6, 22, 46, .98));
  border: 1px solid rgba(74, 168, 255, .35);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .08);
  text-align: center;
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #8ce0ff, #ffffff, #8ce0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sub { margin: 0 0 16px; font-size: 13px; color: #8fb6dd; letter-spacing: .5px; }

.story {
  text-align: left;
  font-size: 13.5px;
  line-height: 1.75;
  color: #d7e6f7;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(74, 168, 255, .08);
  border-left: 3px solid var(--blue);
}
.story p { margin: 0 0 4px; }
.story b { color: var(--blue-soft); }

.rules {
  margin: 14px 0 18px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.9;
  color: #a9c6e3;
}
.rules li::before { content: "🍚 "; }
.rules b { color: var(--gold); }

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #04122a;
  background: linear-gradient(180deg, #a8e4ff, #4aa8ff);
  box-shadow: 0 6px 0 #1d6bb5, 0 10px 24px rgba(74, 168, 255, .35);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1d6bb5; }

.tiny { margin: 12px 0 0; font-size: 11px; color: #5f7fa3; }

/* 结算 */
.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}
.score-grid > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .05);
  font-size: 13px;
  color: #a9c6e3;
}
.score-grid b { font-size: 18px; color: var(--gold); font-variant-numeric: tabular-nums; }

.rank {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 800;
  color: var(--blue-soft);
  line-height: 1.6;
}

.hint {
  position: absolute;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 11.5px;
  color: rgba(160, 190, 220, .5);
  pointer-events: none;
  letter-spacing: 1px;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .bar { width: 74px; }
  #hud { gap: 8px; font-size: 12px; padding: 8px 10px; }
  /* 窄屏上 .hud-right 会换行，margin-left:auto 会让它顶出右边界；改为独占一行并自适应 */
  .hud-right { margin-left: 0; width: 100%; justify-content: flex-start; }
  .clock { margin-left: auto; }
  .panel { padding: 20px 18px 18px; }
  .panel h1 { font-size: 21px; }
  .combo { font-size: 26px; top: 96px; }
}
