/* ============================================================
   乐高滑翔机工坊 · 样式
   基线：平板优先，手机竖屏抽屉折叠在底部，桌面左右分栏
   ============================================================ */

:root {
  --bg: #0d1117;
  --bg-soft: #151b24;
  --panel: #1a222d;
  --panel-hi: #232d3b;
  --line: #2c3847;
  --text: #e8eef7;
  --text-dim: #93a3b8;
  --accent: #4da3ff;
  --accent-2: #41d98b;
  --warn: #ffb02e;
  --danger: #ff5f6d;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }

/* 全局 [hidden] 护轨：组件类（.help-body{display:grid}、.modal{display:flex}…）
   的 display 会盖掉浏览器默认的 [hidden]{display:none}，导致「设了 hidden 却还看得见」。
   帮助弹窗的平板 tab 下两个面板同时显示，就是这条缺失造成的。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------------------------------------------------------- 顶栏 */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #182029, #131a22);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 24px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(77,163,255,.35)); }
.titles { min-width: 0; }
.titles h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
}
.sub {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 顶栏作品名：可点改名。hover 露出 ✏️ 提示「这里能改」 */
.build-title { cursor: pointer; max-width: 220px; transition: color .14s; }
.build-title::after {
  content: "✏️";
  margin-left: 5px;
  font-size: 10px;
  opacity: 0;
  transition: opacity .14s;
}
.build-title:hover { color: var(--text); }
.build-title:hover::after { opacity: .8; }
.build-title[hidden] { display: none; }
.build-title-input {
  width: 200px;
  margin: 0;
  padding: 1px 6px;
  background: var(--panel);
  border: 1.5px solid var(--accent);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  line-height: 16px;
  outline: none;
}
.build-title-input[hidden] { display: none; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.counter {
  display: flex;
  align-items: baseline;
  gap: 2px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.counter #count-num { font-size: 15px; font-weight: 700; color: var(--accent); }
.counter .unit { font-size: 11px; color: var(--text-dim); }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .14s, color .14s, transform .1s, border-color .14s;
}
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn:hover { background: var(--panel-hi); color: var(--text); border-color: #3b4d63; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger:hover { color: var(--danger); border-color: rgba(255,95,109,.5); }
.icon-btn.flash { animation: btn-flash .5s ease; }
/* 扩板引导：放置越界时连闪 3 次把孩子目光引到按钮上 */
.icon-btn.attention { animation: btn-attention 1s ease 3; }
@keyframes btn-attention {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 5px rgba(77, 163, 255, .45); }
}
.icon-btn:disabled { opacity: .38; cursor: not-allowed; }
@keyframes btn-flash {
  0%, 100% { background: var(--panel); }
  40% { background: rgba(77,163,255,.32); }
}

/* 声音开关：开着显示喇叭，关掉显示划叉喇叭 */
#btn-sound .muted-icon { display: none; }
#btn-sound.is-muted .muted-icon { display: block; }
#btn-sound.is-muted > svg:first-of-type { display: none; }
#btn-sound.is-muted { color: #66788c; }

/* ---------------------------------------------------------- 抽屉工具行 */

/* 桌面/平板：顶栏放得下，工具行不显示（按钮都在顶栏里） */
.drawer-tools { display: none; }

/* 窄屏：顶栏只留「计数 + 试飞」，其余操作搬进这里 */
@media (max-width: 640px) {
  .drawer-tools {
    display: flex;
    gap: 6px;
    /* 上边留出把手的 22px 命中区，避免点按钮时误折叠 */
    padding: 22px 12px 8px;
  }
  .drawer-tools .icon-btn { flex: 1 1 0; width: auto; height: 44px; }
}

.primary-btn {
  display: flex; align-items: center; gap: 6px;
  height: 44px;
  padding: 0 16px;
  background: linear-gradient(180deg, #4dabff, #2f86e0);
  border: none;
  border-radius: 11px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(47,134,224,.4);
  transition: transform .1s, box-shadow .16s, filter .16s;
}
.primary-btn:hover { filter: brightness(1.08); box-shadow: 0 6px 20px rgba(47,134,224,.52); }
.primary-btn:active { transform: scale(.96); }
.primary-btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.fly-icon { font-size: 15px; }

/* ---------------------------------------------------------- 主体 */

.stage {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

.viewport {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: radial-gradient(circle at 50% 34%, #1b2531 0%, #0d1117 70%);
}

.canvas-host { position: absolute; inset: 0; }
.build-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------------------------------------------------------- 零件抽屉 */

.drawer-host {
  flex: 0 0 250px;
  min-width: 0;
  display: flex;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  z-index: 10;
}

.drawer {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.color-bar {
  display: flex;
  gap: 7px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.color-dot {
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.14);
  cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.35);
}
.color-dot:hover { transform: scale(1.1); }
.color-dot.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(77,163,255,.42), inset 0 -2px 4px rgba(0,0,0,.3);
}

.part-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px 22px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.part-group-title {
  margin: 12px 0 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-dim);
  text-transform: none;
}
.part-group-title:first-child { margin-top: 0; }

.part-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.part-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 4px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 11px;
  color: var(--text-dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .1s;
  min-height: 44px;
}
.part-btn canvas { display: block; pointer-events: none; }
.part-btn:hover { background: var(--panel-hi); border-color: #3d5068; color: var(--text); }
.part-btn:active { transform: scale(.95); }
.part-btn.active {
  background: rgba(77,163,255,.17);
  border-color: var(--accent);
  color: #cfe6ff;
  box-shadow: 0 0 0 2px rgba(77,163,255,.22);
}

.drawer.placing .part-btn.active::after {
  content: "";
  position: absolute;
  inset: -1.5px;
  border-radius: 11px;
  border: 2px solid var(--accent);
  animation: pulse-ring 1.5s ease-out infinite;
  pointer-events: none;
}
@keyframes pulse-ring {
  0% { opacity: .85; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.28); }
}

/* ---------------------------------------------------------- 登录卡 */

.gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #18222e 0%, #0d1117 75%);
  overflow-y: auto;
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(92vw, 380px);
  padding: 30px 32px 22px;
  background: rgba(20, 27, 36, .92);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(16px);
}
.gate-card h1 { margin: 0 0 4px; font-size: 22px; }
.gate-card form { margin-top: 20px; text-align: left; display: grid; gap: 12px; }
.field { display: grid; gap: 5px; }
.field span { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--text-dim); }
.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  font-size: 16px; /* ≥16px 防 iOS 聚焦自动放大 */
  outline: none;
  transition: border-color .14s, background .14s;
}
.field input:focus { border-color: var(--accent); background: var(--panel-hi); }
.gate-err { min-height: 18px; margin: 0; font-size: 13px; color: var(--danger); text-align: center; }
.gate-foot {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  justify-items: center;
}
.link-btn {
  min-height: 44px;
  padding: 8px 14px;
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s;
}
.link-btn:hover { background: var(--panel-hi); border-color: #3d5068; }
.gate-note { font-size: 11px; color: var(--text-dim); line-height: 1.5; }

/* ---------------------------------------------------------- 弹窗（说明 / 账号） */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 6, 10, .62);
  backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(94vw, 620px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(20, 27, 36, .96);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 18px 22px 22px;
}
.modal-card.narrow { width: min(92vw, 400px); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 14px;
}
.seg-btn {
  min-height: 44px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.seg-btn[aria-selected="true"] { background: var(--accent); color: #04121f; }

.help-body { display: grid; gap: 14px; }
.help-body section { text-align: left; }
.help-body h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-dim);
}
.keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.keys li { font-size: 14px; line-height: 1.6; color: var(--text); }
/* 图标对照：图标在左，一句话在右，孩子扫一眼就知道按哪个。
   图标用和工具条同一套 SVG——文档里的图就是按钮上的图，找得到 // .ic 是「一个按钮大小的方块」*/
.icon-list li { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.ic {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--panel-hi);
  border: 1px solid #3d5068;
  color: #cfe6ff;
}
.ic svg { width: 16px; height: 16px; fill: currentColor; }
.ic + .ic { margin-left: 2px; }
/* 十字方向键没有 SVG，用字符补位 */
.ic.cell { font-size: 10px; line-height: 1; }
/* 键盘快捷键折叠：PC 的进阶内容，默认收起，不占首屏注意力 */
.keys-fold { text-align: left; border-top: 1px solid var(--line); padding-top: 10px; }
.keys-fold > summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  list-style: none;
  padding: 4px 0;
}
.keys-fold > summary::-webkit-details-marker { display: none; }
.keys-fold > summary::before { content: "⌨️ "; }
.keys-fold > summary::after { content: " ▾"; }
.keys-fold[open] > summary::after { content: " ▴"; }
.keys-fold > summary:hover { color: var(--text); }
.keys-fold .keys { margin-top: 6px; }
kbd {
  display: inline-block;
  min-width: 22px;
  margin: 0 2px;
  padding: 1px 6px;
  background: var(--panel-hi);
  border: 1px solid #3d5068;
  border-bottom-width: 2px;
  border-radius: 6px;
  font: 600 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  color: #cfe6ff;
  text-align: center;
}
.account-user { margin: 0 0 12px; font-size: 14px; color: var(--text-dim); }
.account-user b { color: var(--text); }
#account-form { display: grid; gap: 12px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 4px; }

/* 开始页右上角：账号齿轮 + ? */
.start-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.start-account { display: flex; gap: 6px; }
.icon-btn.text { font-size: 18px; font-weight: 800; line-height: 1; }

/* ---------------------------------------------------------- 开始页 */

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #18222e 0%, #0d1117 75%);
  overflow-y: auto;
  transition: opacity .28s, visibility .28s;
}
.start-screen.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.start-card {
  width: min(92vw, 460px);
  padding: 30px 32px 26px;
  background: rgba(20, 27, 36, .92);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(16px);
}
.start-logo { font-size: 46px; line-height: 1; margin-bottom: 10px; }
.start-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: .01em; }
.start-sub { margin: 0 0 22px; font-size: 12.5px; color: var(--text-dim); }

.start-section { margin-top: 20px; text-align: left; }
.start-section h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-dim);
}

.start-btn {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .1s;
}
.start-btn:hover { background: var(--panel-hi); border-color: #3d5068; }
.start-btn:active { transform: scale(.98); }
.start-btn.primary {
  background: linear-gradient(180deg, #4dabff, #2f86e0);
  border-color: transparent;
  color: #04121f;
  box-shadow: 0 4px 14px rgba(47,134,224,.4);
}
.start-btn.primary:hover { filter: brightness(1.08); }

.template-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.start-btn.template {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 14px 8px 12px;
  font-size: 13.5px;
}
.start-btn.template span { font-size: 26px; line-height: 1; }
.start-btn.template .t-label {
  font-size: 13px;
  line-height: 1.25;
  font-weight: 600;
}

/* 精品模板池：随机 10 个，两行滚动 */
.template-row.lucky {
  margin-top: 9px;
  max-height: 172px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.recent-list {
  display: grid;
  gap: 8px;
  max-height: 160px;      /* 3 条完整可见，更多出滚动条 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.recent-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
  /* grid item 的 min-width:auto = 内容宽，nowrap 长名会把整行撑出列表；显式归零才能让省略号生效 */
  min-width: 0;
}
/* 离开编辑器回来补名：新条目原地高亮 + 输入框闪烁 */
.recent-item.renaming { animation: item-glow 1.2s ease 2; }
@keyframes item-glow {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 8px rgba(77,163,255,.55)); }
}
.recent-item .r-open {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background .14s, border-color .14s;
  min-width: 0;
  /* 不许被两个 44px 按钮挤到内容以下（460 卡片放不下 64 图 + 2 按钮 + 长名） */
  flex: 1 1 0;
}
.recent-item .r-open:hover { background: var(--panel-hi); border-color: #3d5068; }
/* 48×48 缩略图：自动存档时拍的 JPEG；没有图就露一块 🧱 占位 */
.r-thumb {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 9px;
  background: var(--bg) center / cover no-repeat;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 22px;
}
.r-thumb:empty::before { content: "🧱"; opacity: .35; }
/* r-open 是 button：必须显式 overflow:hidden + 文字列 flex:1 1 0，否则 nowrap 的长名会把按钮撑开、
   把右侧 ✏️/✕ 挤出列表（手机 390px 下实测挤出 99px） */
.recent-item .r-open { overflow: hidden; }
.r-text { flex: 1 1 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.r-meta { flex: 0 0 auto; font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; text-align: left; }
/* 列表原地改名：名字位置换成输入框 */
.r-name-input {
  width: 100%;
  min-width: 0;
  padding: 2px 6px;
  background: var(--bg);
  border: 1.5px solid var(--accent);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  outline: none;
}
.recent-item .r-edit,
.recent-item .r-del {
  flex: 0 0 40px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  transition: color .14s, border-color .14s, background .14s;
}
.recent-item .r-edit { font-size: 13px; }
.recent-item .r-del { font-size: 13px; }
.recent-item .r-edit:hover { background: var(--panel-hi); border-color: #3d5068; }
.recent-item .r-del:hover { color: var(--danger); border-color: rgba(255,95,109,.5); }

/* ---------------------------------------------------------- 抽屉标签页 */

.tab-bar {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 5px 11px;
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.tab-btn:hover { background: var(--panel); color: var(--text); }
.tab-btn.active {
  background: rgba(77,163,255,.16);
  border-color: rgba(77,163,255,.45);
  color: #cfe6ff;
}

/* ---------------------------------------------------------- 提示条 */

.hint {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 8px);
  max-width: min(88%, 520px);
  padding: 9px 18px;
  background: rgba(20, 28, 38, .93);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  text-align: center;
  color: var(--text-dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  backdrop-filter: blur(10px);
  z-index: 15;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.hint[data-kind="active"] { color: #cfe6ff; border-color: rgba(77,163,255,.55); }
.hint[data-kind="warn"] { color: #ffe0a8; border-color: rgba(255,176,46,.55); }
.hint[data-kind="select"] { color: #d7e4f5; }
.hint.empty { display: none; }

/* ---------------------------------------------- 选中工具条（零件微调按钮）

   设计意图：盘板上必须靠键盘才能做的操作（挪一格、升降、转、拆），
   全部做成屏幕按钮——平板没键盘也能拼得精确。PC 上同样显示，键位退化成快捷键。
   只在选中零件时出现，取消选中就收起，不占常驻空间。 */

.part-tools {
  position: absolute;
  left: 50%;
  bottom: 72px;                 /* 让开底部的提示条 */
  transform: translate(-50%, 10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  background: rgba(20, 28, 38, .95);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 16;
}
.part-tools.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.pt-row { display: flex; align-items: center; gap: 6px; }
.pt-sep { width: 1px; height: 26px; background: var(--line); }

.pt-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.pt-btn svg { width: 20px; height: 20px; fill: currentColor; }
.pt-btn:hover { background: var(--panel-hi); border-color: #3d5068; }
.pt-btn:active { transform: scale(.92); }
.pt-btn.danger:hover { color: var(--danger); border-color: rgba(255,95,109,.55); }
.pt-btn.on { background: var(--accent); border-color: var(--accent); color: #04121f; }

/* 方向键浮层：点「挪一格」才展开。四向各 44px —— 挪一格是精细操作，
   手指点不准就等于没有这功能，所以这里不为省宽度让步。 */
.pt-dpad-pop {
  display: flex;
  justify-content: center;
  padding: 2px 0 4px;
}
.pt-dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px;
  gap: 3px;
}
.pt-btn.mini { width: 44px; height: 44px; border-radius: 12px; font-size: 13px; }
.pt-btn.mini.up { grid-column: 2; grid-row: 1; }
.pt-btn.mini.left { grid-column: 1; grid-row: 2; }
.pt-btn.mini.down { grid-column: 2; grid-row: 2; }
.pt-btn.mini.right { grid-column: 3; grid-row: 2; }

/* 换色板：点 🎨 展开的一行色点 */
.pt-colors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 320px;
  padding: 4px 6px 6px;
}
.pt-colors .color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.16);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.pt-colors .color-dot.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(77,163,255,.55); }

/* 窄屏：工具条贴底，D-pad 再收一档，保证 390px 宽度放得下。
   色板改成单行横向滚动——手机上竖排两行会把工具条撑到 200px 高，挡掉半个底板。 */
@media (max-width: 640px) {
  .part-tools {
    bottom: 12px;
    padding: 5px 6px;
    gap: 4px;
    border-radius: 18px;
    max-width: calc(100vw - 16px);
  }
  .pt-row { gap: 4px; }
  /* 主按钮一律 44px：儿童触控基线不因窄屏让步（D-pad 已收进浮层，宽度够用了） */
  .pt-sep { height: 22px; }
  .pt-colors {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    max-width: calc(100vw - 28px);
    padding: 2px 2px 4px;
    scrollbar-width: none;
  }
  .pt-colors::-webkit-scrollbar { display: none; }
  .pt-colors .color-dot { width: 26px; height: 26px; flex: 0 0 26px; }
}

/* ---------------------------------------------------------- 飞行 HUD */

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 11px 14px;
  background: rgba(13, 19, 26, .84);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  font-variant-numeric: tabular-nums;
  z-index: 16;
  min-width: 132px;
}
.hud-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  line-height: 1.55;
}
.hud-label { font-size: 10.5px; color: var(--text-dim); width: 30px; }
.hud-row b { font-size: 17px; font-weight: 700; color: #eaf3ff; min-width: 42px; text-align: right; }
.hud-unit { font-size: 10px; color: var(--text-dim); }

.hud-bar {
  margin-top: 7px;
  height: 5px;
  background: #26313d;
  border-radius: 3px;
  overflow: hidden;
}
.hud-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #41d98b, #ffb02e 62%, #ff5f6d);
  border-radius: 3px;
  transition: width .1s linear;
}

.flight-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(90%, 460px);
  padding: 22px 26px;
  background: rgba(18, 25, 34, .96);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
  z-index: 30;
  animation: pop .26s cubic-bezier(.2,1.3,.5,1);
}
@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -46%) scale(.94); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.flight-msg h3 {
  margin: 0 0 8px;
  font-size: 19px;
}
.flight-msg p {
  margin: 0 0 6px;
  font-size: 13.5px;
  line-height: 1.65;
  color: #c3d2e4;
}
.flight-msg .why {
  margin: 12px 0 16px;
  padding: 10px 13px;
  background: rgba(77,163,255,.1);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-size: 12.5px;
  text-align: left;
  color: #cfe0f2;
}
.flight-msg .acts { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }
.flight-msg button {
  padding: 9px 18px;
  border: none;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
}
.flight-msg .ok { background: var(--accent); color: #04121f; }
.flight-msg .again { background: var(--panel-hi); color: var(--text); }

/* ---------------------------------------------------------- 空状态 */

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
  z-index: 12;
  transition: opacity .3s;
}
.empty-state.gone { opacity: 0; pointer-events: none; }

/* 卡片本身不拦画布点击——只有里面的按钮可点，避免孩子点不到底板 */
.empty-card {
  pointer-events: none;
  max-width: 400px;
  padding: 26px 28px;
  background: rgba(18, 25, 34, .9);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(14px);
  text-align: center;
  box-shadow: var(--shadow);
}
.empty-card .ghost-btn { pointer-events: auto; }
.empty-icon { font-size: 40px; line-height: 1; margin-bottom: 6px; }
.empty-card h2 { margin: 0 0 8px; font-size: 18px; }
.empty-card > p { margin: 0 0 16px; font-size: 13px; line-height: 1.7; color: var(--text-dim); }
.tips {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  text-align: left;
  display: grid;
  gap: 7px;
}
.tips li {
  font-size: 12.5px;
  color: #b6c6d9;
  padding-left: 26px;
  position: relative;
  line-height: 1.5;
}
.tips li b {
  position: absolute;
  left: 0; top: 1px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  background: rgba(77,163,255,.18);
  color: var(--accent);
  border-radius: 6px;
  font-size: 11px;
}
.ghost-btn {
  padding: 10px 20px;
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .14s, color .14s, background .14s;
  min-height: 42px;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(77,163,255,.08); }

/* ---------------------------------------------------------- 页脚 */

.legal {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 5px 12px;
  background: #0a0e13;
  border-top: 1px solid #1a222c;
  font-size: 10.5px;
  color: #5d6d80;
  z-index: 20;
}
.legal a { color: #7d92aa; text-decoration: none; }
.legal a:hover { color: var(--accent); }
.legal .dot { opacity: .5; }

/* ============================================================
   响应式
   ============================================================ */

/* 平板横屏 / 桌面：左右分栏，抽屉固定宽度 */
@media (min-width: 900px) and (min-height: 480px) {
  .drawer-host { flex-basis: 268px; }
  .part-grid { grid-template-columns: repeat(4, 1fr); }
}

/* 中等屏：抽屉略窄，格子 3 列 */
@media (max-width: 899px) and (min-width: 641px) {
  .drawer-host { flex-basis: 216px; }
  .part-grid { grid-template-columns: repeat(3, 1fr); }
}

/* 窄屏竖屏（手机）：抽屉变成底部可折叠面板 */
@media (max-width: 640px) {
  .stage { flex-direction: column-reverse; }

  .drawer-host {
    flex: 0 0 auto;
    max-height: 42vh;
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.45);
    transition: max-height .26s cubic-bezier(.4,0,.2,1);
  }
  .drawer-host.collapsed { max-height: 168px; }

  /* 窄屏列表：缩略图与 ✏️/✕ 各收一档，长名靠省略号，按钮不能被挤出列表 */
  .r-thumb { flex-basis: 40px; width: 40px; height: 40px; font-size: 18px; }
  .recent-item { gap: 4px; }
  .recent-item .r-edit,
  .recent-item .r-del { flex-basis: 38px; }
  .recent-item .r-open { padding: 5px 6px; gap: 6px; }

  .drawer { position: relative; }

  /* 折叠把手 */
  .drawer::before {
    content: "";
    position: absolute;
    top: 5px; left: 50%;
    transform: translateX(-50%);
    width: 38px; height: 4px;
    background: #3d5068;
    border-radius: 2px;
    cursor: pointer;
    z-index: 2;
  }

  .color-bar { padding: 14px 12px 8px; gap: 8px; }
  .color-dot { width: 30px; height: 30px; }

  .part-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .part-btn { padding: 5px 1px 3px; font-size: 9.5px; min-height: 52px; }

  .hint { bottom: auto; top: 12px; max-width: 92%; font-size: 12px; padding: 8px 14px; }

  .empty-card { padding: 20px 20px; max-width: 340px; }
  .empty-card h2 { font-size: 16px; }
  .tips { display: none; }

  .hud { padding: 8px 10px; min-width: 112px; top: 10px; }
  .hud-row b { font-size: 15px; min-width: 36px; }
  .hud-row { line-height: 1.45; }

  .titles h1 { font-size: 13.5px; }
  .sub { display: none; }
  .logo { font-size: 20px; }
  .topbar { padding: 6px 10px; gap: 8px; }
  .icon-btn { border-radius: 9px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .primary-btn { padding: 0 13px; font-size: 13px; border-radius: 9px; }
  .counter { padding: 4px 8px; }
  .counter #count-num { font-size: 13px; }
  .legal { font-size: 9px; padding: 4px 8px; }
}

/* 手机横屏：抽屉在左，压缩到最窄 */
@media (max-height: 580px) and (orientation: landscape) {
  .drawer-host {
    flex-basis: 178px;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    border-right: 1px solid var(--line);
  }
  .part-grid { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .part-btn { padding: 4px 1px 2px; font-size: 9px; }
  .part-btn canvas { width: 40px !important; height: 40px !important; }
  .color-bar { padding: 7px 9px; gap: 5px; }
  .color-dot { width: 21px; height: 21px; }
  .drawer::before { display: none; }
  .titles h1 { font-size: 13px; }
  .sub { display: none; }
  .empty-card { padding: 16px 20px; }
  .empty-card h2 { font-size: 15px; }
  .empty-card > p { font-size: 12px; margin-bottom: 10px; }
  .tips { display: none; }
  .legal { font-size: 8.5px; padding: 2px 8px; }
  .hint { top: 8px; bottom: auto; font-size: 11px; padding: 6px 12px; }
  .hud { top: 8px; left: 8px; padding: 7px 9px; }
  .hud-row { line-height: 1.35; }
  .hud-row b { font-size: 13px; min-width: 32px; }
  .flight-msg { padding: 16px 20px; }
  .flight-msg h3 { font-size: 16px; }
  .flight-msg p { font-size: 12px; }
}

/* 横屏元素紧凑 */
@media (max-height: 700px) {
  .legal { font-size: 9.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
