/* 星际突围 · 滑块逃脱 —— 全部样式程序化绘制，无外部资源 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0b1026;
  --bg2: #141b3d;
  --panel: #1c2450;
  --line: #2c3770;
  --text: #e8ecff;
  --dim: #8b94c7;
  --accent: #4fd1ff;
  --gold1: #ffd76a;
  --gold2: #f0a020;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1px 1px at 12% 22%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 68% 12%, #fff6 50%, transparent 51%),
    radial-gradient(2px 2px at 84% 38%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 34% 66%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 52% 84%, #fff5 50%, transparent 51%),
    radial-gradient(2px 2px at 8% 78%, #fff4 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 88%, #fff6 50%, transparent 51%),
    linear-gradient(180deg, #0b1026 0%, #101736 60%, #0b1026 100%);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 14px 30px;
}

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px 8px;
}
#topbar h1 {
  font-size: 20px;
  letter-spacing: 4px;
  color: var(--gold1);
  text-shadow: 0 0 12px #ffd76a55;
}

button {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: linear-gradient(180deg, #2a3572, #1e2758);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform .08s, filter .15s;
  user-select: none;
}
button:active { transform: scale(.96); }
button:disabled { opacity: .38; cursor: default; transform: none; }
button.primary {
  background: linear-gradient(180deg, #ffb638, #e08a10);
  border-color: #ffcf6a;
  color: #2a1a00;
  font-weight: 700;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--dim);
}

/* ---------- 屏幕切换 ---------- */
.screen { display: none; flex: 1; flex-direction: column; }
.screen.active { display: flex; }

.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 14px;
}
.screen-head h2 { font-size: 18px; }

/* ---------- 首页 ---------- */
#screen-home { justify-content: center; }
.hero { text-align: center; padding: 20px 0; }
.hero h2 { font-size: 30px; letter-spacing: 8px; margin: 14px 0 10px; }
.tagline { color: var(--dim); font-size: 14px; line-height: 1.7; }
.progress-line { margin: 14px 0 4px; color: var(--accent); font-size: 14px; }

/* CSS 绘制的旗舰图标 */
.hero-ship {
  width: 150px;
  height: 64px;
  margin: 26px auto 0;
  position: relative;
  animation: floaty 3s ease-in-out infinite;
}
.hero-ship span {
  position: absolute;
  inset: 8px 0;
  border-radius: 32px 44px 44px 32px;
  background: linear-gradient(180deg, var(--gold1), var(--gold2));
  box-shadow: 0 0 24px #ffb63888, inset 0 -8px 14px #a35c0055, inset 0 6px 10px #fff8;
}
.hero-ship span::before { /* 舷窗 */
  content: '';
  position: absolute;
  right: 26px;
  top: 12px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d8f6ff, #37b6e8);
  box-shadow: 0 0 8px #4fd1ff;
}
.hero-ship span::after { /* 尾焰 */
  content: '';
  position: absolute;
  left: -26px;
  top: 50%;
  width: 30px;
  height: 14px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at right, #9fe8ff, #4fd1ff55 60%, transparent 75%);
  animation: flame .5s ease-in-out infinite alternate;
}
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes flame { from { transform: translateY(-50%) scaleX(.8); opacity: .7; } to { transform: translateY(-50%) scaleX(1.15); opacity: 1; } }

.menu-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 240px;
  margin: 18px auto 0;
}
.help-box {
  margin: 26px auto 0;
  max-width: 380px;
  text-align: left;
  background: #141b3d99;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--dim);
  line-height: 2;
}

/* ---------- 选关 ---------- */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.lv-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
}
.lv-btn .lv-num { font-size: 17px; font-weight: 700; }
.lv-btn .lv-stars { font-size: 10px; color: var(--gold1); letter-spacing: 1px; }
.lv-btn .lv-stars i { font-style: normal; color: var(--dim); font-size: 10px; }
.lv-btn.cleared { border-color: #6a5a20; background: linear-gradient(180deg, #3d3418, #2a2410); }
.lv-btn.locked { background: #141a38; }

/* CSS 小锁 */
.lock {
  width: 14px;
  height: 11px;
  background: #4a548c;
  border-radius: 2px;
  position: relative;
  margin-top: 4px;
}
.lock::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -8px;
  width: 10px;
  height: 9px;
  transform: translateX(-50%);
  border: 2.5px solid #4a548c;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}

.custom-title { margin: 22px 0 10px; font-size: 16px; color: var(--accent); }
.empty-tip { color: var(--dim); font-size: 13px; }
.custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.custom-row .custom-info { flex: 1; font-size: 13px; }
.custom-row button { padding: 6px 12px; font-size: 13px; }
.custom-row button.danger { border-color: #7a3030; color: #ff9a9a; }

/* ---------- 游戏 HUD ---------- */
.game-hud { padding: 6px 0 12px; }
#game-title { font-size: 17px; font-weight: 700; margin: 8px 0 4px; }
.hud-stats { font-size: 13px; color: var(--dim); }
.hud-stats b { color: var(--accent); font-size: 15px; }

/* ---------- 棋盘 ---------- */
#board-wrap, #eboard-wrap { display: flex; justify-content: center; }
#board, #eboard {
  position: relative;
  width: min(92vw, 440px);
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid var(--line);
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / calc(100%/6) calc(100%/6),
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / calc(100%/6) calc(100%/6),
    radial-gradient(circle at 50% 40%, #1a2350, #10163a 75%);
  box-shadow: inset 0 0 40px #0008, 0 6px 24px #0006;
  touch-action: none;
}

/* 跃迁门（出口） */
#gate {
  position: absolute;
  left: 100%;
  width: 14px;
  border-radius: 0 8px 8px 0;
  background: repeating-linear-gradient(180deg, #4fd1ff 0 6px, #1a6f96 6px 12px);
  box-shadow: 0 0 14px #4fd1ff88;
  animation: gatePulse 1.6s ease-in-out infinite;
}
#gate::after {
  content: '出口';
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}
#gate.open { background: var(--gold1); box-shadow: 0 0 26px #ffd76a; }
@keyframes gatePulse { 0%,100% { opacity: .75; } 50% { opacity: 1; } }

/* ---------- 飞船块 ---------- */
.ship {
  position: absolute;
  padding: 2.5px;
  cursor: grab;
  transition: left .14s ease, top .14s ease, transform .14s ease;
  z-index: 2;
  touch-action: none;
}
.ship.no-anim { transition: none; }
.ship.dragging { transition: none; cursor: grabbing; z-index: 5; }
.ship.dragging .ship-body { filter: brightness(1.25); }

.ship-body {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  position: relative;
  background: linear-gradient(180deg, #4a5aa8, #33407e);
  border: 1px solid #5a6cc0;
  box-shadow: inset 0 3px 6px #fff3, inset 0 -5px 8px #0006, 0 3px 8px #0007;
}
.ship.len3 .ship-body { background: linear-gradient(180deg, #3f8f7a, #2a6b5c); border-color: #55b89e; }
.ship.h .ship-body::after, .ship.v .ship-body::after {
  content: '';
  position: absolute;
  border-style: solid;
  opacity: .85;
}
.ship.h .ship-body::after { /* 横向船头箭头 */
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 6px 0 6px 9px;
  border-color: transparent transparent transparent #ffffff88;
}
.ship.v .ship-body::after { /* 纵向船头箭头 */
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  border-width: 9px 6px 0 6px;
  border-color: #ffffff88 transparent transparent transparent;
}
.ship.h .ship-body::before, .ship.v .ship-body::before { /* 舷窗 */
  content: '';
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d8f6ff, #2e9ecf);
  box-shadow: 0 0 5px #4fd1ff88;
}
.ship.h .ship-body::before { left: 8px; top: 50%; transform: translateY(-50%); }
.ship.v .ship-body::before { top: 8px; left: 50%; transform: translateX(-50%); }

/* 旗舰 */
.ship.flagship { z-index: 3; }
.ship.flagship .ship-body {
  background: linear-gradient(180deg, var(--gold1), var(--gold2));
  border-color: #ffe9a8;
  box-shadow: inset 0 3px 6px #fff9, inset 0 -5px 8px #8a4d0055, 0 0 16px #ffb63877;
}
.ship.flagship .ship-body::before {
  background: radial-gradient(circle at 35% 35%, #ffffff, #37b6e8);
  box-shadow: 0 0 8px #4fd1ff;
}
.ship.flagship .ship-body::after { border-left-color: #7a4a00; }

.ship.hinted .ship-body { animation: hintFlash .45s ease-in-out 4; }
@keyframes hintFlash {
  0%,100% { box-shadow: inset 0 3px 6px #fff3, inset 0 -5px 8px #0006, 0 0 0 #fff0; }
  50% { box-shadow: 0 0 22px #ffffff, 0 0 34px var(--accent); }
}

.ship.exiting { transition: transform .6s ease-in; z-index: 6; }

.ship.selected .ship-body { outline: 2px dashed #fff; outline-offset: 1px; }

/* ---------- 游戏按钮 ---------- */
.game-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}
.game-actions button { min-width: 96px; }

/* ---------- 胜利浮层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: #060916cc;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 30px;
  text-align: center;
  box-shadow: 0 10px 50px #000a;
  animation: pop .3s ease;
  max-width: 86vw;
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel h2 { color: var(--gold1); letter-spacing: 4px; margin-bottom: 10px; }
#win-stars { font-size: 40px; height: 56px; }
#win-stars .star {
  display: inline-block;
  color: #4a548c;
  animation: starPop .4s ease backwards;
}
#win-stars .star.on { color: var(--gold1); text-shadow: 0 0 16px #ffb638; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
#win-info { color: var(--dim); font-size: 14px; margin: 8px 0 20px; }
.panel-btns { display: flex; gap: 10px; justify-content: center; }

/* ---------- 编辑器 ---------- */
.editor-tip { font-size: 12px; color: var(--dim); margin-bottom: 10px; line-height: 1.6; }
#palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
#palette .pal {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  font-size: 13px;
}
#palette .pal.active { border-color: var(--accent); box-shadow: 0 0 10px #4fd1ff55; }
.pal-ship { display: inline-block; border-radius: 5px; background: linear-gradient(180deg, #4a5aa8, #33407e); }
.pal-flag .pal-ship { width: 26px; height: 13px; background: linear-gradient(180deg, var(--gold1), var(--gold2)); }
.pal-h2 .pal-ship { width: 26px; height: 13px; }
.pal-h3 .pal-ship { width: 36px; height: 13px; background: linear-gradient(180deg, #3f8f7a, #2a6b5c); }
.pal-v2 .pal-ship { width: 13px; height: 26px; }
.pal-v3 .pal-ship { width: 13px; height: 36px; background: linear-gradient(180deg, #3f8f7a, #2a6b5c); }

.editor-count { text-align: center; font-size: 13px; color: var(--dim); margin: 12px 0 8px; }
.editor-actions { display: flex; justify-content: center; gap: 10px; margin-bottom: 12px; }
.editor-save-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.editor-save-row input {
  flex: 1;
  max-width: 200px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.editor-save-row input:focus { border-color: var(--accent); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%) translateY(20px);
  background: #232c5fee;
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 99;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  #gate::after { display: none; }
}

@media (max-width: 400px) {
  #level-grid { grid-template-columns: repeat(5, 1fr); gap: 7px; }
  .game-actions button { min-width: 0; flex: 1; }
}
