
:root {
    /* 灰阶统一用 neutral（红绿蓝三通道相等的纯中性灰，没有冷暖色偏）：900 正文 / 600 次要 / 500 弱化 / 300–200 边框 / 100 底 / 50 悬停 */
    --bg: #f5f5f5; --panel: #ffffff; --line: #e5e5e5; --line-2: #e5e5e5; --line-3: #d4d4d4;
    --text: #171717; --text-2: #525252; --muted: #737373; --accent: #171717; --accent-soft: #f5f5f5;
    --field: #f5f5f5; --hover: #fafafa; --thumb: #ffffff; --stage-bg: #f5f5f5; --stage-dot: #d4d4d4;
    --card-ring: rgba(23,23,23,.07); --swatch-ring: rgba(23,23,23,.12);
    /* 卡片不用描边，只用弥散投影：大范围、低浓度、没有贴边的实影；浮在画布上的工具栏 / 按钮 / 弹窗更集中一点 */
    --card-shadow: 0 16px 48px -12px rgba(23,23,23,.08), 0 4px 20px -6px rgba(23,23,23,.05);
    --float-shadow: 0 12px 32px -8px rgba(23,23,23,.12), 0 4px 14px -4px rgba(23,23,23,.06);
    --shadow-sm: 0 1px 2px rgba(23,23,23,.1);
    --seg-track: rgba(23,23,23,.05);   /* 控件上的小投影：滑杆 / 开关圆点、分段选中项、下拉框 */
    --shadow: rgba(23,23,23,.1); --overlay: rgba(23,23,23,.28); --ring: rgba(163,163,163,.3);
    --r: 10px; color-scheme: light;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  :root[data-theme=dark] {
    --bg: #0f0f0f; --panel: #161616; --line: #242424; --line-2: #2e2e2e; --line-3: #404040;
    --text: #f5f5f5; --text-2: #b5b5b5; --muted: #8f8f8f; --accent: #f5f5f5; --accent-soft: #242424;
    --field: #202020; --hover: #1c1c1c; --thumb: #e5e5e5; --stage-bg: #0b0b0b; --stage-dot: #2b2b2b;
    --card-ring: rgba(255,255,255,.1); --swatch-ring: rgba(255,255,255,.14);
    --card-shadow: 0 16px 48px -12px rgba(0,0,0,.55), 0 4px 20px -6px rgba(0,0,0,.35);
    --float-shadow: 0 12px 32px -8px rgba(0,0,0,.65), 0 4px 14px -4px rgba(0,0,0,.4);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
    --seg-track: rgba(255,255,255,.06);
    --shadow: rgba(0,0,0,.5); --overlay: rgba(0,0,0,.55); --ring: rgba(115,115,115,.45);
    color-scheme: dark;
  }
  *, *::before, *::after { box-sizing: inherit; }
  html { scroll-padding-top: env(safe-area-inset-top, 0px); height: 100%; }
  body {
    margin: 0; height: 100%; background: var(--bg); color: var(--text);
    font: 13px/1.45 "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
  }
  button, input, select, textarea { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .app { height: 100%; display: grid; grid-template-rows: 1fr; }
  /* 没有顶栏：品牌、语言、深浅色放在模版列表卡片的第一行 */
  .side-brand { display: flex; align-items: center; gap: 2px; margin: 2px 0 16px 2px; }
  .brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 13.5px; letter-spacing: -.01em; white-space: nowrap; }
  .brand span { overflow: hidden; text-overflow: ellipsis; }   /* 名字过长时省略，不把按钮挤出卡片 */
  /* 品牌名 CardScape：Sora 字体，Card 粗、Scape 细 */
  #brand-name { font-family: "Sora", "Inter", system-ui, sans-serif; font-size: 16px; font-weight: 300; letter-spacing: -.02em; }
  #brand-name b { font-weight: 700; }
  /* logo：深色卡片里的一道地平线，呼应 CardScape（卡片上的风景） */
  .brand .logo { flex: none; display: block; width: 28px; height: 28px; border-radius: 8px; box-shadow: 0 1px 3px rgba(49,46,129,.3); }
  /* 按钮、单行输入框、下拉框、分段切换统一用胶囊形；多行输入框、色块和各种卡片不用 */
  .btn {
    height: 30px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel);
    font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
  }
  .btn:hover { background: var(--hover); border-color: var(--line-3); }
  .btn.primary { background: var(--text); color: var(--panel); border-color: var(--text); }
  .btn.primary:hover { opacity: .85; }
  .btn.ghost { border-color: transparent; background: none; color: var(--text-2); }
  .btn.ghost:hover { background: var(--field); }
  .btn.icon { min-width: 30px; padding: 0 8px; display: inline-grid; place-items: center; font-size: 12px; font-weight: 500; }

  /* 预览区和右侧配置区共用一张浅灰点阵画布，配置分组像卡片一样摆在上面 */
  .main {
    min-height: 0; display: grid; grid-template-columns: 288px 1fr 312px;
    background-color: var(--stage-bg);
    background-image: radial-gradient(circle, var(--stage-dot) 1px, transparent 1.3px);
    background-size: 18px 18px; background-position: 9px 9px;
  }
  aside { position: relative; min-height: 0; overflow: auto; background: var(--panel); }
  /* 两侧卡片固定在栏里，只让卡片内部的内容区滚动：卡片边缘、圆角、阴影和常用操作始终可见 */
  .side-r { display: flex; flex-direction: column; overflow: visible; }   /* 不裁切：弥散投影会超出栏宽 */
  /* 模版面板：右侧唯一的一张卡片。上面是模版名、预设、配置码和整套配置的操作，下面是这个模版的参数分组 */
  .tpl-panel {
    flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
    margin: 12px 12px 16px; padding: 12px 14px 0; background: var(--panel); border-radius: 20px;
    box-shadow: var(--card-shadow);
  }
  .tpl-panel > * { flex: none; }
  /* 面板顶部的「背景 / 内容」标签；每个标签页撑满卡片剩余高度，内部各自滚动 */
  .panel-tabs { margin-bottom: 10px; }
  .panel-tabs button[aria-selected=true] { background: var(--panel); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm); }
  .tpl-panel > .pane { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .pane[hidden] { display: none !important; }
  .pane > * { flex: none; }
  .pane-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -14px; padding: 0 14px 14px; }
  .pane-body .grp { margin: 0 0 8px; border-radius: 14px; background: var(--field); box-shadow: none; }
  .pane-body .grp:last-child { margin-bottom: 0; }
  .grp.static .grp-head { cursor: default; }
  .grp.static .grp-inner { padding-bottom: 12px; }
  .pane-body .pop-input { background: var(--panel); }
  .tpl-slot:empty { display: none; }   /* 只在窄屏放模版列表 */
  .pf-lab { display: block; margin: 0 2px 6px; font-size: 11px; color: var(--muted); }
  /* 分享：随机下方的通栏按钮，浅色，和实心的随机区分主次 */
  .btn.btn-share-full { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; height: 36px; margin-top: 8px; font-size: 13px; }
  /* 随机是这里最常用的操作：实心按钮 + 骰子，点击时骰子转一圈 */
  .btn-random { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; height: 36px; margin-top: 8px; font-size: 13px; border-radius: 999px; }
  .btn-random.rolling svg { animation: roll .45s cubic-bezier(.3, 1.4, .5, 1); }
  @keyframes roll { from { transform: rotate(-180deg) scale(.7); } to { transform: none; } }
  @media (prefers-reduced-motion: reduce) { .btn-random.rolling svg { animation: none; } }
  /* 弹出面板（分享等） */
  .pop {
    position: fixed; z-index: 40; padding: 12px; background: var(--panel); border-radius: 12px;
    box-shadow: var(--float-shadow);
    animation: scInTop .14s ease-out;
  }
  .pop[hidden] { display: none; }
  .pop-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; }
  .pop-input {
    display: block; width: 100%; margin-bottom: 10px; padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 999px;
    background: var(--panel); font-size: 12.5px; line-height: 1.45; resize: none;
  }
  textarea.pop-input { border-radius: 14px; }   /* 多行输入不用胶囊形 */
  .pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .pop-foot .hint { margin: 0; }
  /* 弹窗里的小节标题：右侧注明是否会导出 */
  .pop-sec {
    display: flex; justify-content: space-between; align-items: baseline; margin: 16px 0 8px; padding-top: 12px;
    border-top: 1px solid var(--line); font-size: 12px; font-weight: 600;
  }
  .pop-sec span { font-size: 11px; font-weight: 400; color: var(--muted); }
  .sample-top { display: flex; gap: 16px; margin-bottom: 12px; }
  .sample-base { flex: 1; min-width: 0; }
  .sample-base .pf-lab { display: flex; justify-content: space-between; }
  .sample-base output { color: var(--text); font-variant-numeric: tabular-nums; }
  .sample-base input { width: 100%; }
  .pos-grid { display: grid; grid-template-columns: repeat(3, 22px); gap: 3px; padding: 4px; background: var(--field); border-radius: 8px; }
  .pos-grid button { height: 22px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 5px; background: none; cursor: pointer; }
  .pos-grid button i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-3); transition: transform .12s, background .12s; }
  .pos-grid button:hover i { background: var(--muted); }
  .pos-grid button[aria-checked=true] { background: var(--panel); box-shadow: 0 1px 2px var(--card-ring); }
  .pos-grid button[aria-checked=true] i { background: var(--text); transform: scale(1.3); }
  .share-pop { animation-name: scIn; }
  .share-row { display: flex; gap: 6px; margin-bottom: 10px; }
  .share-row input {
    flex: 1; min-width: 0; height: 30px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 999px;
    background: var(--hover); font: 11.5px "JetBrains Mono", ui-monospace, monospace; color: var(--text); text-overflow: ellipsis;
  }
  .share-row .btn { height: 30px; flex: none; }
  .share-row input.err { border-color: #dc2626; }
  /* 只有图标的按钮：圆形 */
  .share-row .btn.icon-btn { width: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
  .share-pop .hint { margin: 0; }
  .share-short-msg { margin: -4px 0 10px !important; }
  .share-short-msg:empty { display: none; }
  .share-short-msg.err { color: #dc2626; }
  @media (prefers-reduced-motion: reduce) { .share-pop { animation: none; } }
  /* 左侧：模版选择 + 全局设置，和右侧一样是摆在点阵画布上的卡片 */
  .side-l { display: flex; flex-direction: column; overflow: visible; background: none; padding: 4px 12px 8px; }   /* 不裁切：弥散投影会超出栏宽 */
  .grp.tpl-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }   /* 撑满整栏高度 */
  .tpl-card > * { flex: none; }
  .side-r { background: none; }
  .side-title { margin: 0 2px 8px; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
  .grp.tpl-card { padding: 12px 12px 12px; border-radius: 20px; }
  /* 模版列表：缩略图 + 名称 + 描述，选中项用浅灰底 */
  /* 模版列表在卡片内部滚动，品牌行、标题和导入按钮固定 */
  #tpl-list { list-style: none; margin: 0 -12px; padding: 0 12px; display: grid; gap: 2px; align-content: start; }
  .tpl-card > #tpl-list { flex: 0 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .tpl { width: 100%; padding: 6px; border: 0; border-radius: 12px; background: none; cursor: pointer; transition: background .18s ease; }
  .tpl:hover { background: var(--hover); }
  .tpl.on { background: var(--field); }
  .tpl-list-item { position: relative; }
  .tpl-tag { margin-left: 6px; padding: 0 5px; border-radius: 999px; background: var(--field); font-size: 10px; font-style: normal; font-weight: 500; color: var(--muted); vertical-align: 1px; }
  .tpl-del {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; display: grid; place-items: center;
    padding: 0; border: 0; border-radius: 999px; background: var(--panel); color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s;
  }
  .tpl-list-item:hover .tpl-del, .tpl-del:focus-visible { opacity: 1; }
  .tpl-del:hover { color: #dc2626; }
  /* 左侧卡片底部的作者署名 */
  .credit { margin: auto 6px 0; padding-top: 10px;   /* margin-top: auto 把署名推到卡片最底部 */
    border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
  .credit-name { color: var(--text-2); font-weight: 500; text-decoration: none; }
  .credit-name:hover { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
  .tpl-card > .credit { flex: none; }
  .credit-sep { margin: 0 6px; }
  /* 导入自定义模版 */
  .tpl-import { margin: 6px 0 10px; }   /* 下边距保证和底部署名至少隔开 10px */
  .tpl-import-btn { width: 100%; display: flex; align-items: center; gap: 6px; padding: 0 6px; color: var(--text-2); }
  .import-pop { width: 320px; animation-name: scIn; }
  .import-lead { margin: -4px 0 10px; font-size: 12px; color: var(--text-2); line-height: 1.5; }
  .import-steps, .import-rules { margin: 0 0 10px; padding-left: 18px; font-size: 12px; line-height: 1.6; color: var(--text-2); }
  .import-rules { color: var(--muted); font-size: 11.5px; }
  .import-rules code { font: 11px "JetBrains Mono", ui-monospace, monospace; color: var(--text-2); }
  .import-pop .pop-foot { justify-content: flex-end; }
  .tpl-import-msg { margin: 0 0 10px; font-size: 11.5px; line-height: 1.5; }
  .tpl-import-msg:empty { display: none; }
  .tpl-import-msg.err { color: #dc2626; }
  .tpl-opt { display: flex; gap: 10px; align-items: center; min-width: 0; text-align: left; white-space: normal; }
  .tpl-opt .sw { flex: none; width: 36px; height: 36px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--card-ring); }
  .tpl-opt .tx { min-width: 0; display: grid; gap: 1px; }
  .tpl-opt strong { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tpl-opt small { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .stage-wrap { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr; container-type: inline-size; }
  /* 画布：预览卡片在上，播放 / 暂停按钮贴在它正下方（像视频下面的播放控件） */
  .stage {
    position: relative; min-height: 0; overflow: hidden;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px 24px 24px;
  }
  .stage > .demo { flex: none; }
  .demo {
    position: relative; overflow: hidden; background: var(--panel); border-radius: 18px;
    display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start;
    box-shadow: 0 0 0 1px var(--card-ring);
    transition: width .25s ease, height .25s ease, border-radius .25s ease;
  }
  .demo[data-size=card]   { width: min(360px, 100%); height: 220px; }
  .demo[data-size=wide]   { width: min(600px, 100%); height: 260px; }
  .demo[data-size=widescreen] { width: min(960px, 100%); height: auto; aspect-ratio: 16 / 9; }
  .demo[data-size=banner] { width: min(960px, 100%); height: 200px; }
  .demo[data-size=full]   { position: absolute; inset: 16px; width: auto; height: auto; border-radius: 14px; }
  #stage-canvas, .stage-fade { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
  .stage-fade { pointer-events: none; transition: opacity .4s ease; }
  .stage-fade.out { opacity: 0; }
  /* 示例内容：字号都相对基础字号（--sample-base），位置由 data-pos 的行（t/m/b）和列（l/c/r）决定；
     颜色都用纯黑 / 纯白加透明度，深色卡片（.demo.dark）换成白色 */
  .demo-content { position: relative; z-index: 1; padding: 22px 24px; max-width: min(24.6em, 100%); pointer-events: none; font-size: var(--sample-base, 13px); }
  .demo[data-pos^=m] { justify-content: center; }
  .demo[data-pos^=b] { justify-content: flex-end; }
  .demo[data-pos$=c] { align-items: center; }
  .demo[data-pos$=c] .demo-content { text-align: center; }
  .demo[data-pos$=r] { align-items: flex-end; }
  .demo-content[hidden] { display: none; }
  .demo-content .tag { display: inline-block; font-size: .846em; font-weight: 500; color: rgba(0,0,0,.5); padding: .18em .72em; border-radius: 999px; background: rgba(0,0,0,.06); }
  .demo-content h4 { margin: .67em 0 .22em; font-size: 1.385em; font-weight: 600; letter-spacing: -.01em; color: rgba(0,0,0,.9); }
  .demo-content p { margin: 0 0 1.08em; font-size: 1em; color: rgba(0,0,0,.65); line-height: 1.5; }
  .demo-content > :first-child { margin-top: 0; }
  .demo-content > :last-child { margin-bottom: 0; }
  .demo-content [hidden] { display: none !important; }
  .demo-content .cta { display: inline-flex; align-items: center; gap: .3em; font-size: .96em; font-weight: 500; color: rgba(0,0,0,.9); }
  /* 按钮右侧箭头：用遮罩画，颜色跟随文字 */
  .demo-content .cta::after {
    content: ""; flex: none; width: 1em; height: 1em; background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='m13 6 6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='m13 6 6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  .demo.dark .demo-content h4, .demo.dark .demo-content .cta { color: rgba(255,255,255,.9); }
  .demo.dark .demo-content p { color: rgba(255,255,255,.65); }
  .demo.dark .demo-content .tag { background: rgba(255,255,255,.12); color: rgba(255,255,255,.5); }
  .seg-sm { width: auto; }
  .seg-sm button { flex: none; padding: 0 10px; height: 24px; white-space: nowrap; }
  .mini { border: 0; background: none; padding: 0; font-size: 12px; color: var(--accent); cursor: pointer; }
  .mini:hover { text-decoration: underline; }
  .blobs { display: grid; gap: 8px; }
  .blob { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
  .blob-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; font-weight: 500; }
  .blob-head input[type=color] { width: 24px; height: 24px; border-radius: 6px; }
  .blob-head span { flex: 1; }
  .blob-head .rm { color: var(--muted); }
  .blob-head .rm:hover { color: #dc2626; }
  .blob-more { display: grid; }
  .blob-more[hidden] { display: none; }
  .blob-toggle { margin-top: 4px; color: var(--muted); font-size: 11.5px; }
  .blob-line { display: grid; grid-template-columns: 52px 1fr 34px; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-2); }
  .blob-line output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
  .dims { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
  .dims[hidden] { display: none; }
  .dims label { display: inline-flex; align-items: center; gap: 4px; }
  .dims input { width: 58px; height: 24px; padding: 0 8px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel); font-variant-numeric: tabular-nums; }
  .dims #dim-r { width: 46px; }
  .demo[data-size=custom] { max-width: 100%; max-height: calc(100% - 54px); }   /* 给下面的播放按钮留出位置 */
  .hint { margin: 5px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
  /* 画布顶部：工具栏居中，复制 PNG 独立靠右，都浮在画布上 */
  /* 画布顶部一行：宽的时候工具栏居中、按钮靠右；放不下时工具栏靠左、按钮靠右，再窄就换行。
     在正常文档流里，换成两行时会把预览往下推，不会盖住卡片 */
  .stage-top {
    position: relative; z-index: 3; padding: 12px 12px 0;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px;
  }
  @container (max-width: 880px) {
    .stage-top { display: flex; flex-wrap: wrap; justify-content: space-between; }
    .stage-actions { margin-left: auto; }
  }
  /* 画布右上角：复制 PNG + 导出，都是"把结果拿走" */
  .stage-actions { grid-column: 3; justify-self: end; display: flex; gap: 8px; }
  /* 画布左上角：语言、深浅色（偏好设置），和右上角的输出操作对称 */
  .stage-prefs { grid-column: 1; justify-self: start; display: flex; gap: 8px; }
  .stage-float-btn.pref-btn { justify-content: center; min-width: 40px; padding: 0 12px; font-size: 12.5px; }
  .stage-float-btn.icon-pref { width: 40px; padding: 0; }
  /* 语言：地球图标，悬停（或点击 / 键盘聚焦）时在下方弹出菜单 */
  .lang-menu { position: relative; }
  .lang-pop {
    position: absolute; top: 100%; left: 0; z-index: 20; min-width: 140px; padding: 4px; margin-top: 8px;
    background: var(--panel); border-radius: 14px; box-shadow: var(--float-shadow);
    opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity .12s, transform .12s, visibility 0s .12s;
  }
  .lang-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px; }   /* 按钮和菜单之间的"桥"，移过去时不消失 */
  .lang-menu:hover .lang-pop, .lang-menu.open .lang-pop {
    opacity: 1; visibility: visible; transform: none; transition: opacity .12s, transform .12s, visibility 0s;
  }
  .lang-pop button {
    width: 100%; height: 32px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 10px;
    border: 0; border-radius: 8px; background: none; font-size: 12.5px; color: var(--text); text-align: left; cursor: pointer;
  }
  .lang-pop button:hover, .lang-pop button:focus-visible { background: var(--field); outline: none; }
  .lang-pop .lang-check { visibility: hidden; }
  .lang-pop button[aria-checked=true] .lang-check { visibility: visible; }
  @media (prefers-reduced-motion: reduce) { .lang-pop { transition: none; } }
  .stage-float-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
    border: 0; border-radius: 999px; color: var(--text);
    box-shadow: var(--float-shadow);
  }
  .stage-float-btn:hover { background: var(--hover); }
  .stage-bar {
    grid-column: 2; min-width: 0;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 6px 6px 6px 6px;
    color: var(--text-2); font-size: 12px; background: var(--panel); border-radius: 20px;   /* 单行 40px 高时正好是胶囊形，换行时是大圆角矩形 */
    box-shadow: var(--float-shadow);
  }
  /* 画布顶部这一组都用胶囊形大圆角 */
  .stage-bar .seg, .stage-bar .seg button, .stage-bar .btn { border-radius: 999px; }
  .stage-bar .size-select { display: none; }   /* 窄屏才用下拉选择尺寸 */
  /* 工具栏上的「示例内容」开关：开关在前、文字在后，和尺寸分段控件隔开一点 */
  .bar-switch { gap: 8px; padding: 0 6px 0 4px; white-space: nowrap; }
  .bar-switch i { order: -1; }
  /* 播放 / 暂停：圆形；全屏尺寸下卡片撑满画布，改为浮在卡片右下角，半透明毛玻璃底 */
  .stage-float-btn.play-btn { flex: none; width: 40px; justify-content: center; padding: 0; }
  .demo[data-size=full] ~ .play-btn { position: absolute; right: 28px; bottom: 28px; z-index: 2; background: rgba(255,255,255,.72); backdrop-filter: blur(8px); }
  :root[data-theme=dark] .demo[data-size=full] ~ .play-btn { background: rgba(22,22,22,.72); }

  #presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
  .chip {
    height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel);
    font-size: 12px; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  }
  .chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
  .btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
  .btn.ghost[aria-pressed=true] { background: var(--field); color: var(--text); }
  /* 参数分组在卡片内部滚动；负边距让滚动条贴着卡片边缘，内容仍保留内边距 */
  #params { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -14px; padding: 0 14px 12px; }
  /* 卡片底部：预设、随机、分享固定在最下面，参数怎么滚动都在手边 */
  .tpl-foot { margin: 0 -14px; padding: 12px 14px 14px; border-top: 1px solid var(--line); }
  .tpl-foot #presets { margin-bottom: 10px; }
  .tpl-foot .btn-random { margin-top: 0; }
  /* 卡片内的分组：嵌在模版卡片里的浅灰子卡片，不用分隔线 */
  #params .grp { margin: 0 0 8px; border-radius: 14px; background: var(--field); box-shadow: none; }
  /* 子卡片是浅灰底，里面的配色方案反过来用白底 */
  #params .pal { background: var(--panel); }
  #params .pal .pal-item { background: var(--field); }
  #params .grp:last-child { margin-bottom: 0; }
  /* 可折叠分组 */
  .grp { margin: 8px 0; border-radius: 12px; background: var(--panel); box-shadow: var(--card-shadow); }
  .grp-head {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 12px; border: 0; background: none; cursor: pointer; text-align: left; border-radius: 10px;
    font-size: 12.5px; font-weight: 500; color: var(--text);
  }
  .grp-head .cnt { font-weight: 400; color: var(--muted); font-size: 11px; }
  .grp-head > svg { color: var(--muted); transition: transform .15s ease; flex: none; }
  .grp[data-open=false] .grp-head > svg { transform: rotate(-90deg); }
  .grp-head .gi { color: var(--muted); flex: none; }
  .grp-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .24s cubic-bezier(.2,.7,.2,1); }
  .grp[data-open=false] .grp-body { grid-template-rows: 0fr; }
  .grp-inner { min-height: 0; padding: 0 12px 4px; transition: opacity .2s ease, padding .24s ease; }
  .grp.anim .grp-inner { overflow: hidden; }
  .grp[data-open=false] .grp-inner { overflow: hidden; opacity: 0; padding-bottom: 0; visibility: hidden; transition: opacity .16s ease, padding .24s ease, visibility 0s .24s; }
  .grp-head > svg { transition: transform .24s cubic-bezier(.2,.7,.2,1); }
  /* 切换模版：分组和预设依次浮现 */
  @keyframes grpIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  #params.enter > *, #presets.enter > * { animation: grpIn .32s cubic-bezier(.2,.7,.2,1) both; }
  #params.enter > :nth-child(2) { animation-delay: .04s; }
  #params.enter > :nth-child(3) { animation-delay: .08s; }
  #params.enter > :nth-child(4) { animation-delay: .12s; }
  #params.enter > :nth-child(n+5) { animation-delay: .16s; }
  @media (prefers-reduced-motion: reduce) {
    .grp-body, .grp-inner, .grp-head > svg { transition: none !important; }
    #params.enter > *, #presets.enter > * { animation: none; }
    .stage-fade { display: none; }
  }
  .grp-head .l { display: flex; align-items: center; gap: 8px; }
  .more-adv {
    display: flex; align-items: center; gap: 4px; margin: 2px 0 10px; padding: 4px 6px 4px 0;
    border: 0; background: none; cursor: pointer; font-size: 11.5px; color: var(--muted);
  }
  .more-adv:hover { color: var(--text-2); }
  .more-adv svg { transition: transform .15s ease; }
  .more-adv[aria-expanded=true] svg { transform: rotate(180deg); }

  .ctl { margin-bottom: 12px; }
  .ctl[hidden] { display: none; }
  .lab { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; color: var(--text-2); font-size: 12px; }
  .lab output { font-variant-numeric: tabular-nums; color: var(--text); font-size: 12px; }
  /* 滑杆：细轨道 + 深色进度 + 白色圆点，不用品牌色 */
  input[type=range] {
    -webkit-appearance: none; appearance: none; width: 100%; height: 18px; margin: 0;
    background: transparent; cursor: pointer; --pct: 50%;
  }
  input[type=range]:focus { outline: none; }
  input[type=range]::-webkit-slider-runnable-track {
    height: 3px; border-radius: 999px;
    background: linear-gradient(to right, var(--text) 0, var(--text) var(--pct), var(--line-2) var(--pct), var(--line-2) 100%);
  }
  input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%;
    background: var(--thumb); border: 1px solid var(--line-3); box-shadow: var(--shadow-sm);
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
  }
  input[type=range]:hover::-webkit-slider-thumb { border-color: var(--muted); }
  input[type=range]:active::-webkit-slider-thumb { transform: scale(1.12); border-color: var(--text); }
  input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--ring), var(--shadow-sm); border-color: var(--text); }
  input[type=range]::-moz-range-track { height: 3px; border-radius: 999px; background: var(--line-2); }
  input[type=range]::-moz-range-progress { height: 3px; border-radius: 999px; background: var(--text); }
  input[type=range]::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%; background: var(--thumb); border: 1px solid var(--line-3);
    box-shadow: var(--shadow-sm); transition: transform .12s ease, border-color .12s ease;
  }
  input[type=range]:active::-moz-range-thumb { transform: scale(1.12); border-color: var(--text); }
  input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--ring); border-color: var(--text); }
  .colorline { display: flex; gap: 8px; align-items: center; }
  input[type=color] {
    -webkit-appearance: none; appearance: none; width: 30px; height: 30px; padding: 0; border: 0;
    border-radius: 8px; background: none; cursor: pointer; flex: none;
  }
  input[type=color]:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
  input[type=color]::-webkit-color-swatch-wrapper { padding: 0; border-radius: inherit; }   /* 圆角要逐层继承，色块和描边才是圆的 */
  /* 色块内侧一圈淡描边：白色 / 很浅的颜色放在白卡片上也看得出轮廓 */
  input[type=color]::-webkit-color-swatch { border: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px var(--swatch-ring); }
  input[type=color]::-moz-color-swatch { border: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px var(--swatch-ring); }
  .hex { flex: 1; min-width: 0; height: 30px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 999px; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; text-transform: lowercase; }
  .swatches { display: flex; gap: 6px; flex-wrap: wrap; }
  .pal { padding: 10px; margin-bottom: 14px; border-radius: 10px; background: var(--field); }
  .pal .colorline { margin-bottom: 8px; }
  .color-mode { margin-bottom: 12px; }
  .pal-mode { width: 100%; margin-bottom: 8px; }
  .pal-mode button { flex: 1; }
  .pal-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .pal-item {
    display: grid; gap: 4px; padding: 5px; border: 1px solid transparent; border-radius: 8px;
    background: var(--panel); cursor: pointer; text-align: left;
  }
  .pal-item:hover { border-color: var(--line-3); }
  .pal-strip { display: flex; height: 18px; border-radius: 4px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--card-ring); }
  .pal-strip i { flex: 1; }
  .pal-name { font-size: 11px; color: var(--text-2); }
  /* shadcn/ui Select（zinc） */
  .sc-trigger {
    width: 100%; height: 32px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 0 12px 0 14px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel);
    font: inherit; font-size: 13px; color: var(--text); text-align: left; cursor: pointer;
    box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
  }
  .sc-trigger:hover { background: var(--hover); }
  .sc-trigger:focus-visible, .sc-trigger[aria-expanded=true] { outline: none; border-color: var(--muted); box-shadow: 0 0 0 3px var(--ring); }
  .sc-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sc-chev { display: grid; color: var(--text-2); opacity: .7; flex: none; }
  .sc-content {
    position: fixed; z-index: 50; max-height: 288px; overflow: auto; padding: 4px;
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px;
    box-shadow: var(--float-shadow);   /* 下拉菜单和其他弹窗一样用弥散投影 */
    font-size: 13px; color: var(--text); outline: none;
    animation: scIn .12s ease-out;
  }
  .sc-content[data-side=top] { animation-name: scInTop; }
  @keyframes scIn { from { opacity: 0; transform: translateY(-2px) scale(.97); } to { opacity: 1; transform: none; } }
  @keyframes scInTop { from { opacity: 0; transform: translateY(2px) scale(.97); } to { opacity: 1; transform: none; } }
  @media (prefers-reduced-motion: reduce) { .sc-content { animation: none; } }
  .sc-item {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 32px; padding: 0 10px; border-radius: 8px; cursor: default; user-select: none; white-space: nowrap;
  }
  .sc-item.hl { background: var(--field); }
  .sc-check { width: 16px; height: 16px; display: grid; place-items: center; color: var(--text); flex: none; }
  /* 分段切换的底槽用半透明黑：放在白底上约 #f2f2f2，放在浅灰子卡片上约 #e9e9e9，始终只比背景深一点 */
  .seg { display: flex; padding: 2px; background: var(--seg-track); border-radius: 999px; }
  .seg button { flex: 1; height: 26px; border: 0; border-radius: 999px; background: none; font-size: 12px; color: var(--text-2); cursor: pointer; transition: background .18s ease, color .18s ease, box-shadow .18s ease; }
  .seg button[aria-checked=true] { background: var(--panel); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm); }
  .switch { display: flex; align-items: center; justify-content: space-between; cursor: pointer; color: var(--text-2); font-size: 12px; }
  .switch { position: relative; }
  .switch input { position: absolute; left: 0; top: 0; opacity: 0; width: 1px; height: 1px; margin: 0; }
  .switch i { position: relative; width: 30px; height: 18px; border-radius: 999px; background: var(--line-3); transition: background .15s; }
  .switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--thumb); box-shadow: var(--shadow-sm); transition: transform .15s; }
  .switch input:checked + i { background: var(--accent); }
  :root[data-theme=dark] .switch input:checked + i::after { background: #171717; }
  .switch input:checked + i::after { transform: translateX(12px); }
  .switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

  #modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: var(--overlay); backdrop-filter: blur(2px); }
  #modal[hidden] { display: none; }
  #modal:not([hidden]) { animation: fadeIn .18s ease both; }
  #modal:not([hidden]) .dialog { animation: dlgIn .24s cubic-bezier(.2,.7,.2,1) both; }
  @keyframes fadeIn { from { opacity: 0; } }
  @keyframes dlgIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
  @media (prefers-reduced-motion: reduce) { #modal:not([hidden]), #modal:not([hidden]) .dialog { animation: none; } }
  .dialog { width: min(760px, 100%); max-height: 100%; display: grid; grid-template-rows: auto 1fr auto; background: var(--panel); border-radius: 14px; border: 1px solid var(--line); box-shadow: 0 24px 60px -20px var(--shadow); overflow: hidden; }
  .dialog-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .dialog-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
  .tabs { display: flex; padding: 2px; background: var(--seg-track); border-radius: 999px; }
  .tabs button { height: 26px; padding: 0 12px; border: 0; border-radius: 999px; background: none; font-size: 12px; color: var(--text-2); cursor: pointer; }
  .tabs button[aria-selected=true] { background: var(--panel); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm); }
  #code { width: 100%; height: min(56vh, 480px); resize: none; border: 0; padding: 14px 16px; background: var(--hover); font: 12px/1.6 "JetBrains Mono", ui-monospace, monospace; color: var(--text-2); white-space: pre; overflow: auto; }
  #code:focus-visible { outline: none; }
  .dialog-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
  #media { padding: 16px; display: grid; gap: 12px; background: var(--panel); }
  #media[hidden] { display: none; }
  .m-row { display: flex; align-items: center; gap: 12px; min-height: 28px; }
  .m-row[hidden] { display: none; }
  .m-row[hidden] { display: none; }
  .m-lab { width: 40px; flex: none; font-size: 12px; color: var(--text-2); }
  .m-switch { flex: 1; justify-content: flex-start; gap: 10px; }
  .m-switch i { order: -1; }
  /* 卡片相关的几个开关竖着排：标签和第一个开关对齐 */
  .m-row-top { align-items: flex-start; }
  .m-row-top .m-lab { line-height: 28px; }
  .m-switches { flex: 1; display: flex; flex-direction: column; gap: 4px; }
  .m-switches .m-switch { flex: none; min-height: 28px; }
  .m-preview { display: grid; place-items: center; min-height: 180px; max-height: 300px; padding: 16px; border-radius: 10px;
    background-color: var(--stage-bg); background-image: radial-gradient(circle, var(--stage-dot) 1px, transparent 1.3px); background-size: 14px 14px;
    box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
  #m-canvas { max-width: 100%; max-height: 260px; display: block; }
  /* 视频循环预览的时间轴：竖线是当前播放位置 */
  .m-timeline { position: relative; height: 4px; margin: -2px 2px 0; border-radius: 999px; background: var(--line); }
  .m-timeline[hidden] { display: none; }
  .m-timeline .head { position: absolute; top: -3px; width: 2px; height: 10px; margin-left: -1px; border-radius: 1px; background: var(--text); }
  .m-info { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
  #code-hint { flex: 1; color: var(--muted); font-size: 12px; }


  /* ---------- 窄屏 / 手机：单列，从上到下是 模版 → 预览 → 参数 ---------- */
  @media (max-width: 960px) {
    .app { height: auto; min-height: 100%; }
    /* minmax(0, 1fr)：不让横向滚动的模版列表把整页撑宽 */
    .main { grid-template-columns: minmax(0, 1fr); align-content: start; }   /* 页面最小高度多出来的空间留在最下面，不去撑大预览区 */
    /* 上面预览、下面配置：左栏整个隐藏，模版列表由脚本移进右侧面板的「模版」标签，署名移到页面最底部 */
    .side-l { display: none; }
    /* 模版：配置面板最上面横向滑动的一排，缩略图为主、名字在下面，不显示说明；两端贴着卡片边缘，滑动时对齐到每一项 */
    .tpl-slot { margin: 0 -14px 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
    #tpl-slot #tpl-list {
      margin: 0; padding: 4px 14px 2px; grid-auto-flow: column; grid-auto-columns: 56px; gap: 6px;
      overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding: 0 14px;
      -webkit-overflow-scrolling: touch; scrollbar-width: none;
    }
    #tpl-slot #tpl-list::-webkit-scrollbar { display: none; }
    #tpl-slot .tpl-list-item { scroll-snap-align: start; }
    #tpl-slot .tpl { padding: 0; background: none; border-radius: 0; }
    #tpl-slot .tpl-opt { flex-direction: column; align-items: center; gap: 5px; text-align: center; }
    #tpl-slot .tpl-opt .sw { width: 48px; height: 48px; border-radius: 11px; transition: box-shadow .15s ease; }
    #tpl-slot .tpl.on .sw { box-shadow: inset 0 0 0 1px var(--card-ring), 0 0 0 2px var(--panel), 0 0 0 3.5px var(--text); }
    #tpl-slot .tpl-opt .tx { display: block; width: 100%; }
    #tpl-slot .tpl-opt strong { display: block; font-size: 11px; color: var(--text-2); }
    #tpl-slot .tpl.on strong { color: var(--text); font-weight: 600; }
    #tpl-slot .tpl-opt small, #tpl-slot .tpl-tag { display: none; }
    #tpl-slot .tpl-del { opacity: 1; top: -2px; right: 0; transform: none; width: 18px; height: 18px; box-shadow: var(--shadow-sm); }
    /* 页面最底部：语言、深浅色按钮 + 署名；语言菜单改为向上弹出 */
    .m-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -8px 16px 28px; }
    .m-foot .credit { margin: 0; padding-top: 0; border-top: 0; }
    .m-foot .lang-pop { top: auto; bottom: 100%; margin: 0 0 8px; transform: translateY(4px); }
    .m-foot .lang-pop::before { top: auto; bottom: -10px; }
    /* 顶部一行：左边语言 / 深浅色，右边复制 / 导出；工具栏单独占下一行 */
    .stage-top { display: flex; flex-wrap: wrap; justify-content: space-between; row-gap: 8px; }
    /* 顶部一行：尺寸下拉 + 示例内容开关靠左，复制 / 导出靠右；工具栏容器不参与排版（display: contents），
       这样选「自定义」时宽高输入框能单独换到下一行占满整行 */
    .stage-top { align-items: center; }
    .stage-bar { display: contents; }
    .stage-top .size-select { order: 1; }
    .stage-top .bar-switch { order: 2; padding: 0; min-width: 0; }
    .stage-actions { order: 3; margin-left: auto; flex: none; }
    .stage-top #dims { order: 4; flex-basis: 100%; justify-content: center; }
    .stage-top .dims label { white-space: nowrap; }
    /* 尺寸改成下拉选择，和「示例内容」开关排在同一行 */
    .stage-bar #sizes { display: none; }
    .stage-bar .size-select { display: flex; width: auto; min-width: 0; height: 40px; padding: 0 10px 0 14px; gap: 6px; box-shadow: var(--float-shadow); border-color: transparent; }
    /* 预览区：往下滚动时预览卡片吸在屏幕顶部，工具栏滑出去（top 由脚本按工具栏高度设为负值） */
    .stage-wrap {
      height: auto; position: sticky; top: calc(-1 * var(--stage-top-h, 0px)); z-index: 5;
      background-color: var(--stage-bg); background-image: radial-gradient(circle, var(--stage-dot) 1px, transparent 1.3px);
      background-size: 18px 18px; background-position: 9px 9px;
    }
    .stage { padding: 12px 16px 16px; min-height: 0; }
    .demo[data-size=full] { position: relative; inset: auto; width: 100%; height: 280px; }
    .demo[data-size=custom] { max-height: none; }
    /* 播放按钮叠在预览卡片上，省出一行高度 */
    /* 叠在卡片底部居中：卡片不一定占满宽度，按画布右边定位会跑到卡片外面 */
    .stage > .play-btn { position: relative; margin-top: -66px; z-index: 2; background: rgba(255,255,255,.72); backdrop-filter: blur(8px); }
    :root[data-theme=dark] .stage > .play-btn { background: rgba(22,22,22,.72); }
    /* 复制 PNG / 导出只留图标 */
    .stage-actions .stage-float-btn { width: 40px; padding: 0; justify-content: center; }
    .stage-actions .stage-float-btn span { display: none; }
    /* 参数卡片跟着页面自然滚动；预设、随机、分享放到卡片最上面（先选起点，再往下细调），随机和分享并排 */
    .side-r { overflow: visible; }
    .tpl-panel { flex: none; overflow: visible; margin-bottom: 24px; }   /* 按内容定高：内容少的标签（模版）不被页面最小高度撑出空白 */
    #params, .pane-body { overflow: visible; }
    .tpl-foot {
      order: -1; margin: 0 -14px 12px; padding: 2px 14px 12px; border-top: 0; border-bottom: 1px solid var(--line);
      display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    }
    .tpl-foot #presets { grid-column: 1 / -1; margin-bottom: 2px; }
    .tpl-foot .btn-random, .tpl-foot .btn-share-full { margin-top: 0; }
    /* iPhone 上字号小于 16px 的输入框一点就会放大页面 */
    input[type=text], input[type=number], textarea { font-size: 16px !important; }
  }
  /* 触屏：没有悬停，自定义模版的删除按钮一直显示 */
  @media (hover: none) {
    .tpl-del { opacity: 1; }
  }



/* Settings and preset library occupy independent columns. */
@media (min-width: 961px) {
  .main { grid-template-columns: 250px minmax(0, 1fr) 520px; }
  .side-r { display: grid; grid-template-columns: minmax(0, 308px) minmax(0, 212px); gap: 0; }
  .side-r .tpl-panel { margin-right: 6px; margin-left: 6px; }
}
.preset-panel { min-height: 0; overflow: hidden; display: flex; flex-direction: column; margin: 12px 12px 16px 6px; padding: 16px 12px; border-radius: 20px; background: var(--panel); box-shadow: var(--card-shadow); }
.preset-heading { display: flex; justify-content: space-between; align-items: center; padding: 0 2px 14px; font-size: 13px; font-weight: 600; }
.preset-heading span { color: var(--muted); font-size: 11px; font-weight: 400; }
.preset-panel #presets { display: flex; flex-direction: column; flex-wrap: nowrap; overflow: auto; min-height: 0; gap: 8px; margin: 0; padding: 1px; }
.preset-panel .chip { flex: none; width: 100%; height: auto; min-height: 52px; display: flex; align-items: center; gap: 9px; padding: 7px; text-align: left; white-space: normal; line-height: 1.4; border-radius: 12px; }
.preset-swatch { display: block; flex: 0 0 40px; width: 40px; height: 36px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(128,128,128,.12); }
@media (max-width: 960px) {
  .side-r { display: grid; grid-template-columns: minmax(0, 1fr) minmax(130px, .6fr); align-items: start; }
  .side-r .tpl-panel { margin-right: 4px; margin-left: 8px; min-width: 0; }
  .preset-panel { margin-left: 4px; margin-right: 8px; position: sticky; top: 12px; max-height: 72vh; padding: 12px 8px; }
  .preset-panel .chip { font-size: 11px; gap: 6px; }
  .preset-swatch { flex-basis: 28px; width: 28px; height: 32px; }
  .m-foot { grid-column: 1 / -1; }
}
@media (min-width: 961px) {
  .main { grid-template-columns: 220px minmax(0, 1fr) 710px; }
  .side-r { grid-template-columns: minmax(0, 300px) minmax(0, 200px) minmax(0, 210px); }
}
.custom-panel { gap: 10px; }
.custom-panel .preset-heading { padding-bottom: 0; }
#custom-json { flex: 1; min-height: 240px; width: 100%; resize: none; box-sizing: border-box; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--text); font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; overflow: auto; }
@media (max-width: 960px) {
  .custom-panel { grid-column: 1 / -1; position: static; max-height: none; }
  #custom-json { height: 360px; flex: none; }
}
.stage-controls { display: flex; align-items: center; justify-content: center; gap: 10px; flex: none; z-index: 2; }
.stage-controls .btn-random, .stage-controls .play-btn { width: 40px; height: 40px; padding: 0; margin: 0; border-radius: 50%; }
.demo[data-size=full] ~ .stage-controls { position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); }
@media (max-width: 960px) {
  .stage > .stage-controls { position: relative; margin-top: -66px; }
  .stage-controls .stage-float-btn { background: var(--panel); }
  .demo[data-size=full] ~ .stage-controls { left: auto; bottom: auto; transform: none; }
}
