:root {
  --ink: #17181C;
  --muted: #5F6368;
  --line: #E3E5E8;
  --surface: #F4F5F7;
  --panel: #FFFFFF;
  --ground: #ECEEF2;
  --accent: #2F5BEA;
  --accent-ink: #2349C4;
  --accent-soft: #E8EEFD;
  --vip-bg: #FEF3C7;
  --vip-ink: #92400E;
  --ok: #1E8E3E;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 14px/1.5 -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.app { display: grid; grid-template-columns: 76px 300px minmax(0, 1fr) 284px; grid-template-rows: 56px minmax(0, 1fr); height: 100vh; }
@media (max-width: 1180px) {
  .app { grid-template-columns: 76px 300px minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr) auto; height: auto; min-height: 100vh; }
  .inspector { grid-column: 2 / 4; border-left: 0 !important; border-top: 1px solid var(--line); }
}
/* 顶栏 */
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); height: 56px; }
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.tag { font-size: 11px; line-height: 18px; padding: 0 8px; border-radius: 9px; background: var(--vip-bg); color: var(--vip-ink); font-weight: 700; white-space: nowrap; }
.name-input { width: 160px; height: 36px; padding: 0 10px; border: 1.5px solid transparent; border-radius: 8px; background: var(--surface); }
.name-input:focus { outline: none; border-color: var(--accent); background: #FFF; }
.grow { flex: 1; }
.seg { display: inline-grid; grid-auto-flow: column; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface); }
.seg button { height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; font-weight: 500; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.seg button.on { background: #FFF; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--surface); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.primary { height: 36px; padding: 0 18px; border: 0; border-radius: 18px; background: var(--accent); color: #FFF; font-weight: 700; white-space: nowrap; }
.primary:hover { background: var(--accent-ink); }

/* 左侧导航 */
.rail { display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; background: var(--panel); border-right: 1px solid var(--line); }
.rail button { width: 60px; min-width: 60px; height: 58px; border: 0; border-radius: 10px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); }
.rail button:hover { background: var(--surface); }
.rail button.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }

/* 面板 */
.panel, .inspector { background: var(--panel); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; }
.panel { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }
.panel h2, .inspector h2 { margin: 0; font-size: 17px; }
.lead { margin: -12px 0 0; color: var(--muted); font-size: 13px; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group-title { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.group-title small { font-weight: 400; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.card { padding: 6px; border: 1.5px solid transparent; border-radius: 10px; background: var(--surface); display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; min-width: 0; }
.card:hover { border-color: #C9D3F5; }
.card.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.thumb { width: 100%; aspect-ratio: 358 / 220; border-radius: 6px; overflow: hidden; background: #FFF; }
.thumb svg, .thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.frame-thumb { width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; }
.frame-thumb div { width: 70%; height: 36px; box-sizing: border-box; border-style: solid; border-color: transparent; }
.upload { min-height: 44px; border: 1.5px dashed #B9BEC6; border-radius: 10px; background: var(--surface); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; cursor: pointer; padding: 8px; text-align: center; }
.upload input { display: none; }
.chip { height: 36px; padding: 0 12px; border: 1.5px solid transparent; border-radius: 18px; background: var(--surface); font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.note { font-size: 12px; color: var(--muted); }
.banner { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 500; }
.switch { position: relative; width: 44px; height: 26px; border: 0; border-radius: 13px; background: #C9CDD3; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: #FFF; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--accent); }
.switch.on::after { left: 21px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; font-size: 13px; }
.field input[type="text"] { height: 40px; padding: 0 12px; border: 1.5px solid #D5D8DD; border-radius: 10px; background: #FFF; }
.field input[type="text"]:focus { outline: none; border-color: var(--accent); }
.btn { height: 40px; padding: 0 14px; border: 1.5px solid #D5D8DD; border-radius: 10px; background: #FFF; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: #AEB4BD; }
.btn.blue { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.btn.danger { color: #B3261E; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 32px; height: 32px; border-radius: 16px; border: 1px solid rgba(0,0,0,.15); }
.swatch.on { box-shadow: 0 0 0 2px #FFF, 0 0 0 4px var(--accent); }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 10px; background: var(--surface); text-align: left; width: 100%; }
.check-row:hover { background: #EBEDF0; }
.check-row .dot { width: 20px; height: 20px; border-radius: 10px; flex: none; display: flex; align-items: center; justify-content: center; }
.check-row .dot.done { background: var(--ok); }
.check-row .dot.todo { border: 2px solid #B9BEC6; }
.check-row b { font-weight: 500; flex: 1; }
.check-row span { color: var(--muted); font-size: 12px; }

/* 九宫格编辑 */
.slice-box { position: relative; margin: 0 auto; background:
    linear-gradient(45deg, #E9EBEE 25%, transparent 25%, transparent 75%, #E9EBEE 75%) 0 0 / 16px 16px,
    linear-gradient(45deg, #E9EBEE 25%, #FFF 25%, #FFF 75%, #E9EBEE 75%) 8px 8px / 16px 16px; border-radius: 8px; touch-action: none; }
.slice-box img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sl { position: absolute; background: transparent; }
.sl::before { content: ""; position: absolute; background: #E8336B; }
.sl.v { top: 0; bottom: 0; width: 14px; margin-left: -7px; cursor: ew-resize; }
.sl.v::before { left: 6px; width: 2px; top: 0; bottom: 0; }
.sl.h { left: 0; right: 0; height: 14px; margin-top: -7px; cursor: ns-resize; }
.sl.h::before { top: 6px; height: 2px; left: 0; right: 0; }
.slice-demo { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 10px; border-radius: 10px; background: #F7E9EF; }
.slice-demo div { height: 44px; box-sizing: border-box; border-style: solid; border-color: transparent; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #4A3B52; }

/* 画布 */
.stage { position: relative; overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.typed { width: 100%; max-width: 720px; min-height: 52px; padding: 12px 16px; border-radius: 12px; background: #FFF; box-shadow: 0 1px 2px rgba(0,0,0,.06); font-size: 16px; white-space: pre-wrap; word-break: break-all; }
.typed .caret { display: inline-block; width: 2px; height: 20px; vertical-align: -4px; background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.sizer { position: relative; flex: none; }
.kb { position: absolute; left: 0; top: 0; width: 720px; height: 374px; border-radius: 18px; overflow: hidden; transform-origin: 0 0; box-shadow: 0 12px 40px rgba(20, 24, 40, .18); user-select: none; touch-action: none; --kt: #4A3B52; }
.kb-bg, .kb-wash { position: absolute; inset: 0; }
.kb-bg svg, .kb-bg img { display: block; width: 100%; height: 100%; object-fit: cover; }
.kb.night .kb-bg.auto { filter: brightness(var(--dim, .45)) saturate(.85); }
.cand { position: absolute; left: 0; right: 0; top: 0; height: 52px; display: flex; align-items: center; gap: 22px; padding: 0 22px; font-size: 18px; color: var(--kt); }
.cand b { font-weight: 700; }
.key { position: absolute; color: var(--kt); }
.key .frame { position: absolute; inset: 0; border-style: solid; border-color: transparent; pointer-events: none; }
.kb.night .key .frame { filter: brightness(var(--dimk, .55)) saturate(.9); }
.key .label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; white-space: nowrap; }
.key .label.corner { align-items: flex-start; justify-content: flex-start; padding: 10px 0 0 14px; }
.key .sub { position: absolute; right: 12px; bottom: 9px; font-size: 12px; opacity: .8; pointer-events: none; }
.key.ghost .label, .key.ghost .sub { visibility: hidden; }
.kb.editing .key { cursor: pointer; }
@media (hover: hover) {
  .kb.editing .key:hover::after { content: ""; position: absolute; inset: -2px; border-radius: 12px; border: 2px solid rgba(47, 91, 234, .45); pointer-events: none; }
}
.kb.editing .key.ghost::before { content: ""; position: absolute; inset: 2px; border-radius: 10px; border: 1.5px dashed rgba(47, 91, 234, .6); pointer-events: none; }
.key.sel::after, .kb.editing .key.sel:hover::after { content: ""; position: absolute; inset: -3px; border-radius: 12px; border: 2.5px solid var(--accent); pointer-events: none; z-index: 2; }
.key.down .frame { filter: brightness(.9); }
.kb.night .key.down .frame { filter: brightness(calc(var(--dimk, .55) * .85)); }
.sticker { position: absolute; transform-origin: 50% 50%; }
.sticker img { display: block; width: 100%; height: 100%; pointer-events: none; }
.kb.editing .sticker.above { cursor: move; }
.kb.night .sticker { filter: brightness(.82); }
.sticker.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 手柄按屏幕上的大小算，画布缩小时手柄不跟着变小 */
.handle { position: absolute; --hs: calc(18px * var(--inv, 1)); right: calc(var(--hs) / -2); bottom: calc(var(--hs) / -2); width: var(--hs); height: var(--hs); border-radius: 50%; background: #FFF; border: calc(2px * var(--inv, 1)) solid var(--accent); cursor: nwse-resize; }
.marquee { position: absolute; border: 1.5px solid var(--accent); background: rgba(47, 91, 234, .12); pointer-events: none; }
.stage-tools { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.stage-tools .chip { height: 32px; font-size: 13px; }
.hint-text { color: var(--muted); font-size: 13px; text-align: center; }
.m-only { display: none !important; }
.layer-keys { position: absolute; inset: 0; }
.float { position: absolute; width: 22px; height: 22px; pointer-events: none; animation: floatUp var(--dur, 1.3s) ease-out forwards; z-index: 30; }
.float img { width: 100%; height: 100%; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(0, 0) scale(.6); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx, 0px), var(--dy, -90px)) scale(1.1) rotate(var(--rot, 20deg)); } }
.fx-bounce { animation: fxBounce .32s ease-out; }
@keyframes fxBounce { 40% { transform: translateY(-7px) scale(1.04); } }
.fx-zoom { animation: fxZoom .32s ease-out; z-index: 20; }
@keyframes fxZoom { 35% { transform: scale(1.3) translateY(-10px); } }
.fx-glow { animation: fxGlow .45s ease-out; }
@keyframes fxGlow { 30% { filter: drop-shadow(0 0 10px #FFE08A) drop-shadow(0 0 4px #FFF); } }
.fx-shake { animation: fxShake .32s ease-in-out; }
@keyframes fxShake { 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
.ripple { position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .95); animation: ripple .5s ease-out forwards; pointer-events: none; }
@keyframes ripple { to { transform: scale(5); opacity: 0; } }

.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 25, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal { width: 440px; max-width: 100%; max-height: 90vh; overflow-y: auto; background: #FFF; border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal h2 { margin: 0; font-size: 18px; }
.sum { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 12px; background: var(--surface); font-size: 13px; }
.sum div { display: flex; justify-content: space-between; gap: 12px; }
.sum span:last-child { color: var(--muted); text-align: right; }
.toast { position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 16px); padding: 10px 18px; border-radius: 12px; background: rgba(23, 24, 28, .92); color: #FFF; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 手机：画布在上，设置面板在中间滚动，底部是导航栏 ---------- */
@media (max-width: 760px) {
  .m-only { display: inline-flex !important; }
  .d-only { display: none !important; }
  /* 整页不滚动，只有中间的面板滚：顶栏、画布、底栏一直在屏幕上。
     不能留平板断点的 min-height: 100vh，手机浏览器地址栏在的时候 100vh 比可见高度大，整页会被撑出滚动 */
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; min-height: 0; }
  .topbar { grid-row: 1; height: 52px; padding: 0 12px; gap: 8px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
  .topbar .name-input, .topbar .tag { display: none; }
  .topbar .seg .t { display: none; }
  .topbar .seg button { padding: 0 10px; height: 34px; }
  .topbar .primary { padding: 0 14px; }
  .brand { font-size: 17px; }
  .stage { grid-row: 2; padding: 10px 12px 8px; gap: 8px; overflow: visible; }
  .typed { min-height: 40px; padding: 8px 12px; font-size: 15px; }
  .hint-text { display: none; }
  .stage-tools { width: 100%; justify-content: flex-start; }
  .stage-tools .grow { flex: 1; }
  .panel, .inspector { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .panel > *, .inspector > * { flex-shrink: 0; }
  .panel, .inspector { grid-row: 3; grid-column: 1; border: 0 !important; border-radius: 16px 16px 0 0; box-shadow: 0 -2px 12px rgba(20, 24, 40, .08); padding: 16px 16px 24px; }
  .app.has-sel .panel { display: none; }
  .app:not(.has-sel) .inspector { display: none; }
  .rail { grid-row: 4; flex-direction: row; gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); }
  .rail button { flex: 1 1 0; width: auto; min-width: 0; height: 52px; font-size: 11px; }
  .chip { height: 40px; }
  .swatch { width: 36px; height: 36px; border-radius: 18px; }
  .field input[type="text"], .name-input { font-size: 16px; }
  .btn { height: 44px; }
  .sl.v { width: 28px; margin-left: -14px; }
  .sl.v::before { left: 13px; }
  .sl.h { height: 28px; margin-top: -14px; }
  .sl.h::before { top: 13px; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}
