/* 方寸 · AI 3D 工作台 */
:root {
  --bg: #14171b;
  --pn: #1a1e23;
  --pn2: #23282f;
  --pn3: #2b313a;
  --ln: #333a43;
  --tx: #e7ebef;
  --sub: #8d97a2;
  --dim: #69737e;
  --ac: #f59e42;
  --ac-soft: rgba(245, 158, 66, .14);
  --blue: #4a9eff;
  --ok: #5fbf7f;
  --bad: #e07a63;
  --r: 13px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--tx);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- 顶栏 ---------- */
#top {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  height: calc(50px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: linear-gradient(180deg, #191d22, #16191e);
  border-bottom: 1px solid var(--ln);
  position: relative; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 7px; color: var(--ac); flex: 0 0 auto; }
.brand .nm {
  font-size: 14px; font-weight: 700; color: var(--tx); letter-spacing: .4px;
  max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hstats { flex: 1; min-width: 0; font-size: 10.5px; color: var(--dim); letter-spacing: .3px; text-align: left; }
.hactions { display: flex; gap: 4px; flex: 0 0 auto; }

.ico {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid transparent;
  background: none; color: var(--sub); display: grid; place-items: center; cursor: pointer;
  transition: .16s;
}
.ico:active { background: var(--pn2); }
.ico:disabled { opacity: .3; }
.ico.dim { opacity: .34; }
.ico.dim:active { opacity: .7; }
.ico.on {
  color: var(--bad); background: rgba(224, 122, 99, .16);
  border-color: rgba(224, 122, 99, .55);
  box-shadow: 0 0 0 2px rgba(224, 122, 99, .12);
}

/* ---------- 画布 ---------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- 右侧浮动 ---------- */
#rail {
  position: absolute; right: 10px; top: 12px; z-index: 20;
  display: flex; flex-direction: column; gap: 7px;
}
.fab {
  width: 36px; height: 36px; border-radius: 11px;
  background: rgba(30, 35, 42, .82); border: 1px solid var(--ln);
  color: var(--sub); font-size: 17px; font-weight: 600;
  display: grid; place-items: center; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: .16s;
}
.fab:active { background: var(--pn3); color: var(--tx); }

/* ---------- 底部工具坞 ---------- */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  background: linear-gradient(180deg, rgba(22, 25, 30, .0), rgba(22, 25, 30, .96) 22px);
  padding-bottom: env(safe-area-inset-bottom);
  pointer-events: none;
}
#dock > * { pointer-events: auto; }

.tools {
  display: flex; gap: 5px; padding: 26px 8px 8px;
  width: 100%; max-width: 760px; margin: 0 auto;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
}
.tools::-webkit-scrollbar { display: none; }

.tool {
  flex: 0 0 auto; min-width: 49px; height: 48px; padding: 0 6px;
  border-radius: 12px; border: 1px solid var(--ln); background: var(--pn2);
  color: var(--sub); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10px; font-family: inherit; cursor: pointer; transition: .15s;
}
.tool svg { width: 18px; height: 18px; }
.tool.on {
  background: var(--ac-soft); border-color: rgba(245, 158, 66, .55); color: var(--ac);
  box-shadow: 0 0 0 1px rgba(245, 158, 66, .18) inset;
}
.tool.ai { color: var(--ac); border-color: rgba(245, 158, 66, .35); }

#panel { padding: 0 10px 10px; width: 100%; max-width: 760px; margin: 0 auto; }

/* ---------- 通用控件 ---------- */
.card {
  background: rgba(27, 31, 37, .96); border: 1px solid var(--ln); border-radius: var(--r);
  padding: 11px 12px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.card.danger {
  border-color: rgba(224, 122, 99, .42);
  background: rgba(38, 27, 27, .96);
  box-shadow: 0 0 0 1px rgba(224, 122, 99, .1) inset;
}
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.tiny { font-size: 10.5px; color: var(--dim); letter-spacing: .2px; }
.lbl { font-size: 11px; color: var(--sub); font-weight: 600; letter-spacing: .4px; }

.btn {
  border: 1px solid var(--ln); background: var(--pn2); color: var(--tx);
  border-radius: 11px; padding: 9px 14px; font-size: 12.5px; font-family: inherit;
  font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:active { transform: scale(.975); background: var(--pn3); }
.btn.pri { background: var(--ac); border-color: var(--ac); color: #1a1206; }
.btn.pri:active { background: #ffb055; }
.btn.ghost { background: transparent; color: var(--sub); }
.btn.danger { color: var(--bad); border-color: rgba(224, 122, 99, .35); background: rgba(224, 122, 99, .09); }
.btn.sm { padding: 6px 10px; font-size: 11.5px; border-radius: 9px; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn:disabled { opacity: .45; }

.chips { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--ln); background: var(--pn2); color: var(--sub);
  border-radius: 999px; padding: 6px 11px; font-size: 11.5px; font-family: inherit; cursor: pointer;
  transition: .15s; white-space: nowrap;
}
.chip.on { background: var(--ac-soft); border-color: rgba(245, 158, 66, .5); color: var(--ac); }

textarea, input[type=text], input[type=password] {
  width: 100%; border: 1px solid var(--ln); border-radius: 11px; background: #12151a;
  color: var(--tx); font-family: inherit; font-size: 13.5px; padding: 10px 12px;
  outline: none; resize: none; line-height: 1.55; transition: border-color .15s;
}
textarea:focus, input:focus { border-color: rgba(245, 158, 66, .55); }
textarea::placeholder, input::placeholder { color: #5b656f; }

/* ---------- AI 面板 ---------- */
.ai-bar { display: flex; gap: 8px; align-items: flex-end; }
.ai-bar textarea { flex: 1; min-height: 46px; max-height: 104px; }
.send {
  flex: 0 0 44px; height: 44px; border-radius: 12px; border: none;
  background: var(--ac); color: #1a1206; font-size: 18px; font-weight: 700;
  display: grid; place-items: center; cursor: pointer; transition: .15s;
}
.send:active { transform: scale(.95); }
.send.ghost { background: var(--pn3); color: var(--sub); }

.ai-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
@media (max-width: 380px) { .ai-meta { gap: 5px; } }

/* ---------- 选中面板 ---------- */
.sel-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.sel-n { font-size: 12.5px; font-weight: 700; }
.sel-k { font-size: 10.5px; color: var(--dim); letter-spacing: .3px; }
.sel-btns { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sel-btns::-webkit-scrollbar { display: none; }
.sel-btns .btn { flex: 0 0 auto; }

.swatches {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 12px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 12px), transparent);
}
.swatches::-webkit-scrollbar { display: none; }
.sw {
  flex: 0 0 24px; width: 24px; height: 24px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .16);
  cursor: pointer;
}
.sw.on { outline: 2px solid var(--ac); outline-offset: 1px; }

/* ---------- 提示 / toast ---------- */
#hintbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 14px; z-index: 18;
  background: rgba(24, 28, 34, .9); border: 1px solid var(--ln); color: var(--sub);
  font-size: 11.5px; padding: 7px 13px; border-radius: 999px; white-space: nowrap;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: opacity .3s; pointer-events: none;
}
#toast {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(8px);
  bottom: 190px; z-index: 40; max-width: 82%;
  background: rgba(38, 44, 52, .97); border: 1px solid var(--ln);
  color: var(--tx); font-size: 12px; padding: 9px 15px; border-radius: 12px;
  opacity: 0; transition: .25s; pointer-events: none; text-align: center; line-height: 1.5;
  backdrop-filter: blur(10px);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 弹层 ---------- */
#sheet {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end;
}
#sheet.hidden { display: none; }
.sheet-bd { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); }
.sheet-cd {
  position: relative; width: 100%; max-height: 86dvh; overflow-y: auto;
  background: #1b1f25; border-top: 1px solid var(--ln);
  border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(14px); animation: up .22s ease forwards;
  -webkit-overflow-scrolling: touch;
}
@keyframes up { to { transform: translateY(0); } }
.sh-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sh-t { font-size: 14px; font-weight: 700; letter-spacing: .3px; }
.sh-x {
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--ln);
  background: var(--pn2); color: var(--sub); font-size: 15px; cursor: pointer;
}
.fld { margin-bottom: 13px; }
.fld > label { display: block; font-size: 11px; color: var(--sub); font-weight: 600; margin-bottom: 6px; letter-spacing: .4px; }
.hr { height: 1px; background: var(--ln); margin: 15px 0; }

/* 滑块 */
input[type=range] {
  -webkit-appearance: none; width: 100%; height: 26px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; background: var(--pn3); border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ac); margin-top: -8px; border: 2px solid #1b1f25;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .4);
}

/* 网格选项 */
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.opt {
  border: 1px solid var(--ln); background: var(--pn2); border-radius: 10px;
  padding: 9px 4px; font-size: 11.5px; color: var(--sub); text-align: center;
  font-family: inherit; cursor: pointer; transition: .15s;
}
.opt.on { border-color: rgba(245, 158, 66, .6); background: var(--ac-soft); color: var(--ac); font-weight: 700; }
.opt:active { transform: scale(.97); }

/* 忙碌 */
#busy {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(10, 12, 15, .55); backdrop-filter: blur(3px);
}
#busy.hidden { display: none; }
.busy-card {
  background: #1c2027; border: 1px solid var(--ln); border-radius: 16px;
  padding: 22px 26px; text-align: center; min-width: 200px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.spin {
  width: 26px; height: 26px; margin: 0 auto 13px;
  border: 2.5px solid var(--pn3); border-top-color: var(--ac); border-radius: 50%;
  animation: sp .8s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }
.bt { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.bs { font-size: 11px; color: var(--dim); }

.hidden { display: none !important; }

/* 小屏收紧 */
@media (max-height: 700px) {
  .tool { height: 44px; min-width: 50px; }
  .tools { padding-top: 20px; }
}

@media (min-width: 900px) {
  .tools { padding: 14px 8px 6px; justify-content: center; }
  .tool { min-width: 62px; }
  #panel .card { padding: 12px 14px; }
  .ai-bar textarea { min-height: 42px; }
}

/* 启动遮罩 */
#boot {
  position: fixed; inset: 0; z-index: 300;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #14171b; color: var(--tx);
  transition: opacity .35s;
}
#boot.gone { opacity: 0; pointer-events: none; }
.bl-mark { color: var(--ac); margin-bottom: 14px; animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: .5; transform: scale(.96); } 50% { opacity: 1; transform: scale(1); } }
.bl-t { font-size: 17px; font-weight: 700; letter-spacing: 6px; margin-bottom: 6px; }
.bl-s { font-size: 11.5px; color: var(--dim); letter-spacing: .6px; }
.bl-bar {
  width: 96px; height: 2px; background: var(--pn3); border-radius: 2px; margin-top: 18px; overflow: hidden;
}
.bl-bar i {
  display: block; width: 40%; height: 100%; background: var(--ac); border-radius: 2px;
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
