:root {
  --bg: #12061c;
  --pink: #ff5d8f;
  --gold: #ffd36a;
  --cyan: #5ce1ff;
  --purple: #8b6cff;
  --text: #fff7fb;
  --dim: rgba(255, 247, 251, 0.62);
}

* {
  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: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  background: radial-gradient(ellipse at 50% 20%, #3a1458 0%, #12061c 62%);
}

#stage {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: #12061c;
  box-shadow: 0 0 0 2px rgba(92, 225, 255, 0.22), 0 18px 50px rgba(0, 0, 0, 0.45);
}

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

#touch-left, #touch-right {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
  height: 100%;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 6;
  pointer-events: none;
}

#app.playing #touch-left,
#app.playing #touch-right {
  min-width: 108px;
}

.hidden {
  display: none !important;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(12px + env(safe-area-inset-top)) 18px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 5;
}

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

.hud-left {
  margin-left: 0;
}

.hud-right {
  align-items: flex-end;
  pointer-events: auto;
}

.mission, .level-tag, .hint {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 4, 22, 0.55);
  border: 1px solid rgba(92, 225, 255, 0.28);
  backdrop-filter: blur(8px);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.mission {
  color: var(--gold);
  font-weight: 700;
}

.level-tag {
  width: fit-content;
  color: var(--cyan);
}

.hint {
  color: var(--dim);
  font-size: 12px;
}

.hp {
  display: flex;
  gap: 6px;
  padding: 4px 0;
}

.heart {
  width: 22px;
  height: 20px;
  clip-path: path("M11 19 L2.2 10.4 A5.4 5.4 0 0 1 11 4.2 A5.4 5.4 0 0 1 19.8 10.4 Z");
  background: linear-gradient(180deg, #ff8fb3, #ff3d7a);
  box-shadow: 0 0 10px rgba(255, 93, 143, 0.7);
}

.heart.empty {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

#btn-pause, #btn-codex {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(12, 4, 22, 0.6);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

#audio-dock {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 16;
  pointer-events: auto;
}

#btn-speaker {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(92, 225, 255, 0.35);
  background: rgba(12, 4, 22, 0.72);
  color: var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}

#btn-speaker.muted {
  color: var(--dim);
}

#audio-panel {
  margin-top: 8px;
  width: 230px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(12, 4, 22, 0.92);
  border: 1px solid rgba(92, 225, 255, 0.35);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.audio-row {
  display: grid;
  grid-template-columns: 64px 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--dim);
}

.audio-row:last-child {
  margin-bottom: 0;
}

.audio-row input[type="range"] {
  width: 100%;
  accent-color: #ff8a1a;
}

.audio-row button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  font-size: 11px;
  padding: 3px 0;
  cursor: pointer;
}

.audio-row button.off {
  color: #ff8aa8;
  border-color: rgba(255, 93, 143, 0.5);
}

#joystick {
  pointer-events: auto;
  touch-action: none;
}

.joy-base {
  position: relative;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(139, 108, 255, 0.28), rgba(18, 6, 28, 0.62));
  border: 2px solid rgba(92, 225, 255, 0.45);
  box-shadow: 0 0 24px rgba(92, 225, 255, 0.22), inset 0 0 18px rgba(255, 93, 143, 0.18);
}

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe4f0, #ff5d8f 58%, #a21d4d);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.joy-label {
  position: absolute;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.08em;
  pointer-events: none;
}

.joy-left { left: 10px; top: 50%; transform: translateY(-50%); }
.joy-right { right: 10px; top: 50%; transform: translateY(-50%); }

#action-btns {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#action-btns.hidden {
  display: none !important;
}

#btn-jump, #btn-defend {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(255, 211, 106, 0.55);
  color: #1a0818;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32);
}

#btn-jump {
  background: radial-gradient(circle at 35% 30%, #ffe9b0, #ffd36a 58%, #e09a2a);
}

#btn-defend {
  background: radial-gradient(circle at 35% 30%, #c8f4ff, #5ce1ff 58%, #2aa0c8);
  border-color: rgba(92, 225, 255, 0.7);
}

#btn-jump.held, #btn-defend.held {
  transform: scale(0.94);
  filter: brightness(0.92);
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(10, 3, 18, 0.18), rgba(10, 3, 18, 0.42));
}

#overlay.plain {
  background: rgba(8, 2, 16, 0.72);
  backdrop-filter: blur(6px);
}

#overlay-inner {
  width: min(760px, calc(100% - 32px));
  max-height: calc(100% - 40px);
  overflow: auto;
}

.panel {
  background: linear-gradient(180deg, rgba(38, 16, 64, 0.92), rgba(16, 6, 30, 0.94));
  border: 1px solid rgba(92, 225, 255, 0.35);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(255, 93, 143, 0.12);
  border-radius: 22px;
  padding: 28px 28px 24px;
  text-align: center;
}

.logo {
  font-size: clamp(28px, 6vw, 46px);
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(90deg, #ffd36a, #ff5d8f, #5ce1ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
}

.sub {
  margin-top: 8px;
  color: var(--dim);
  letter-spacing: 0.28em;
  font-size: 13px;
}

.story-kicker {
  color: var(--cyan);
  font-size: 12px;
  letter-spacing: 0.24em;
  margin-bottom: 10px;
}

.story-text {
  font-size: clamp(16px, 2.6vw, 20px);
  line-height: 1.85;
  text-align: left;
  color: #fff4fa;
}

.sys-window {
  border-radius: 18px;
  border: 1px solid rgba(92, 225, 255, 0.7);
  background: linear-gradient(180deg, rgba(12, 36, 58, 0.92), rgba(18, 8, 36, 0.94));
  box-shadow: 0 0 0 1px rgba(255, 93, 143, 0.2), 0 0 48px rgba(92, 225, 255, 0.22);
  padding: 22px 22px 18px;
  text-align: left;
  position: relative;
  overflow: hidden;
}

.sys-window::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    180deg,
    transparent 0 2px,
    rgba(92, 225, 255, 0.04) 2px 3px
  );
  pointer-events: none;
}

.sys-title {
  color: var(--cyan);
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 14px;
  margin-bottom: 12px;
}

.sys-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--dim);
  font-size: 13px;
  margin-bottom: 8px;
}

.sys-q {
  margin: 16px 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
}

button.btn {
  min-width: 132px;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #1a0818;
  background: linear-gradient(90deg, #ffd36a, #ff7aa8);
  box-shadow: 0 8px 20px rgba(255, 93, 143, 0.28);
}

button.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: none;
}

button.btn:active {
  transform: translateY(1px);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #ff6b7d;
  font-size: 12px;
  letter-spacing: 0.16em;
  margin-bottom: 8px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3355;
  box-shadow: 0 0 8px #ff3355;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #12061c;
  align-items: center;
  justify-content: center;
}

.rotate-card {
  text-align: center;
  color: var(--dim);
}

.phone-icon {
  width: 42px;
  height: 70px;
  margin: 0 auto 16px;
  border: 3px solid var(--cyan);
  border-radius: 8px;
  animation: spinphone 1.6s ease-in-out infinite;
}

@keyframes spinphone {
  0%, 30% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (max-width: 820px) {
  #rotate-hint { display: flex; }
}

.lesson-banner {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100% - 48px));
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(12, 4, 22, 0.78);
  border: 1px solid rgba(255, 211, 106, 0.45);
  color: #ffe9b0;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  z-index: 7;
}

.bestiary {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 18px;
  align-items: center;
  text-align: left;
}

.bestiary-art {
  width: 160px;
  height: 160px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 40%, rgba(139, 108, 255, 0.35), rgba(8, 2, 16, 0.9));
  border: 1px solid rgba(92, 225, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bestiary h2 {
  font-size: 24px;
  margin: 4px 0 10px;
  color: #fff;
}

.bestiary .tag {
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.18em;
}

.bestiary p {
  font-size: 15px;
  line-height: 1.7;
  color: #fff4fa;
  margin-bottom: 8px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.level-card {
  text-align: left;
  border: 1px solid rgba(92, 225, 255, 0.35);
  background: linear-gradient(180deg, rgba(38, 16, 64, 0.88), rgba(16, 6, 30, 0.94));
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px 12px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.level-card:hover:not(.locked) {
  border-color: rgba(255, 211, 106, 0.7);
}

.level-card.locked {
  opacity: 0.48;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.lc-index {
  color: var(--cyan);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.lc-name {
  font-size: 18px;
  font-weight: 800;
  margin: 6px 0 8px;
}

.lc-state {
  font-size: 12px;
  color: var(--gold);
}

.level-card.locked .lc-state {
  color: var(--dim);
}

.select-hint {
  margin-top: 12px;
  color: rgba(255, 247, 251, 0.72);
  line-height: 1.7;
  font-size: 14px;
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.codex-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(92, 225, 255, 0.3);
  background: rgba(12, 4, 22, 0.45);
}

.codex-card.locked {
  opacity: 0.42;
  filter: grayscale(1);
}

.codex-card h3 {
  font-size: 15px;
  margin-bottom: 4px;
}

.codex-card p {
  font-size: 12px;
  line-height: 1.55;
  color: rgba(255, 247, 251, 0.72);
}

.codex-thumb {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 40%, rgba(139, 108, 255, 0.28), rgba(8, 2, 16, 0.9));
}

#cinema-ui {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: calc(16px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom));
}

#cinema-skip {
  pointer-events: auto;
  align-self: flex-end;
  margin-bottom: auto;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(12, 4, 22, 0.55);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  letter-spacing: 0.12em;
  cursor: pointer;
}

#cinema-caption {
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(8, 2, 16, 0.72);
  border: 1px solid rgba(92, 225, 255, 0.28);
  backdrop-filter: blur(8px);
  font-size: clamp(14px, 2.3vw, 18px);
  line-height: 1.7;
  text-align: center;
  color: #fff7fb;
}

@media (max-width: 640px) {
  .panel { padding: 20px 16px 16px; }
  .joy-base { width: 96px; height: 96px; }
  #btn-jump, #btn-defend { width: 64px; height: 64px; font-size: 16px; }
  .lesson-banner {
    max-width: calc(100% - 28px);
    bottom: 12px;
    font-size: 13px;
  }
  .bestiary {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .level-grid {
    grid-template-columns: 1fr;
  }
  .codex-grid {
    grid-template-columns: 1fr;
  }
}
