/* 彩色连线 Flow Connect —— 全部样式原创手写 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(120% 100% at 50% 0%, #1c2440 0%, #12172a 55%, #0c1020 100%);
  color: #e8ecf5;
  min-height: 100%;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.screen { display: none; flex-direction: column; flex: 1; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

/* ---------- 按钮 ---------- */
.btn {
  display: block; width: 100%;
  border: none; border-radius: 14px;
  padding: 14px 18px;
  font-size: 17px; font-weight: 600; color: #e8ecf5;
  background: #232c48;
  box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
}
.btn:active { transform: scale(.97); filter: brightness(1.2); }
.btn-primary { background: linear-gradient(135deg, #3d7dff, #36c2ff); color: #fff; }
.btn-small { width: auto; padding: 9px 14px; font-size: 14px; border-radius: 10px; }
.btn-icon {
  width: 42px; flex: 0 0 42px; padding: 0;
  font-size: 26px; line-height: 40px; text-align: center;
  border-radius: 12px;
}
.btn-tool { flex: 1; font-size: 15px; padding: 12px 8px; }

/* ---------- 主菜单 ---------- */
.home-inner { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px 0; }
.logo-dots { display: flex; gap: 14px; margin-bottom: 4px; }
.ld { width: 22px; height: 22px; border-radius: 50%; animation: bob 2.2s ease-in-out infinite; }
.ld1 { background: #ef5350; box-shadow: 0 0 18px #ef5350; }
.ld2 { background: #fdd835; box-shadow: 0 0 18px #fdd835; animation-delay: .2s; }
.ld3 { background: #42a5f5; box-shadow: 0 0 18px #42a5f5; animation-delay: .4s; }
.ld4 { background: #66bb6a; box-shadow: 0 0 18px #66bb6a; animation-delay: .6s; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.game-logo { font-size: 44px; letter-spacing: 6px; text-shadow: 0 4px 24px rgba(61,125,255,.45); }
.tagline { color: #93a0c2; font-size: 14px; margin-bottom: 18px; }
.menu { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.home-foot { display: flex; gap: 10px; margin-top: 20px; }

/* ---------- 顶栏 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar h2 { font-size: 19px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { width: 42px; flex: 0 0 42px; }
.stats { font-size: 14px; color: #aeb9d8; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats .dot { margin: 0 6px; color: #556; }

/* ---------- 关卡列表 ---------- */
.level-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 20px; }
.level-group-title { font-size: 14px; color: #93a0c2; margin: 18px 2px 10px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-cell {
  aspect-ratio: 1; border: none; border-radius: 12px;
  background: #1d2540; color: #e8ecf5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 17px; font-weight: 700; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
  transition: transform .06s ease, filter .15s ease;
}
.level-cell:active { transform: scale(.94); filter: brightness(1.25); }
.level-cell .lv-stars { font-size: 10px; letter-spacing: 1px; color: #ffd54f; min-height: 12px; }
.level-cell .lv-stars .off { color: #3a4568; }
.level-cell.cleared { background: #223259; }

/* ---------- 面板 / 随机 ---------- */
.panel { background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.06); border-radius: 16px; padding: 18px; }
.panel-label { font-size: 15px; margin-bottom: 12px; }
.dim { color: #8894b5; font-size: 13px; line-height: 1.6; margin-top: 12px; }
.size-row { display: flex; flex-wrap: wrap; gap: 10px; }
.size-btn {
  width: 52px; height: 52px; border-radius: 12px; border: 2px solid transparent;
  background: #1d2540; color: #e8ecf5; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .06s ease, border-color .15s ease;
}
.size-btn:active { transform: scale(.94); }
.size-btn.sel { border-color: #36c2ff; background: #223259; }

/* ---------- 游戏 ---------- */
.canvas-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; margin: 2px 0 12px; }
#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; border-radius: 14px; }
.toolbar { display: flex; gap: 10px; }
.toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: 86%; padding: 9px 16px; border-radius: 999px;
  background: rgba(10, 14, 28, .88); border: 1px solid rgba(255,255,255,.12);
  font-size: 13px; color: #ffd54f; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
.toast.show { opacity: 1; }

/* ---------- 编辑器 ---------- */
.editor-panel { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.editor-row { display: flex; align-items: center; gap: 12px; }
.editor-label { font-size: 14px; color: #93a0c2; flex: 0 0 32px; }
.palette { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  position: relative; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer; padding: 0;
  transition: transform .08s ease, border-color .15s ease;
}
.swatch.sel { border-color: #fff; transform: scale(1.12); }
.swatch .cnt {
  position: absolute; right: -5px; top: -5px; min-width: 16px; height: 16px;
  border-radius: 8px; background: #0c1020; color: #cfd8f0;
  font-size: 10px; line-height: 16px; text-align: center; padding: 0 3px;
}
#editor-canvas { width: 100%; aspect-ratio: 1 / 1; touch-action: none; border-radius: 14px; background: #171b28; }
.editor-msg { min-height: 20px; font-size: 13px; color: #ffd54f; text-align: center; }
.custom-title { font-size: 15px; color: #93a0c2; margin-top: 6px; }
.custom-list { display: flex; flex-direction: column; gap: 8px; }
.custom-item {
  display: flex; align-items: center; gap: 10px;
  background: #1d2540; border-radius: 12px; padding: 10px 14px;
}
.custom-item .ci-name { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-item .ci-size { font-size: 12px; color: #8894b5; }
.custom-item button { width: auto; padding: 7px 14px; font-size: 13px; border-radius: 9px; }
.custom-empty { font-size: 13px; color: #5c6787; text-align: center; padding: 8px; }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 9, 18, .72); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.overlay.show { display: flex; }
.dialog {
  width: 100%; max-width: 360px;
  background: linear-gradient(165deg, #232c48, #171d33);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 20px; padding: 26px 22px;
  text-align: center;
  animation: pop .28s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dialog h2 { font-size: 24px; margin-bottom: 10px; }
.stars { font-size: 44px; letter-spacing: 8px; color: #ffd54f; text-shadow: 0 0 22px rgba(255,213,79,.55); margin: 6px 0 12px; }
.stars .off { color: #39425f; text-shadow: none; }
.win-stats { font-size: 14px; color: #aeb9d8; line-height: 1.9; margin-bottom: 18px; }
.dialog-btns { display: flex; gap: 10px; }
.dialog-btns .btn { flex: 1; padding: 12px 6px; font-size: 15px; }
.help-body { text-align: left; font-size: 14px; line-height: 1.8; color: #c4cdea; margin-bottom: 18px; }
.help-body p { margin-bottom: 8px; }

@media (max-width: 380px) {
  .game-logo { font-size: 36px; }
  .level-grid { grid-template-columns: repeat(4, 1fr); }
}
