/* style.css — 太空防御者：深空霓虹街机舷窗 + 双翼牌匾沉浸舞台。
   桌面端（≥900px）左中右三区对称；移动端收折为掌机操作台并预留底部广告安全区。 */

:root {
  --space-0: #05081c;
  --space-1: #0b1130;
  --space-2: #171a44;
  --space-3: #2a1b52;
  --cyan: #4de2ff;
  --cyan-soft: #7ef9ff;
  --amber: #ffb703;
  --gold: #ffd166;
  --rose: #ff5d8f;
  --violet: #b48cff;
  --ink: #eaf2ff;
  --ink-dim: #9fb0d8;
  --plate-1: #1c2350;
  --plate-2: #121735;
  --plate-edge: rgba(126, 249, 255, 0.22);
  --shadow-plate: 0 18px 40px rgba(3, 6, 22, 0.55);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--space-0);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* 环境舞台：深空渐变 + 光晕 + 细噪点，拒绝死板平铺 */
#game-app {
  position: relative;
  min-height: 100dvh;
  padding-top: 14px;
  padding-left: clamp(12px, 3vw, 40px);
  padding-right: clamp(12px, 3vw, 40px);
  /* 移动端底部广告安全避让区：绝不让未来横幅遮挡操作台 */
  padding-bottom: max(68px, calc(20px + env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(1200px 700px at 18% -8%, rgba(88, 62, 190, 0.42), transparent 62%),
    radial-gradient(1000px 620px at 88% 12%, rgba(40, 120, 200, 0.30), transparent 60%),
    radial-gradient(900px 700px at 50% 108%, rgba(220, 84, 160, 0.22), transparent 62%),
    linear-gradient(170deg, var(--space-1) 0%, var(--space-2) 46%, var(--space-3) 100%);
  overflow-x: hidden;
}

#game-app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: drift 26s ease-in-out infinite alternate;
}

@keyframes drift {
  from {
    transform: translate3d(-8px, -6px, 0) scale(1.02);
  }
  to {
    transform: translate3d(10px, 8px, 0) scale(1.06);
  }
}

/* ---------------------------------------------------------- 顶边状态条 */

#stage-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(38, 46, 96, 0.92), rgba(16, 20, 48, 0.94));
  border: 1px solid rgba(126, 249, 255, 0.2);
  box-shadow: var(--shadow-plate), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

#app-title {
  margin: 0;
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: center;
  font-size: clamp(16px, 2.4vw, 22px);
  letter-spacing: 0.06em;
}

#app-title-main {
  color: var(--cyan-soft);
  text-shadow: 0 0 18px rgba(78, 226, 255, 0.5);
}

#app-subtitle {
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.18em;
}

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

.bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(126, 249, 255, 0.24);
  background: linear-gradient(180deg, #2b3568, #1a2149);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 6px 14px rgba(3, 6, 22, 0.45);
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.bar-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(126, 249, 255, 0.55);
}

.bar-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.bar-text {
  font-size: 13px;
}

/* -------------------------------------------------------------- 模式条 */

#mode-bar {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 8px;
  justify-content: center;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.mode-chip {
  padding: 8px 18px;
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(126, 249, 255, 0.2);
  background: linear-gradient(180deg, rgba(40, 48, 100, 0.9), rgba(18, 22, 52, 0.92));
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: transform 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.mode-chip:hover {
  transform: translateY(-2px);
  color: var(--ink);
}

.mode-chip.is-active {
  color: var(--space-0);
  border-color: transparent;
  background: linear-gradient(180deg, var(--cyan-soft), var(--cyan));
  box-shadow: 0 10px 22px rgba(78, 226, 255, 0.32);
  font-weight: 700;
}

/* -------------------------------------------------------------- 主舞台 */

#stage-core {
  position: relative;
  z-index: 2;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.wing {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(34, 42, 90, 0.9), rgba(14, 18, 44, 0.94));
  border: 1px solid var(--plate-edge);
  box-shadow: var(--shadow-plate), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.plaque-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(58, 70, 132, 0.5), rgba(22, 28, 62, 0.6));
  border: 1px solid rgba(126, 249, 255, 0.14);
}

.plaque-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
}

.plaque-value {
  font-family: var(--mono);
  font-size: 17px;
  color: var(--cyan-soft);
  text-shadow: 0 0 14px rgba(78, 226, 255, 0.35);
}

.plaque-value.bump {
  animation: bump 0.28s ease;
}

@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.22);
  }
  100% {
    transform: scale(1);
  }
}

.plaque-value-sm {
  font-size: 14px;
}

.wing-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.key-btn {
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(126, 249, 255, 0.24);
  background: linear-gradient(180deg, #33407a, #1b2149);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 18px rgba(3, 6, 22, 0.5);
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

.key-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.key-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.55);
}

.key-primary {
  background: linear-gradient(180deg, var(--cyan-soft), #2fb6dd);
  color: #04202c;
  font-weight: 700;
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 12px 24px rgba(78, 226, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.hint-text {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-dim);
}

/* ---------------------------------------------------------- 舷窗舞台 */

#arena {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* 框体宽度由"舷窗可用高度反推"决定，保证 canvas 100% 填满、不出现空隙暗条 */
#crt-bezel {
  position: relative;
  width: min(100%, calc((100dvh - 250px) * 0.75 + 20px));
  padding: 10px;
  border-radius: 26px;
  background: linear-gradient(180deg, #2a3268, #10142f);
  border: 1px solid rgba(126, 249, 255, 0.28);
  box-shadow: 0 26px 60px rgba(3, 6, 22, 0.65), inset 0 2px 0 rgba(255, 255, 255, 0.14),
    0 0 60px rgba(78, 226, 255, 0.14);
}

#crt-bezel::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 18px;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

#stage-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 18px;
  background: #05081c;
  touch-action: none;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6);
}

#toast {
  min-height: 26px;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--gold);
  background: rgba(8, 12, 32, 0.7);
  border: 1px solid rgba(255, 209, 102, 0.28);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.is-on {
  opacity: 1;
  transform: translateY(0);
}

/* ------------------------------------------------------- 右翼战况牌匾 */

.shield-cells {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.shield-cell {
  width: 22px;
  height: 12px;
  border-radius: 5px;
  background: rgba(126, 249, 255, 0.14);
  border: 1px solid rgba(126, 249, 255, 0.3);
}

.shield-cell.is-on {
  background: linear-gradient(180deg, var(--cyan-soft), var(--cyan));
  box-shadow: 0 0 12px rgba(78, 226, 255, 0.6);
}

.meter {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(58, 70, 132, 0.5), rgba(22, 28, 62, 0.6));
  border: 1px solid rgba(126, 249, 255, 0.14);
}

.meter-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(6, 10, 28, 0.8);
  overflow: hidden;
  border: 1px solid rgba(126, 249, 255, 0.16);
}

.meter-track > i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--cyan-soft));
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.5);
  transition: width 0.16s ease;
}

.meter-track.is-full > i {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.45);
  }
}

.gauge-row {
  display: flex;
  gap: 8px;
}

.gauge {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(58, 70, 132, 0.45), rgba(22, 28, 62, 0.6));
  border: 1px solid rgba(126, 249, 255, 0.12);
}

.gauge-value {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--amber);
}

.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 9px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(58, 70, 132, 0.4), rgba(22, 28, 62, 0.55));
  border: 1px solid rgba(126, 249, 255, 0.12);
}

.score-line {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-dim);
}

.score-line strong {
  font-family: var(--mono);
  color: var(--ink);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-dim);
  cursor: pointer;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: #2fb6dd;
}

/* ------------------------------------------------------------ 操作台 */

#control-deck {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.pad {
  display: flex;
  gap: 10px;
}

.pad-btn {
  min-height: 52px;
  min-width: 72px;
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid rgba(126, 249, 255, 0.24);
  background: linear-gradient(180deg, #33407a, #1b2149);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 18px rgba(3, 6, 22, 0.5);
  transition: transform 0.12s ease;
}

.pad-btn:active,
.pad-btn.is-held {
  transform: translateY(2px);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.55);
}

.pad-btn kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-dim);
}

.pad-primary {
  background: linear-gradient(180deg, var(--cyan-soft), #2fb6dd);
  color: #04202c;
  font-weight: 700;
}

.pad-overload {
  background: linear-gradient(180deg, var(--gold), #e08a00);
  color: #2a1500;
  font-weight: 700;
}

/* ------------------------------------------------------------ 浮层 */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 7, 20, 0.72);
  backdrop-filter: blur(6px);
}

.overlay.is-open {
  display: flex;
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.panel {
  width: min(560px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  padding: 22px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(40, 50, 106, 0.96), rgba(14, 18, 44, 0.98));
  border: 1px solid rgba(126, 249, 255, 0.28);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.panel-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--cyan);
}

.panel-title {
  margin: 6px 0 8px;
  font-size: 22px;
  color: var(--cyan-soft);
  text-shadow: 0 0 20px rgba(78, 226, 255, 0.4);
}

.panel-desc {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-dim);
}

.stars-line {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--gold);
}

.wave-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.wave-cell {
  position: relative;
  min-height: 62px;
  padding: 6px 4px;
  border-radius: 14px;
  border: 1px solid rgba(126, 249, 255, 0.2);
  background: linear-gradient(180deg, #2f3a72, #1a2048);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 6px 14px rgba(3, 6, 22, 0.4);
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.wave-cell:hover {
  transform: translateY(-2px);
}

.wave-cell.is-selected {
  border-color: var(--cyan-soft);
  box-shadow: 0 0 0 2px rgba(126, 249, 255, 0.35), 0 8px 18px rgba(78, 226, 255, 0.25);
}

.wave-cell.is-locked {
  opacity: 0.42;
  cursor: not-allowed;
}

.wave-cell.is-boss {
  background: linear-gradient(180deg, #6a2b4a, #35162e);
}

.wave-cell .wave-no {
  font-family: var(--mono);
  font-size: 15px;
}

.wave-cell .wave-stars {
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 0.1em;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid rgba(126, 249, 255, 0.24);
  background: linear-gradient(180deg, #33407a, #1b2149);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 8px 18px rgba(3, 6, 22, 0.45);
  transition: transform 0.14s ease, filter 0.14s ease;
}

.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.12);
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--cyan-soft), #2fb6dd);
  color: #04202c;
  font-weight: 700;
}

.result-stars {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 4px 0 14px;
}

.result-stars .star {
  font-size: 34px;
  color: rgba(255, 255, 255, 0.16);
  transition: transform 0.3s ease, color 0.3s ease, text-shadow 0.3s ease;
}

.result-stars .star.is-on {
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 209, 102, 0.7);
  animation: starPop 0.42s ease backwards;
}

@keyframes starPop {
  0% {
    transform: scale(0.2) rotate(-25deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.25) rotate(6deg);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(10, 14, 36, 0.6);
  border: 1px solid rgba(126, 249, 255, 0.12);
  font-size: 13px;
  color: var(--ink-dim);
}

.result-row strong {
  font-family: var(--mono);
  color: var(--ink);
}

.result-hint {
  margin: 12px 0 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--gold);
}

.help-list {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink-dim);
}

/* --------------------------------------------------------- 响应式 */

@media (min-width: 900px) {
  #stage-core {
    grid-template-columns: 236px minmax(0, 1fr) 236px;
    align-items: stretch;
  }

  #control-deck {
    display: none;
  }
}

@media (max-width: 899px) {
  #stage-core {
    grid-template-columns: 1fr;
  }

  #arena {
    order: -1;
  }

  .wing {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  .wing > * {
    flex: 1 1 140px;
  }

  .wing-actions {
    flex-direction: row;
    flex: 1 1 100%;
  }

  #crt-bezel {
    width: min(100%, calc((100dvh - 320px) * 0.75 + 20px));
  }

  /* 触控操作台常驻在广告安全区之上：既不会被横幅遮住，也不用翻页去找发射键 */
  #control-deck {
    position: sticky;
    bottom: max(68px, calc(20px + env(safe-area-inset-bottom)));
    z-index: 5;
    padding: 8px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(34, 42, 90, 0.94), rgba(14, 18, 44, 0.96));
    border: 1px solid var(--plate-edge);
    box-shadow: var(--shadow-plate);
  }
}

@media (max-width: 560px) {
  #app-subtitle {
    display: none;
  }

  .bar-text {
    display: none;
  }

  #crt-bezel {
    width: min(100%, calc((100dvh - 300px) * 0.75 + 20px));
  }

  .result-rows {
    grid-template-columns: 1fr;
  }

  .wave-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .pad-btn {
    min-width: 62px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  #game-app::before {
    animation: none;
  }
}
