*{margin:0;padding:0;box-sizing:border-box}
:root{
  --s:#3f6dde; --g:#e8843f; --a:#7a5bd6; --p:#2f9e5f; --h:#c2950d;
  --ink:#0f172a; --mute:#64748b; --line:#e2e8f0;
  --panel:rgba(255,255,255,.86);
}
html,body{height:100%}
body{
  font-family:"PingFang SC","Microsoft YaHei","Segoe UI",system-ui,sans-serif;
  color:var(--ink); background:#fff; overflow:hidden;
  -webkit-font-smoothing:antialiased;
}
.app{display:flex;flex-direction:column;height:100vh}

/* ---------- topbar ---------- */
.topbar{
  flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;
  gap:16px;padding:12px 20px;background:var(--panel);
  backdrop-filter:blur(10px);border-bottom:1px solid var(--line);z-index:20;
}
.brand{display:flex;align-items:center;gap:10px}
.brand-mark{
  font-weight:600;font-size:15px;letter-spacing:.1em;
  padding:5px 10px;border-radius:8px;color:#fff;
  background:linear-gradient(120deg,var(--s),var(--a) 40%,var(--p) 72%,var(--h));
}
.brand-text{font-size:13px;color:var(--mute)}
.tools{display:flex;align-items:center;gap:18px;flex-wrap:wrap}
.btn-group{display:flex;gap:8px}
.btn{
  border:1px solid var(--line);background:#fff;color:#334155;
  font:inherit;font-size:12.5px;padding:7px 13px;border-radius:8px;
  cursor:pointer;transition:.18s ease;white-space:nowrap;
}
.btn:hover{transform:translateY(-1px);box-shadow:0 4px 14px rgba(15,23,42,.08)}
.btn-s{color:var(--s);border-color:rgba(63,109,222,.35);background:rgba(63,109,222,.05)}
.btn-g{color:var(--g);border-color:rgba(232,132,63,.35);background:rgba(232,132,63,.05)}
.btn-a{color:var(--a);border-color:rgba(122,91,214,.35);background:rgba(122,91,214,.05)}
.btn-p{color:var(--p);border-color:rgba(47,158,95,.35);background:rgba(47,158,95,.05)}
.btn-h{color:var(--h);border-color:rgba(194,149,13,.4);background:rgba(194,149,13,.06)}
.btn-ghost:hover{border-color:#cbd5e1;background:#f8fafc}

/* ---------- stage ---------- */
.stage{position:relative;flex:1 1 auto;overflow:hidden}
/* 无限画布：背景格子不再写在 CSS 里（那样会钉死在视口上，一平移就穿帮），
   改由 render.js 的 drawGridLayer() 画到 canvas 上，跟着相机一起走。 */
#stage{
  position:absolute;inset:0;width:100%;height:100%;display:block;
  background-color:#fff;
  touch-action:none;              /* 双指捏合缩放要自己接管，别让浏览器先吃掉 */
  cursor:default;
}
.stage::after{
  content:"";position:absolute;inset:0;pointer-events:none;
  background:radial-gradient(circle at 50% 45%,rgba(255,255,255,0) 45%,rgba(255,255,255,.75) 100%);
}

/* ---------- 缩放导航 ---------- */
.nav-group{align-items:center}
.nav-btn{display:inline-flex;align-items:center;justify-content:center;padding:7px 9px}
.nav-btn svg{display:block}
.zoom-label{min-width:52px;font-variant-numeric:tabular-nums;color:#475569}

/* ---------- 迷你地图 ---------- */
.minimap{
  position:absolute;right:20px;bottom:62px;z-index:10;
  width:184px;padding:8px 8px 6px;border-radius:10px;
  background:var(--panel);border:1px solid var(--line);
  backdrop-filter:blur(8px);box-shadow:0 6px 18px rgba(15,23,42,.06);
  cursor:pointer;
}
.mm-svg{display:block;width:168px;height:98px;background:#fff;border-radius:6px}
.mm-label{
  display:block;margin-top:5px;font-size:10.5px;color:#94a3b8;
  letter-spacing:.06em;text-align:center;
}

/* ---------- 积木托盘（黑板模式专用） ---------- */
/* 位置：左下角。为什么放这儿 —— 拇指区，且不挡右边 AI 对话。 */
.tray{
  position:absolute;left:20px;bottom:18px;z-index:12;
  padding:9px 10px 8px;border-radius:12px;
  background:var(--panel);border:1px solid var(--line);
  backdrop-filter:blur(8px);box-shadow:0 6px 18px rgba(15,23,42,.07);
  max-width:calc(100% - 40px);
}
.tray-head{display:flex;align-items:center;justify-content:space-between;gap:14px;margin-bottom:7px}
.tray-title{font-size:11.5px;color:#64748b;letter-spacing:.08em;font-weight:600}
.tray-toggle{
  border:0;background:none;color:#94a3b8;font-size:11px;cursor:pointer;
  padding:2px 4px;border-radius:5px;
}
.tray-toggle:hover{background:#f1f5f9;color:#475569}
.tray-body{display:flex;gap:8px;flex-wrap:wrap;align-items:flex-end}
.tray-item{
  display:flex;flex-direction:column;align-items:center;gap:4px;
  border:1px solid var(--line);background:#fff;border-radius:10px;
  padding:7px 9px 5px;cursor:pointer;min-width:56px;
  transition:transform .12s,box-shadow .12s,border-color .12s;
}
.tray-item:hover{transform:translateY(-2px);box-shadow:0 4px 12px rgba(15,23,42,.1);border-color:#cbd5e1}
.tray-item:active{transform:translateY(0)}
.tray-item .ti-swatch{display:block;border-radius:3px}
.tray-item .ti-name{font-size:10.5px;color:#475569;white-space:nowrap}
.tray-item .ti-val{font-size:9.5px;color:#94a3b8;font-variant-numeric:tabular-nums}
/* 多色选择：同一种积木给几个颜色，孩子自己挑 */
.tray-colors{display:flex;gap:4px;margin-top:2px}
.tray-color{
  width:15px;height:15px;border-radius:50%;border:2px solid #fff;cursor:pointer;
  box-shadow:0 0 0 1px var(--line);padding:0;
}
.tray-color.active{box-shadow:0 0 0 2px #3f6dde}
/* 数量档：×1 / ×5 / ×10 —— 点一下给一小批，省掉"一块一块点 13 次" */
.tray-ns{display:flex;gap:3px;margin-top:4px}
.tray-n{
  min-width:26px;height:18px;padding:0 5px;border-radius:5px;cursor:pointer;
  border:1px solid var(--line);background:#f8fafc;color:#64748b;
  font-size:11px;font-weight:600;line-height:1;
}
.tray-n:hover{background:#eef2f7;color:#334155}
.tray-n.active{background:#3f6dde;border-color:#3f6dde;color:#fff}
.tray-swatch{cursor:pointer;display:block;line-height:0}
.tray-hint{
  margin-top:7px;font-size:11px;color:#94a3b8;line-height:1.5;max-width:420px;
}
.tray.collapsed .tray-body,.tray.collapsed .tray-hint{display:none}

/* ---------- hints ---------- */
.hints{
  position:absolute;right:20px;bottom:18px;font-size:12px;color:#94a3b8;
  z-index:10;padding:9px 14px;border-radius:10px;background:var(--panel);border:1px solid var(--line);
  max-width:340px;line-height:1.6;
}

/* ---------- context menu ---------- */
.context-menu{
  position:absolute;z-index:50;min-width:196px;padding:6px;
  background:#fff;border:1px solid var(--line);border-radius:12px;
  box-shadow:0 18px 40px rgba(15,23,42,.14);
  font-size:13px;animation:pop .13s ease;
}
@keyframes pop{from{opacity:0;transform:scale(.96) translateY(-4px)}to{opacity:1;transform:none}}
.context-menu[hidden]{display:none}
.mi{
  display:flex;align-items:center;gap:9px;padding:8px 11px;border-radius:8px;
  cursor:pointer;color:#334155;transition:.12s;user-select:none;
}
.mi:hover{background:#f1f5f9}
.mi.danger{color:#dc2626}
.mi.danger:hover{background:#fef2f2}
.mi.disabled{color:#b6c0cc;cursor:not-allowed}
.mi.disabled:hover{background:transparent}
.mi .ico{width:16px;text-align:center;font-size:12px;opacity:.85}
.mi .tag{
  margin-left:auto;font-size:10px;color:#94a3b8;border:1px solid var(--line);
  padding:1px 5px;border-radius:5px;
}
.mi-title{padding:7px 11px 5px;font-size:11px;color:#94a3b8;letter-spacing:.05em}
.mi-sep{height:1px;background:var(--line);margin:5px 4px}

/* ---------- toast ---------- */
.toast{
  position:absolute;left:50%;top:16px;transform:translate(-50%,-14px);
  z-index:60;padding:8px 16px;border-radius:999px;font-size:12.5px;
  background:rgba(15,23,42,.9);color:#fff;opacity:0;pointer-events:none;
  transition:.24s ease;white-space:nowrap;
}
.toast.show{opacity:1;transform:translate(-50%,0)}

/* ---------- 右上设置抽屉 ---------- */
.drawer{
  position:absolute;right:16px;top:14px;z-index:40;width:300px;max-height:calc(100% - 40px);
  background:#fff;border:1px solid var(--line);border-radius:14px;
  box-shadow:0 18px 44px rgba(15,23,42,.16);display:flex;flex-direction:column;overflow:hidden;
}
.drawer[hidden]{display:none}
.dr-head{display:flex;align-items:center;justify-content:space-between;padding:11px 14px;border-bottom:1px solid var(--line);font-size:13px;font-weight:500}
.dr-close{border:none;background:none;font:inherit;font-size:17px;line-height:1;cursor:pointer;color:#94a3b8}
.dr-body{padding:4px 14px 16px;overflow:auto}
.dr-sec{margin-top:12px}
.dr-sec>h4{font-size:11.5px;color:#94a3b8;font-weight:500;margin-bottom:6px;letter-spacing:.04em}
.row{display:flex;align-items:center;gap:8px;padding:5px 0}
.row label{flex:1 1 auto;font-size:12.5px;color:#334155;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.row input[type=color]{width:34px;height:24px;border:1px solid var(--line);border-radius:6px;background:none;cursor:pointer;padding:0;flex:0 0 auto}
.row select{border:1px solid var(--line);border-radius:6px;padding:3px 6px;background:#fff;color:#334155;font:inherit;font-size:12px}
.row input[type=range]{flex:0 0 96px;accent-color:#0f172a}
.speed-val{width:38px;text-align:right;font-size:12px;color:#64748b}
.dr-hint{font-size:11.5px;color:#94a3b8;margin-top:6px;line-height:1.5}
.dr-actions{display:flex;gap:8px;margin-top:14px}
.dr-actions .btn{flex:1;text-align:center}

/* ---------- 对话面板（桌面：右侧；移动端：底部抽屉） ---------- */
.chat{
  position:absolute;right:16px;top:14px;z-index:30;width:330px;
  max-height:calc(100% - 30px);
  background:var(--panel);border:1px solid var(--line);border-radius:14px;
  backdrop-filter:blur(10px);box-shadow:0 10px 30px rgba(15,23,42,.08);
  display:flex;flex-direction:column;overflow:hidden;
}
.chat-head{
  display:flex;align-items:center;gap:8px;padding:10px 12px;
  border-bottom:1px solid var(--line);
}
.chat-title{font-size:13px;font-weight:500}
.chat-mode{
  font-size:10.5px;color:#64748b;border:1px solid var(--line);
  padding:1px 6px;border-radius:5px;background:#fff;
}
.chat-toggle{
  margin-left:auto;border:1px solid var(--line);background:#fff;border-radius:6px;
  font:inherit;font-size:11.5px;padding:3px 9px;cursor:pointer;color:#64748b;
}
.chat-list{flex:1 1 auto;overflow:auto;padding:12px;display:flex;flex-direction:column;gap:10px}
.chat-empty{font-size:12px;color:#94a3b8;line-height:1.7;padding:6px 2px}
.msg{display:flex;max-width:100%}
.msg-child{justify-content:flex-end}
.msg-ai{justify-content:flex-start}
.bubble{
  max-width:86%;padding:8px 11px;border-radius:12px;font-size:13px;line-height:1.65;
  word-break:break-word;
}
.msg-ai .bubble{background:#fff;border:1px solid var(--line);border-top-left-radius:4px;color:#0f172a}
.msg-child .bubble{background:#0f172a;color:#fff;border-top-right-radius:4px}
.bubble-id{font-size:10.5px;color:#94a3b8;margin-bottom:3px;letter-spacing:.03em}
.bubble-body{white-space:pre-wrap}
.bubble-ops{display:flex;flex-wrap:wrap;gap:4px;margin-top:7px}
.op-chip{
  font-size:10.5px;color:#3f6dde;background:rgba(63,109,222,.08);
  border:1px solid rgba(63,109,222,.25);padding:1px 6px;border-radius:5px;
}
/* 提问未答提示条 */
.chat-ask{
  display:flex;align-items:center;gap:7px;margin:0 12px 8px;
  font-size:12px;color:#b45309;background:rgba(245,158,11,.1);
  border:1px solid rgba(245,158,11,.35);border-radius:8px;padding:7px 10px;
}
.chat-ask[hidden]{display:none}
.ask-dot{
  width:7px;height:7px;border-radius:50%;background:#f59e0b;flex:0 0 auto;
  animation:blink 1.1s ease-in-out infinite;
}
@keyframes blink{0%,100%{opacity:1}50%{opacity:.25}}
.chat-actions{display:flex;gap:6px;padding:0 12px 8px;flex-wrap:wrap}
.chat-actions .btn{font-size:11.5px;padding:6px 10px}
.chat-foot{display:flex;gap:7px;padding:0 12px 8px;align-items:flex-end}
.chat-foot textarea{
  flex:1 1 auto;resize:none;font-family:inherit;font-size:13px;line-height:1.5;
  border:1px solid var(--line);border-radius:9px;padding:7px 9px;color:#0f172a;
  background:#fff;max-height:88px;min-height:34px;
}
.chat-foot textarea:focus{outline:none;border-color:#94a3b8}
.btn-send{
  border-color:#0f172a;background:#0f172a;color:#fff;font-size:12.5px;padding:8px 14px;
}
.btn-send:disabled{opacity:.45;cursor:not-allowed}
.chat-cont-row{display:flex;gap:7px;padding:0 12px 12px}
.chat-cont-row .btn{flex:1;text-align:center;font-size:12.5px;padding:8px 10px}
.btn-continue{border-color:#cbd5e1}
.btn-continue.blocked{
  color:#b6c0cc;background:#f1f5f9;border-color:var(--line);
  cursor:not-allowed;transform:none;box-shadow:none;
}
.btn-continue.blocked:hover{transform:none;box-shadow:none}
.btn-settle{border-color:rgba(194,149,13,.45);background:rgba(194,149,13,.06);color:var(--h)}

/* ---------- 结算动画 ---------- */
.settle-box{
  position:absolute;left:50%;top:50%;transform:translate(-50%,-50%) scale(.94);
  z-index:70;padding:20px 26px;border-radius:16px;background:#fff;
  border:1px solid var(--line);box-shadow:0 24px 60px rgba(15,23,42,.2);
  text-align:center;opacity:0;pointer-events:none;transition:.28s ease;
}
.settle-box.show{opacity:1;pointer-events:auto;transform:translate(-50%,-50%) scale(1)}
.settle-title{font-size:13px;color:#94a3b8;margin-bottom:6px}
.settle-exp{font-size:30px;font-weight:600;color:var(--h);letter-spacing:.01em}
.settle-meta{margin-top:12px;font-size:12px;color:#475569;line-height:1.9}
.settle-up{color:#dc2626;font-weight:600}
.settle-box .btn-home{margin-top:14px;padding:8px 22px}

/* ---------- 手机窄屏 ---------- */
@media (max-width:720px){
  .topbar{padding:10px 12px;gap:10px}
  .brand-text{display:none}
  .tools{gap:8px;overflow-x:auto;width:100%}
  .btn-group{flex:0 0 auto}
  .btn{font-size:12px;padding:8px 11px}
  .drawer{right:8px;left:8px;width:auto;top:8px;max-height:70%}
  .hints{display:none}
  /* 手机窄屏收掉迷你地图（底部已被托盘占满），导航按钮留在工具栏里 */
  .minimap{display:none}
  .nav-btn{min-height:36px;min-width:36px}

  /* 对话面板 → 底部抽屉：收起时只露一条把手，点开撑起 62% */
  .chat{
    left:0;right:0;bottom:0;top:auto;width:auto;max-height:62%;
    border-radius:16px 16px 0 0;border-left:none;border-right:none;border-bottom:none;
    transition:max-height .22s ease;
  }
  .chat:not(.open){max-height:46px}
  .chat:not(.open) .chat-list,
  .chat:not(.open) .chat-ask,
  .chat:not(.open) .chat-actions,
  .chat:not(.open) .chat-foot,
  .chat:not(.open) .chat-cont-row{display:none}
  .chat-head{padding:12px 14px;min-height:46px}
  .chat-toggle{padding:7px 12px}

  /* 移动端触控尺寸：输入框字号 ≥16px（防 iOS 缩放），按钮 ≥44px */
  .chat-foot textarea{font-size:16px;min-height:44px;padding:10px 11px}
  .btn-send{font-size:15px;min-height:44px;padding:0 18px}
  .chat-actions .btn{min-height:44px;font-size:13px;padding:0 12px}
  .chat-cont-row .btn{min-height:46px;font-size:14px}
  .chat-ask{font-size:13px;padding:10px 12px}
  .settle-box{width:calc(100% - 32px);padding:18px 16px}

  /* ---- 黑板积木托盘（手机端）------------------------------------------
     手机上托盘是**孩子唯一取积木的地方**，所以不能像桌面那样挂在右下角：
       · 左下角会被对话抽屉压住
       · 右下角在窄屏只剩一条缝
     做法：托盘横过来贴底（对话抽屉上方），一个可横滑的积木条。
     说明文字（tray-hint）在手机上收掉 —— 那行字是给家长读的，孩子看图标就懂。
     ------------------------------------------------------------------ */
  .tray{
    left:8px;right:8px;bottom:54px;top:auto;
    max-height:34%;padding:8px 10px 9px;
  }
  .tray.collapsed{max-height:none;width:auto;right:auto}
  .tray-body{flex-direction:row;gap:10px;overflow-x:auto;overflow-y:hidden;
    -webkit-overflow-scrolling:touch;padding-bottom:2px}
  .tray-item{flex:0 0 auto;align-items:center;min-width:64px}
  .tray-hint{display:none}
  /* 触控尺寸：数量档和色点都得能点得中（≥28px 热区；色点用 padding 撑） */
  .tray-n{min-width:38px;height:28px;font-size:12px;border-radius:7px}
  .tray-color{width:20px;height:20px}
  .tray-toggle{min-height:30px;padding:5px 10px}
}

