/* ============================================================
 * style.css — 《霓虹坦克》科技风 UI（深空 + 霓虹描边 + 扫描线）
 * ============================================================ */
:root {
  --bg: #070B14; --grid: #101A2E;
  --cyan: #00F0FF; --red: #FF3860; --purple: #B44CFF;
  --warn: #FFD24A; --xp: #3DFFA2; --text: #D7E5FF;
}
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }

body {
  background: #03050A;
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  font-family: 'Segoe UI', 'Microsoft YaHei', Consolas, monospace;
  color: var(--text);
  overflow: hidden;
  position: fixed; width: 100%; height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
html { height: 100%; overscroll-behavior: none; }
/* 去除移动端点按 300ms 延迟 + 高亮 */
button, .btn, .dbtn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* 16:9 letterbox 居中 */
#wrap {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  /* 老内核（不支持 aspect-ratio）用 calc 兜底，效果等价 16:9 */
  height: calc(min(100vw, 100vh * 16 / 9) * 9 / 16);
  aspect-ratio: 16 / 9;
  box-shadow: 0 0 60px rgba(0, 240, 255, 0.12);
}
canvas#game { width: 100%; height: 100%; display: block; background: var(--bg); touch-action: none; }

/* CRT 扫描线 */
#scanlines {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none; z-index: 30;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.12) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

/* ---------- 界面层 ---------- */
.screen {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 20;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(4, 7, 14, 0.88);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.screen.show { display: flex; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* —— 主菜单整体布局（grid 三段：头部 / 主体 / 底部） —— */
#screen-menu {
  justify-content: flex-start;
  padding: 26px 36px 20px;
  overflow: hidden;
}

/* 头部：标题 + 副标题 + 战绩 */
.menu-header {
  position: relative; z-index: 3;
  text-align: center;
  margin-bottom: 14px;
}
.menu-header .title { margin-bottom: 4px; }
.menu-header .subtitle { margin: 2px 0 4px; }
.menu-header #menu-hiscore { margin: 0; }

/* 主体：分组按钮 */
.menu-body {
  position: relative; z-index: 3;
  flex: 1 1 auto;
  width: 100%;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow-y: auto;
  padding: 4px 0;
}
.menu-body::-webkit-scrollbar { width: 6px; }
.menu-body::-webkit-scrollbar-thumb { background: rgba(0,240,255,0.3); border-radius: 3px; }

/* 分组标签 */
.menu-section {
  width: 100%;
  max-width: 880px;
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
}
.section-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; letter-spacing: 5px;
  color: var(--text);
  opacity: 0.55;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.section-label .lbl-dot {
  width: 5px; height: 5px;
  background: var(--cyan); border-radius: 50%;
  box-shadow: 0 0 6px var(--cyan);
}

/* 按钮网格 */
.menu-btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 660px;
}
.menu-btn-grid.two-col { grid-template-columns: repeat(2, 1fr); max-width: 440px; }

/* 底部 */
.menu-footer {
  position: relative; z-index: 3;
  margin-top: 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}

/* 标题 */
.title {
  position: relative;
  font-size: 64px; letter-spacing: 14px; font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 12px var(--cyan), 0 0 48px rgba(0,240,255,0.55);
  animation: breathe 2.4s ease-in-out infinite;
  z-index: 2;
  margin: 0;
}
.title span { color: var(--red); text-shadow: 0 0 12px var(--red), 0 0 48px rgba(255,56,96,0.5); }
@keyframes breathe {
  0%, 100% { text-shadow: 0 0 12px var(--cyan), 0 0 48px rgba(0,240,255,0.55); }
  50% { text-shadow: 0 0 26px var(--cyan), 0 0 90px rgba(0,240,255,0.9); }
}

/* 标题 Glitch 故障（::before / ::after 错位副本） */
.title::before, .title::after {
  content: attr(data-text);
  position: absolute; top: 0; left: 0; right: 0;
  pointer-events: none;
  clip-path: inset(0 0 0 0);
}
.title::before {
  color: var(--red);
  text-shadow: none;
  animation: glitchTop 4.2s steps(2, end) infinite;
  opacity: 0.65;
  mix-blend-mode: screen;
}
.title::after {
  color: var(--purple);
  text-shadow: none;
  animation: glitchBot 3.7s steps(2, end) infinite;
  opacity: 0.55;
  mix-blend-mode: screen;
}
@keyframes glitchTop {
  0%, 92%, 100% { transform: translate(0, 0); clip-path: inset(0 0 95% 0); }
  93% { transform: translate(-3px, -2px); clip-path: inset(0 0 88% 0); }
  95% { transform: translate(2px, 1px); clip-path: inset(0 0 92% 0); }
  97% { transform: translate(-2px, 0); clip-path: inset(0 0 96% 0); }
}
@keyframes glitchBot {
  0%, 90%, 100% { transform: translate(0, 0); clip-path: inset(95% 0 0 0); }
  91% { transform: translate(3px, 2px); clip-path: inset(88% 0 0 0); }
  94% { transform: translate(-2px, -1px); clip-path: inset(92% 0 0 0); }
  98% { transform: translate(1px, 0); clip-path: inset(96% 0 0 0); }
}

/* —— 主菜单：Canvas 动态星空背景 —— */
#menu-space {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  display: block;
}

/* —— 主菜单：四角科幻角标 —— */
.menu-corner {
  position: absolute;
  width: 48px; height: 48px;
  z-index: 1;
  pointer-events: none;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}
.menu-corner::before {
  content: ''; position: absolute; top: 5px; right: 5px; bottom: 5px; left: 5px;
  border: 1px solid rgba(0, 240, 255, 0.45);
}
.menu-corner::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px;
  background: var(--cyan); box-shadow: 0 0 6px var(--cyan);
  border-radius: 50%;
  animation: cornerBlink 2s ease-in-out infinite;
}
@keyframes cornerBlink { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
.menu-corner.top-left     { top: 16px; left: 16px; clip-path: polygon(0 0, 100% 0, 100% 22%, 78% 22%, 78% 100%, 0 100%); }
.menu-corner.top-right    { top: 16px; right: 16px; clip-path: polygon(0 0, 100% 0, 100% 100%, 22% 100%, 22% 78%, 0 78%); }
.menu-corner.bottom-left  { bottom: 16px; left: 16px; clip-path: polygon(0 0, 78% 0, 78% 22%, 100% 22%, 100% 100%, 0 100%); }
.menu-corner.bottom-right { bottom: 16px; right: 16px; clip-path: polygon(22% 0, 100% 0, 100% 100%, 0 100%, 0 22%, 22% 22%); }

/* —— 作者专区（独立醒目卡片，右下角） —— */
.menu-author-card {
  position: absolute;
  right: 24px; bottom: 22px;
  z-index: 4;
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 32px 10px;
  min-width: 220px;
  background: linear-gradient(180deg, rgba(0,240,255,0.10), rgba(180,76,255,0.10));
  border: 1px solid var(--cyan);
  border-radius: 2px;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.4), inset 0 0 20px rgba(180, 76, 255, 0.08);
  text-align: center;
  overflow: hidden;
}
.menu-author-card .author-glow {
  position: absolute; top: 0; left: -100%;
  width: 80%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0,240,255,0.25), transparent);
  animation: authorSweep 4s linear infinite;
  pointer-events: none;
}
@keyframes authorSweep {
  0%   { left: -100%; }
  60%  { left: 130%; }
  100% { left: 130%; }
}
.menu-author-card .author-label {
  font-size: 11px; letter-spacing: 8px;
  color: var(--text);
  opacity: 0.75;
  margin-bottom: 4px;
}
.menu-author-card .author-name {
  font-size: 36px; font-weight: 900;
  letter-spacing: 14px;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--red), var(--cyan));
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 8px rgba(0,240,255,0.6)) drop-shadow(0 0 14px rgba(180,76,255,0.4));
  animation: authorFlow 4.5s linear infinite;
  margin: 2px 0 4px;
  position: relative; z-index: 1;
}
@keyframes authorFlow {
  0%   { background-position: 0% 0; }
  100% { background-position: 300% 0; }
}
.menu-author-card .author-tagline {
  font-size: 10px; letter-spacing: 4px;
  color: var(--text);
  opacity: 0.6;
  position: relative; z-index: 1;
}

.subtitle { font-size: 13px; letter-spacing: 14px; margin: 2px 0; color: var(--text); opacity: 0.75; }
#menu-hiscore { font-size: 13px; letter-spacing: 2px; opacity: 0.8; }

/* 按钮 */
.btn {
  font: 700 17px/1 'Segoe UI', 'Microsoft YaHei', monospace;
  letter-spacing: 4px;
  padding: 11px 18px;
  margin: 0;
  color: var(--cyan); background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.55); cursor: pointer;
  transition: all 0.18s ease;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  text-align: center;
  position: relative;
}
.btn:hover { background: rgba(0, 240, 255, 0.18); box-shadow: 0 0 18px rgba(0,240,255,0.5); transform: translateY(-1px); }
.btn.primary { color: #061018; background: var(--cyan); border-color: var(--cyan); font-weight: 800; }
.btn.primary:hover { box-shadow: 0 0 26px rgba(0,240,255,0.85); }
.btn.accent-purple {
  color: var(--purple);
  background: rgba(180, 76, 255, 0.08);
  border-color: rgba(180, 76, 255, 0.55);
}
.btn.accent-purple:hover { background: rgba(180, 76, 255, 0.2); box-shadow: 0 0 18px rgba(180,76,255,0.5); }
.menu-btns { display: flex; }
.menu-btns.column { flex-direction: column; }

/* 关卡选择 */
#level-panel { display: none; width: 100%; max-width: 720px; }
#level-panel.show { display: block; animation: fadeIn 0.25s ease; }
#level-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.level-btn {
  position: relative; width: 100%; aspect-ratio: 1;
  min-height: 44px;
  font: 700 17px Consolas, monospace; color: var(--cyan);
  background: rgba(0,240,255,0.05); border: 1px solid rgba(0,240,255,0.4);
  cursor: pointer; transition: 0.15s;
}
.level-btn:hover:not(.locked) { background: rgba(0,240,255,0.2); box-shadow: 0 0 12px rgba(0,240,255,0.5); }
.level-btn.locked { opacity: 0.25; cursor: not-allowed; }
.level-btn .stars { position: absolute; bottom: 1px; left: 0; right: 0; font-size: 9px; color: var(--warn); letter-spacing: 0; }

/* Boss 图鉴 */
#boss-gallery { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.boss-badge {
  padding: 5px 14px; font-size: 11px; letter-spacing: 2px;
  color: rgba(215,229,255,0.35); border: 1px dashed rgba(180,76,255,0.35);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.boss-badge.killed {
  color: var(--purple); border: 1px solid var(--purple);
  text-shadow: 0 0 8px var(--purple); box-shadow: 0 0 14px rgba(180,76,255,0.35) inset;
}

/* 设置 */
.settings { display: flex; gap: 24px; font-size: 12px; letter-spacing: 2px; }
.settings label { display: flex; align-items: center; gap: 6px; }
input[type="range"] { accent-color: var(--cyan); width: 100px; }
.controls-hint { font-size: 11px; letter-spacing: 1px; opacity: 0.5; text-align: center; }
.controls-hint.sub { opacity: 0.35; font-size: 10px; }

/* 横幅 */
#banner {
  position: absolute; top: 22%; left: 0; right: 0; z-index: 25;
  text-align: center; pointer-events: none; opacity: 0;
}
#banner.show { animation: bannerIn 0.4s ease forwards; }
@keyframes bannerIn {
  from { opacity: 0; transform: scale(1.4); letter-spacing: 30px; }
  to { opacity: 1; transform: scale(1); }
}
#banner-text {
  font-size: 44px; font-weight: 900; letter-spacing: 12px;
  color: var(--warn); text-shadow: 0 0 18px var(--warn);
}
#banner-sub { font-size: 16px; letter-spacing: 6px; margin-top: 6px; color: var(--text); opacity: 0.85; }

/* 升级三选一 */
#screen-levelup h2 { font-size: 26px; letter-spacing: 8px; color: var(--xp); text-shadow: 0 0 14px var(--xp); margin-bottom: 34px; }
#levelup-cards { display: flex; gap: 26px; }
.card {
  --rc: var(--text);
  width: 240px; min-height: 300px; padding: 30px 22px;
  background: rgba(10, 16, 28, 0.95);
  border: 1px solid var(--rc);
  box-shadow: 0 0 18px rgba(0,240,255,0.35), inset 0 0 26px rgba(0,0,0,0.6);
  box-shadow: 0 0 18px color-mix(in srgb, var(--rc) 35%, transparent), inset 0 0 26px rgba(0,0,0,0.6);
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
  cursor: pointer; text-align: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: cardIn 0.35s ease backwards;
}
.card:nth-child(2) { animation-delay: 0.08s; }
.card:nth-child(3) { animation-delay: 0.16s; }
.card:nth-child(4) { animation-delay: 0.24s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; } }
.card:hover { transform: translateY(-10px) scale(1.04); box-shadow: 0 0 40px rgba(0,240,255,0.65); box-shadow: 0 0 40px color-mix(in srgb, var(--rc) 65%, transparent); }
.card-rarity { font-size: 12px; letter-spacing: 4px; margin-bottom: 14px; opacity: 0.9; }
.card-name { font-size: 22px; font-weight: 800; color: var(--rc); text-shadow: 0 0 10px var(--rc); margin-bottom: 16px; }
.card-desc { font-size: 14px; line-height: 1.7; opacity: 0.85; }
.card.syn { border-width: 2px; animation: cardIn 0.35s ease backwards, synGlow 1.2s ease-in-out infinite alternate; }
@keyframes synGlow { from { box-shadow: 0 0 14px var(--rc); } to { box-shadow: 0 0 44px var(--rc); } }

/* 结算 */
#result-title { font-size: 42px; letter-spacing: 10px; margin-bottom: 26px; }
#result-title.win { color: var(--xp); text-shadow: 0 0 20px var(--xp); }
#result-title.lose { color: var(--red); text-shadow: 0 0 20px var(--red); }
#result-rows { border-collapse: collapse; margin-bottom: 30px; }
#result-rows td { padding: 8px 26px; font-size: 16px; letter-spacing: 2px; border-bottom: 1px solid rgba(215,229,255,0.12); }
#result-rows td:last-child { color: var(--cyan); font-weight: 700; text-align: right; }

/* 装置养成面板 */
#screen-gadget { padding: 28px 48px; }
.screen-title {
  font-size: 32px; letter-spacing: 10px; font-weight: 900;
  color: var(--cyan); text-shadow: 0 0 14px var(--cyan);
  margin-bottom: 8px;
}
.gadget-top {
  width: 100%; max-width: 900px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 26px;
}
.gadget-token {
  font: 700 20px Consolas, monospace;
  letter-spacing: 3px;
  color: var(--warn);
  padding: 8px 20px;
  border: 1px solid rgba(255,210,74,0.5);
  background: rgba(255,210,74,0.06);
  text-shadow: 0 0 10px var(--warn);
}
#gadget-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 900px;
  margin-bottom: 30px;
}
.gadget-card {
  position: relative;
  padding: 22px 18px 20px;
  background: rgba(10, 16, 28, 0.95);
  border: 1px solid var(--rc);
  box-shadow: 0 0 16px rgba(0,240,255,0.3), inset 0 0 22px rgba(0,0,0,0.6);
  box-shadow: 0 0 16px color-mix(in srgb, var(--rc) 30%, transparent), inset 0 0 22px rgba(0,0,0,0.6);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  text-align: center;
}
.gadget-card .gadget-icon {
  font-size: 42px; line-height: 1;
  color: var(--rc);
  text-shadow: 0 0 14px var(--rc);
  margin-bottom: 10px;
}
.gadget-card .gadget-ring {
  width: 72px; height: 72px; margin: 0 auto 8px;
  border: 2px solid var(--rc);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 14px rgba(0,240,255,0.45) inset;
  box-shadow: 0 0 14px color-mix(in srgb, var(--rc) 45%, transparent) inset;
}
.gadget-card .gadget-name {
  font-size: 18px; font-weight: 800; letter-spacing: 3px;
  color: var(--rc); text-shadow: 0 0 10px var(--rc);
  margin-bottom: 6px;
}
.gadget-card .gadget-level {
  font-size: 13px; letter-spacing: 2px;
  color: var(--text); opacity: 0.8;
  margin-bottom: 10px;
}
.gadget-card .gadget-level span { color: var(--rc); font-weight: 700; font-size: 16px; }
.gadget-card .gadget-desc {
  font-size: 12px; line-height: 1.6;
  color: var(--text); opacity: 0.82;
  min-height: 48px;
  margin-bottom: 14px;
  padding: 0 4px;
}
.gadget-card .gadget-btn {
  width: 100%;
  padding: 9px 0;
  font: 700 13px/1 'Segoe UI', monospace;
  letter-spacing: 3px;
  color: var(--rc);
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--rc);
  cursor: pointer;
  transition: all 0.15s ease;
}
.gadget-card .gadget-btn:hover:not(:disabled) {
  background: rgba(0,240,255,0.18);
  background: color-mix(in srgb, var(--rc) 18%, transparent);
  box-shadow: 0 0 14px rgba(0,240,255,0.5);
  box-shadow: 0 0 14px color-mix(in srgb, var(--rc) 50%, transparent);
}
.gadget-card .gadget-btn:disabled {
  opacity: 0.4; cursor: not-allowed;
}

/* 升级失败抖动 */
.shake-err { animation: shakeErr 0.4s ease; }
@keyframes shakeErr {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}

/* ============================================================
 * 地图编辑器（霓虹科技风）
 * ============================================================ */
#screen-editor {
  justify-content: flex-start;
  padding: 16px 24px 20px;
  background: rgba(3, 6, 14, 0.92);
}
#screen-editor.show { display: flex; }

.editor-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow: 0 0 26px rgba(0, 240, 255, 0.22), inset 0 0 36px rgba(0, 240, 255, 0.06);
  padding: 12px 14px;
  clip-path: polygon(18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%, 0 18px);
  background: linear-gradient(180deg, rgba(8,14,28,0.96), rgba(4,8,18,0.98));
}

.editor-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px dashed rgba(0, 240, 255, 0.2);
  padding-bottom: 10px;
}
.screen-title {
  font-size: 22px;
  letter-spacing: 6px;
  font-weight: 800;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
  margin: 0;
}
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.editor-actions .btn {
  padding: 8px 18px;
  margin: 0;
  font-size: 13px;
  letter-spacing: 3px;
}
.ed-input {
  height: 38px;
  padding: 0 12px;
  min-width: 180px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: var(--text);
  font: 600 13px/1 'Segoe UI','Microsoft YaHei',monospace;
  letter-spacing: 2px;
  outline: none;
  transition: all 0.18s ease;
}
.ed-input::placeholder { opacity: 0.5; }
.ed-input:focus { border-color: var(--cyan); box-shadow: 0 0 12px rgba(0,240,255,0.45); }

.ed-cb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  height: 38px;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--text);
  cursor: pointer;
  border: 1px solid rgba(180,76,255,0.4);
  background: rgba(180,76,255,0.06);
}
.ed-cb input { accent-color: var(--purple); transform: scale(1.15); }

.editor-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 180px 1fr 240px;
  gap: 12px;
  min-height: 0;
}

/* 调色板 */
.editor-palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px;
  border: 1px solid rgba(0, 240, 255, 0.25);
  background: rgba(6,12,22,0.65);
  overflow-y: auto;
}
.pal-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(0,240,255,0.25);
  color: var(--text);
  cursor: pointer;
  font: 600 12px/1.2 'Segoe UI','Microsoft YaHei',monospace;
  letter-spacing: 2px;
  transition: all 0.15s ease;
}
.pal-btn:hover { border-color: var(--cyan); background: rgba(0,240,255,0.08); }
.pal-btn.active {
  border-color: var(--cyan);
  background: rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 12px rgba(0,240,255,0.4);
  color: var(--cyan);
}
.pal-swatch {
  width: 28px; height: 28px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1) inset;
}

/* 画布容器居中 */
#ed-canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #06090F;
  image-rendering: pixelated;
  border: 1px solid rgba(0, 240, 255, 0.3);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0,240,255,0.15);
  cursor: crosshair;
  display: block;
  margin: 0 auto;
}

/* 侧边栏 */
.editor-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.ed-slot-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--purple);
  text-shadow: 0 0 8px rgba(180,76,255,0.7);
  padding: 4px 0;
}
.ed-slotlist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
  flex: 1 1 auto;
}
.ed-slot {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(180,76,255,0.25);
  cursor: pointer;
  transition: all 0.15s ease;
}
.ed-slot:hover:not(.empty) {
  border-color: var(--purple);
  background: rgba(180,76,255,0.1);
}
.ed-slot.active {
  border-color: var(--cyan);
  background: rgba(0,240,255,0.1);
  box-shadow: 0 0 10px rgba(0,240,255,0.35);
}
.ed-slot.empty { opacity: 0.45; cursor: default; }
.ed-slot-n {
  grid-row: 1 / 3;
  font-size: 16px;
  font-weight: 800;
  color: var(--purple);
  text-shadow: 0 0 8px var(--purple);
}
.ed-slot-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-slot-sz {
  grid-column: 2 / 3;
  font-size: 11px;
  color: var(--text);
  opacity: 0.65;
  letter-spacing: 1px;
}
.ed-slot-del {
  grid-column: 3 / 4;
  grid-row: 1 / 3;
  padding: 4px 7px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--red);
  background: transparent;
  border: 1px solid rgba(255,56,96,0.45);
  cursor: pointer;
  transition: all 0.15s ease;
}
.ed-slot-del:hover { background: rgba(255,56,96,0.15); box-shadow: 0 0 10px rgba(255,56,96,0.5); }

.ed-tips {
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.7;
  letter-spacing: 1px;
  color: var(--text);
  opacity: 0.82;
  background: rgba(0,0,0,0.45);
  border: 1px dashed rgba(0,240,255,0.25);
}
.ed-tips p { margin: 2px 0; }

/* Rush 三选一面板样式补充（与 gadget-card 同风格差异化） */
#screen-rushpick .screen-title { text-align: center; color: var(--red); text-shadow: 0 0 12px var(--red); }
#rush-back { margin-top: 8px; }
.rush-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 880px;
  margin: 18px 0 8px;
}
.rush-card {
  --rc: var(--cyan);
  padding: 22px 18px;
  background: rgba(10, 16, 28, 0.95);
  border: 1px solid var(--rc);
  box-shadow: 0 0 16px rgba(0,240,255,0.3), inset 0 0 22px rgba(0,0,0,0.6);
  box-shadow: 0 0 16px color-mix(in srgb, var(--rc) 30%, transparent), inset 0 0 22px rgba(0,0,0,0.6);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
}
.rush-card[data-tier="mini"]    { --rc: var(--cyan); }
.rush-card[data-tier="normal"]  { --rc: var(--purple); }
.rush-card[data-tier="insane"]  { --rc: var(--red); }
.rush-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 0 28px rgba(0,240,255,0.55), inset 0 0 22px rgba(0,0,0,0.6);
  box-shadow: 0 0 28px color-mix(in srgb, var(--rc) 55%, transparent), inset 0 0 22px rgba(0,0,0,0.6);
}
.rush-card .rush-name { font-size: 20px; font-weight: 800; letter-spacing: 4px; color: var(--rc); text-shadow: 0 0 10px var(--rc); margin-bottom: 8px; }
.rush-card .rush-count { font-size: 13px; opacity: 0.8; margin-bottom: 10px; letter-spacing: 2px; }
.rush-card .rush-desc { font-size: 13px; line-height: 1.7; opacity: 0.85; min-height: 66px; margin-bottom: 12px; }
.rush-card .rush-token { font-size: 15px; font-weight: 700; letter-spacing: 3px; color: var(--warn); text-shadow: 0 0 8px rgba(255,210,74,0.7); }

/* ============================================================
 * 暂停系统：右上角按钮 + 毛玻璃弹窗 + 游戏暗化
 * ============================================================ */

/* —— 危险按钮（返回主菜单） —— */
.btn.danger {
  color: #fff; background: transparent;
  border: 1px solid var(--red);
  box-shadow: 0 0 0 rgba(255,56,96,0), inset 0 0 0 rgba(255,56,96,0);
}
.btn.danger:hover {
  background: rgba(255,56,96,0.12);
  box-shadow: 0 0 18px rgba(255,56,96,0.5), inset 0 0 12px rgba(255,56,96,0.18);
}

/* —— 右上角【暂停】按钮（HUD 层，游戏中显示） —— */
#pause-btn {
  position: absolute; top: 14px; right: 18px; z-index: 15;
  display: none;
  align-items: center; gap: 8px;
  padding: 9px 16px 9px 13px;
  min-height: 38px;
  background: rgba(6, 16, 28, 0.72);
  border: 1px solid rgba(0, 240, 255, 0.55);
  border-radius: 6px;
  color: #fff;
  font: 700 14px/1 'Orbitron', Consolas, monospace;
  letter-spacing: 2px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 18px rgba(0,0,0,0.55), inset 0 0 12px rgba(0,240,255,0.08);
  transition: all 0.15s ease;
  user-select: none;
}
#pause-btn.show { display: flex; animation: pauseBtnIn 0.3s ease; }
@keyframes pauseBtnIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
#pause-btn:hover {
  background: rgba(0, 240, 255, 0.14);
  border-color: var(--cyan);
  box-shadow: 0 0 18px rgba(0,240,255,0.6), inset 0 0 12px rgba(0,240,255,0.2);
}
#pause-btn:active { transform: scale(0.96); }

/* 暂停图标：双竖线 ⏸ */
#pause-btn .pb-icon {
  display: inline-block; width: 10px; height: 14px; position: relative;
}
#pause-btn .pb-icon::before,
#pause-btn .pb-icon::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 3px;
  background: var(--cyan); border-radius: 1px;
  box-shadow: 0 0 6px var(--cyan);
}
#pause-btn .pb-icon::before { left: 0; }
#pause-btn .pb-icon::after  { right: 0; }
#pause-btn .pb-text { text-shadow: 0 0 8px rgba(0,240,255,0.4); }

/* —— 游戏画面变暗层（暂停时叠加在画布上但在弹窗下） —— */
#pause-dim {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 18;
  pointer-events: none;
  opacity: 0;
  background: rgba(0, 0, 0, 0.55);
  transition: opacity 0.22s ease;
}
#wrap.paused #pause-dim {
  opacity: 1;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
/* 暂停时画布及扫描线视觉冻结 + 变暗（变暗由 pause-dim 提供） */
#wrap.paused canvas#game {
  filter: brightness(0.65) saturate(0.9);
  transition: filter 0.22s ease;
}
#wrap.paused #scanlines { opacity: 0.7; }

/* —— 暂停 screen 本身改为透明 + 居中 panel（因为已用 pause-dim 做变暗） —— */
#screen-pause {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 30;
  pointer-events: none;
}
#screen-pause.show { display: flex; }
#screen-pause .pause-panel {
  pointer-events: auto;
  min-width: 460px;
  padding: 34px 44px 30px;
  color: #fff;
  background: rgba(8, 10, 18, 0.55);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 14px;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow:
    0 8px 40px rgba(0,0,0,0.6),
    0 0 0 1px rgba(255,255,255,0.04) inset,
    0 0 32px rgba(0, 240, 255, 0.15);
  animation: pausePanelIn 0.28s cubic-bezier(.2,.7,.3,1.2) both;
}
@keyframes pausePanelIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
#screen-pause .pause-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 10px;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 14px rgba(0,240,255,0.75), 0 0 36px rgba(0,240,255,0.4);
  margin-bottom: 8px;
}
#screen-pause .pause-sub {
  font-size: 14px;
  letter-spacing: 3px;
  text-align: center;
  color: rgba(215, 229, 255, 0.85);
  margin-bottom: 22px;
}
#screen-pause .pause-settings {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 18px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  margin-bottom: 22px;
}
#screen-pause .pause-settings label {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  font-size: 14px; letter-spacing: 2px; color: rgba(215,229,255,0.9);
}
#screen-pause .pause-btns {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 18px;
}
#screen-pause .pause-btns .btn {
  width: 100%;
  justify-content: center;
  letter-spacing: 3px;
}
#screen-pause .pause-hint {
  text-align: center;
  font-size: 12px;
  letter-spacing: 2px;
  color: rgba(215,229,255,0.45);
}

/* ============================================================
 * 移动端虚拟按键（霓虹风，仅触屏设备 + 游戏进行中显示）
 * 方向键 + 开火 + 暂停，半透明不挡画面，尺寸适合手指点击
 * ============================================================ */
#touch-ui { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 12; pointer-events: none; display: none; }
body.touch.playing #touch-ui { display: block; }

/* —— 双摇杆（左：移动 / 右：瞄准 + 开火）—— */
.joy {
  position: absolute;
  width: clamp(110px, 32vmin, 170px);
  height: clamp(110px, 32vmin, 170px);
  pointer-events: auto; touch-action: none;
  z-index: 13;
}
#joy-l { left: 3.5%;  bottom: 5%; }
#joy-r { right: 3.5%; bottom: 5%; }
.joy-base {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: 50%;
  border: 2px solid rgba(0,240,255,0.40);
  background: rgba(0,240,255,0.06);
  box-shadow: 0 0 16px rgba(0,240,255,0.18), inset 0 0 18px rgba(0,240,255,0.05);
}
#joy-r .joy-base { border-color: rgba(255,56,96,0.45); background: rgba(255,56,96,0.06); box-shadow: 0 0 16px rgba(255,56,96,0.20), inset 0 0 18px rgba(255,56,96,0.06); }
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 44%; height: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(0,240,255,0.35);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 18px rgba(0,240,255,0.5);
  transition: transform .04s linear;
}
#joy-r .joy-knob { background: rgba(255,56,96,0.35); border-color: var(--red); box-shadow: 0 0 18px rgba(255,56,96,0.55); }

/* 通用虚拟按键基础（暂停键沿用） */
.dbtn {
  pointer-events: auto; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  font: 800 clamp(22px, 6.5vmin, 36px)/1 'Segoe UI','Microsoft YaHei',monospace;
  color: var(--cyan);
  background: rgba(0,240,255,0.10);
  border: 2px solid rgba(0,240,255,0.5);
  border-radius: 16px;
  box-shadow: 0 0 14px rgba(0,240,255,0.22), inset 0 0 12px rgba(0,240,255,0.06);
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .07s ease, background .12s ease, box-shadow .12s ease;
}
/* .held 由 JS 添加：手指按住 / 滑动切换时的高亮（与 :active 等价，触屏更可靠） */
.dbtn:active, .dbtn.held {
  transform: scale(0.93);
  background: rgba(0,240,255,0.26);
  box-shadow: 0 0 24px rgba(0,240,255,0.6);
}

/* 虚拟暂停（触屏常驻，可切换 暂停/继续；置于暂停弹窗之上以便恢复） */
.dbtn.pause {
  position: fixed; top: 10px; right: 10px; z-index: 25;
  width: clamp(50px, 13vmin, 66px); height: clamp(50px, 13vmin, 66px);
  border-radius: 14px; font-size: clamp(22px, 6vmin, 30px);
  color: var(--warn);
  background: rgba(255,210,74,0.10);
  border-color: rgba(255,210,74,0.6);
  box-shadow: 0 0 14px rgba(255,210,74,0.25);
  display: none;
}
body.touch.playing #t-pause { display: flex; }
body.touch #pause-btn { display: none; }   /* 触屏设备用虚拟暂停，隐藏右上角原生暂停 */

/* ============================================================
 * 小屏（手机）界面适配：加大点击热区、压缩菜单间距，防止内容溢出
 * ============================================================ */
@media (max-width: 900px) {
  /* 菜单按钮触摸热区 ≥46px，手机上更好点 */
  .btn { min-height: 46px; padding: 10px 12px; font-size: 14px; letter-spacing: 1px; min-width: 0; white-space: nowrap; }
  .btn.small, #level-grid .btn, #boss-gallery .btn { min-height: 44px; font-size: 13px; letter-spacing: 1px; }

  /* 菜单排版压缩，内容过多时主体区可滚动（带惯性） */
  #screen-menu { padding: 8px 12px 6px; }
  .menu-header { margin-bottom: 6px; }
  .title { font-size: clamp(22px, 6vw, 42px) !important; letter-spacing: 6px; }
  .menu-body { gap: 6px; -webkit-overflow-scrolling: touch; }
  .menu-section { gap: 4px; width: 100%; max-width: 96vw; }
  .menu-btn-grid { gap: 7px; }
  .menu-footer { gap: 2px; }
  .controls-hint { font-size: 10px !important; letter-spacing: 0.5px; }

  /* 作者卡片在手机上移到流式底部，不再叠在模式按钮上 */
  .menu-author-card { position: static !important; min-width: 0 !important; padding: 8px 16px !important; margin: 8px auto 0 !important; }
  .author-name { font-size: 20px !important; letter-spacing: 8px !important; }

  /* 关卡网格：手机从 8 列改为 4 列 */
  #level-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 6px; }

  /* 结算 / 升级 / 暂停弹窗：压缩内边距，保证小屏完整可见 */
  .screen { padding: 8px 10px; }
  .pause-panel { padding: 14px 16px !important; max-width: 96vw; }
  #screen-result table { font-size: 12px; }
  #screen-result h2 { font-size: clamp(20px, 6vw, 34px) !important; }

  /* 升级三选一：卡片缩小，三张并排也能放下（横屏手机 / 平板竖屏） */
  #screen-levelup h2 { font-size: 18px !important; letter-spacing: 4px !important; margin-bottom: 12px !important; }
  #levelup-cards { gap: 10px; max-width: 96vw; }
  .card { width: clamp(140px, 29vw, 200px); min-height: 0; padding: 12px 10px; }
  .card-rarity { font-size: 10px; letter-spacing: 2px; margin-bottom: 5px; }
  .card-name { font-size: 15px; margin-bottom: 7px; }
  .card-desc { font-size: 11px; line-height: 1.5; }

  /* Rush 三选一：同步压缩 */
  .rush-grid { gap: 10px; max-width: 96vw; }
  .rush-card { padding: 12px 10px; }
  .rush-card .rush-name { font-size: 15px; letter-spacing: 2px; }
  .rush-card .rush-desc { font-size: 11px; line-height: 1.5; min-height: 0; margin-bottom: 8px; }
  .rush-card .rush-token { font-size: 12px; }

  /* 装置养成：卡片大幅缩小 + 面板整体可滚动，手机上 6 张卡与升级按钮完整可见可点 */
  #screen-gadget {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 18px;
  }
  #screen-gadget .screen-title { font-size: 18px !important; letter-spacing: 3px !important; margin-bottom: 4px; }
  .gadget-top { margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
  .gadget-token { font-size: 13px; padding: 5px 12px; letter-spacing: 2px; }
  #gadget-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 96vw; margin-bottom: 14px; }
  .gadget-card { padding: 12px 10px; clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px); }
  .gadget-card .gadget-ring { width: 46px; height: 46px; margin: 0 auto 5px; }
  .gadget-card .gadget-icon { font-size: 24px; margin-bottom: 0; }
  .gadget-card .gadget-name { font-size: 13px; letter-spacing: 1px; margin-bottom: 3px; }
  .gadget-card .gadget-level { font-size: 11px; margin-bottom: 5px; }
  .gadget-card .gadget-level span { font-size: 13px; }
  .gadget-card .gadget-desc { font-size: 10px; line-height: 1.45; min-height: 0; margin-bottom: 8px; }
  .gadget-card .gadget-btn { padding: 8px 0; font-size: 11px; letter-spacing: 1px; min-height: 40px; }
  #gadget-back { flex-shrink: 0; margin-top: 2px; }
}

/* —— 极窄屏（手机竖屏）：2 列网格 + 更紧凑按钮 + 隐藏作者卡片 —— */
@media (max-width: 560px) {
  /* 关键修复：3 列网格在 393px 下按钮会被撑爆重叠；改成 2 列后每列 ~180px 足够容纳内容 */
  .menu-btn-grid,
  .menu-btn-grid:not(.two-col) { grid-template-columns: repeat(2, 1fr) !important; max-width: 100% !important; }
  .menu-btn-grid.two-col { grid-template-columns: repeat(2, 1fr) !important; }

  .btn { padding: 10px 6px !important; font-size: 13px !important; letter-spacing: 0 !important; min-width: 0 !important; }
  .btn.primary { font-size: 14px !important; }

  .menu-header .title { letter-spacing: 3px !important; }
  .menu-header .subtitle { letter-spacing: 6px !important; font-size: 11px !important; }
  .menu-footer .settings { flex-direction: column; gap: 4px !important; }

  /* 极窄屏隐藏"姚中宇"作者卡，避免再遮模式按钮 */
  .menu-author-card { display: none !important; }
}

/* —— 版本徽章（菜单角落小标签，便于用户确认最新部署） —— */
#menu-version {
  position: absolute;
  left: 10px; bottom: 8px;
  z-index: 4;
  font: 700 10px/1 Consolas, monospace;
  letter-spacing: 2px;
  color: var(--cyan);
  opacity: 0.55;
  padding: 3px 8px;
  border: 1px solid rgba(0, 240, 255, 0.35);
  background: rgba(6, 16, 28, 0.6);
  pointer-events: none;
}
@media (max-width: 560px) {
  #menu-version { left: 6px; bottom: 4px; font-size: 9px; padding: 2px 6px; }
}

/* ============================================================
 * 手机竖屏优先（默认）：16:9 游戏按【宽度】适配铺满手机，画面较小但
 * 始终正立、不旋转；双摇杆正立贴屏幕底边，方向直觉。玩家若物理横屏，
 * 下方 landscape 规则自动撑满全屏（不依赖任何锁屏 API，iOS 也兼容）。
 * ============================================================ */

/* —— 竖屏手机：wrap 撑满视口，canvas 以宽度为基准按 16:9 居中显示 —— */
@media (orientation: portrait) and (max-width: 760px) {
  body { overflow: hidden; }
  #wrap {
    width: 100vw; height: 100vh; aspect-ratio: auto;
    box-shadow: none; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
  }
  canvas#game {
    width: 100vw;
    height: min(100vh, calc(100vw * 9 / 16));
    flex-shrink: 0; margin: 0;
  }
  /* 菜单字号进一步缩小，竖屏窄屏不溢出 */
  .title { font-size: clamp(18px, 5.2vw, 30px) !important; letter-spacing: 4px !important; }
  .menu-header .subtitle { font-size: 10px !important; letter-spacing: 4px !important; }
  .section-label { font-size: 10px !important; letter-spacing: 3px !important; }
  .btn { font-size: 12px !important; padding: 9px 6px !important; }
  .author-name { font-size: 16px !important; letter-spacing: 5px !important; }
  .controls-hint { font-size: 9px !important; }
  #screen-menu { padding: 6px 10px 4px; }

  /* 升级三选一：竖屏改为竖排卡片（容器可滚动），三张都完整可见可点 */
  #screen-levelup { justify-content: flex-start; padding-top: 7vh; }
  #levelup-cards {
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 74vh;
    padding: 4px 6px;
  }
  .card { width: min(86vw, 330px) !important; flex-shrink: 0; }
  /* Rush 三选一：竖屏单列竖排，可滚动 */
  .rush-grid { grid-template-columns: 1fr !important; overflow-y: auto; max-height: 72vh; }
}

/* —— 物理横屏手机：wrap 撑满视口，canvas 按 16:9 居中 —— */
@media (orientation: landscape) and (max-height: 520px) {
  #wrap {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    box-shadow: none;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  canvas#game {
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    flex-shrink: 0;
    margin: 0;
  }
}
