/* ============================================================
   Fractal Mandala — styles
   三套暗色主题：minimal / neon / gloomy，由 [data-theme] 切换
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

/* 修复：确保 hidden 属性始终隐藏元素，不被 display:flex/grid 覆盖 */
[hidden] { display: none !important; }

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .22s cubic-bezier(.4,0,.2,1);
  --font: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ---------- 主题：简约 Minimal ---------- */
body[data-theme="minimal"] {
  --bg: #15151a;
  --bg-elev: #1c1c22;
  --bg-elev2: #23232b;
  --panel: #1b1b21;
  --card: #1e1e25;
  --border: #2c2c36;
  --text: #e6e6ea;
  --text-dim: #9a9aa6;
  --text-mute: #6b6b78;
  --accent: #7aa2f7;
  --accent-2: #bb9af7;
  --danger: #f7768e;
  --glow: 0 0 0 transparent;
  --text-glow: none;
  --shadow: 0 6px 18px rgba(0,0,0,.35);
  --shadow-soft: 0 2px 8px rgba(0,0,0,.25);
}

/* ---------- 主题：霓虹 Neon ---------- */
body[data-theme="neon"] {
  --bg: #07070d;
  --bg-elev: #0d0d18;
  --bg-elev2: #12121f;
  --panel: #0a0a14;
  --card: #0e0e1a;
  --border: #1f1f38;
  --text: #e8f7ff;
  --text-dim: #8fa8c8;
  --text-mute: #5a6a85;
  --accent: #00f0ff;
  --accent-2: #ff2bd6;
  --danger: #ff4d6d;
  --glow: 0 0 12px rgba(0,240,255,.55), 0 0 30px rgba(255,43,214,.25);
  --text-glow: 0 0 8px rgba(0,240,255,.6);
  --shadow: 0 8px 28px rgba(0,0,0,.6), 0 0 0 1px rgba(0,240,255,.15);
  --shadow-soft: 0 2px 10px rgba(0,0,0,.5);
}

/* ---------- 主题：阴暗 Gloomy ---------- */
body[data-theme="gloomy"] {
  --bg: #0b0a0c;
  --bg-elev: #121013;
  --bg-elev2: #18151a;
  --panel: #100e11;
  --card: #151216;
  --border: #241f25;
  --text: #cfc8c0;
  --text-dim: #8a8079;
  --text-mute: #5c544e;
  --accent: #a65a5a;
  --accent-2: #7a5a8a;
  --danger: #c45a5a;
  --glow: 0 0 0 transparent;
  --text-glow: none;
  --shadow: 0 10px 30px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.03);
  --shadow-soft: 0 3px 12px rgba(0,0,0,.6);
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

body[data-theme="neon"] { background-image:
  radial-gradient(1000px 600px at 85% -10%, rgba(0,240,255,.06), transparent 60%),
  radial-gradient(800px 500px at -10% 110%, rgba(255,43,214,.06), transparent 60%); }
body[data-theme="gloomy"] { background-image:
  radial-gradient(900px 600px at 50% -20%, rgba(122,90,138,.08), transparent 60%); }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: var(--glow);
  position: relative;
}
.brand-logo::after {
  content: ""; position: absolute; inset: 6px; border-radius: 4px;
  background: var(--bg-elev);
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .5px; }
.brand-sub { font-size: 10px; color: var(--text-mute); letter-spacing: 2px; text-transform: uppercase; }

.topbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.control-group { display: flex; align-items: center; gap: 6px; }
.ctl-label { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.ctl-select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-color: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 24px 6px 10px; font-size: 12px; font-family: var(--font);
  cursor: pointer; outline: none;
  /* 与整体暗色主题一致的自绘下拉箭头 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' fill='none' stroke='%239a9aa6' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 9px 6px;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}
.ctl-select:hover { border-color: var(--accent); }
.ctl-select:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ctl-select option { background: var(--bg-elev2); color: var(--text); }

/* ---------------- 自绘下拉框（主题化弹出列表） ---------------- */
.ff-select { position: relative; display: inline-flex; vertical-align: middle; }
.ff-select > select { opacity: 0; pointer-events: none; }
.ff-select-trigger {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: flex; align-items: center; text-align: left;
  padding: 0 20px 0 8px; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ff-select.open > .ff-select-trigger { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ff-select-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 2000;
  min-width: 100%; max-height: 240px; overflow: auto;
  padding: 4px; display: flex; flex-direction: column; gap: 2px;
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.ff-select-menu[hidden] { display: none; }
.ff-select.align-right .ff-select-menu { left: auto; right: 0; }
.ff-select-option {
  display: block; width: 100%; text-align: left;
  padding: 6px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text);
  font-family: var(--font); font-size: 12px; white-space: nowrap; cursor: pointer;
}
.ff-select-option:hover, .ff-select-option:focus { background: var(--bg-elev); color: var(--accent); outline: none; }
.ff-select-option.is-selected { color: var(--accent); }
.param-field .ff-select { width: 100%; }
.param-field .ff-select-trigger { font-family: var(--mono); }
.exp-size .ff-select-trigger { font-size: 11px; padding: 0 18px 0 6px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 13px; font-size: 12px; font-family: var(--font);
  cursor: pointer;
  /* 只过渡颜色/阴影/位移动画，避免中英文切换时字体与内边距被过渡、导致按钮宽度抖动闪现 */
  transition: color var(--transition), background-color var(--transition),
    border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap; user-select: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn:disabled:hover { border-color: var(--border); color: var(--text); transform: none; }
.btn.small { padding: 5px 10px; font-size: 11px; }
.btn-primary { background: var(--accent); color: #0b0b10; border-color: var(--accent); font-weight: 600; box-shadow: var(--glow); }
body[data-theme="minimal"] .btn-primary { color: #fff; }
.btn-primary:hover { filter: brightness(1.1); color: #0b0b10; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.theme-switcher { display: flex; gap: 2px; background: var(--bg-elev2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.theme-btn {
  width: 26px; height: 26px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 5px; cursor: pointer; font-size: 13px; transition: all var(--transition);
}
.theme-btn:hover { color: var(--text); }
.theme-btn.active { background: var(--accent); color: #0b0b10; box-shadow: var(--glow); }
body[data-theme="minimal"] .theme-btn.active { color: #fff; }

/* ---------------- Layout ---------------- */
.layout {
  display: flex; gap: 14px;
  padding: 14px 18px 40px;
  min-height: calc(100vh - 57px);
}
.grid-area { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.grid-toolbar { display: flex; align-items: center; justify-content: space-between; }
.grid-info { font-size: 12px; color: var(--text-dim); }
.grid-toolbar-right { display: flex; gap: 8px; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* ---------------- Card ---------------- */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), var(--glow); }
.card.selected::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 1px var(--accent);
  z-index: 3; border-radius: var(--radius);
}
.card-canvas-wrap { position: absolute; inset: 0; }
.card-canvas-wrap canvas { width: 100%; height: 100%; display: block; }

.card-overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 10px; opacity: 0; transition: opacity var(--transition);
  background: linear-gradient(180deg, rgba(0,0,0,.5) 0%, transparent 30%, transparent 60%, rgba(0,0,0,.65) 100%);
}
.card:hover .card-overlay, .card.selected .card-overlay { opacity: 1; }
.card-tag {
  align-self: flex-start;
  background: rgba(0,0,0,.55); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 10px; font-size: 10px; letter-spacing: .5px;
  backdrop-filter: blur(4px);
}
.card-actions { display: flex; gap: 6px; align-self: flex-end; }
.card-actions .btn { padding: 5px 9px; font-size: 10px; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); }

.card-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-mute); font-size: 11px; z-index: 1;
}
.card-loading::after {
  content: ""; position: absolute; width: 26px; height: 26px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Param Panel ---------------- */
.panel {
  width: 320px; flex-shrink: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  max-height: calc(100vh - 90px); position: sticky; top: 71px;
  overflow-y: auto;
  box-shadow: var(--shadow-soft);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-title { font-weight: 600; font-size: 13px; }
.panel-actions { display: flex; gap: 6px; }
.panel-meta { font-size: 11px; color: var(--text-mute); font-family: var(--mono); word-break: break-all; }
.param-controls { display: flex; flex-direction: column; gap: 12px; }
.param-controls::-webkit-scrollbar { width: 6px; }
.param-controls::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.param-field { display: flex; flex-direction: column; gap: 5px; }
.param-field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.param-field label { font-size: 11px; color: var(--text-dim); }
.param-field .param-val { font-size: 11px; color: var(--accent); font-family: var(--mono); }
.param-field input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--bg-elev2); border-radius: 2px; outline: none;
}
.param-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: var(--glow);
}
.param-field input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: none;
  background: var(--accent); cursor: pointer;
}
.param-field select, .param-field input[type="number"] {
  background-color: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 7px; font-size: 12px; font-family: var(--mono); outline: none; width: 100%;
}
.param-field select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding: 5px 24px 5px 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' fill='none' stroke='%239a9aa6' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 9px 6px;
}
.param-field select option { background: var(--bg-elev2); color: var(--text); }
.param-field select:focus, .param-field input[type="number"]:focus { border-color: var(--accent); }
.panel-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.panel-hint { font-size: 10px; color: var(--text-mute); line-height: 1.6; }

/* ---------------- Explorer ---------------- */
.explorer {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.explorer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.explorer-title { font-weight: 600; font-size: 13px; color: #D0FE17; }
.explorer-tools { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.explorer-head > #btnExpClose { margin-left: 8px; }
.exp-size { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); }
.exp-size .ctl-select {
  padding: 4px 20px 4px 8px; font-size: 11px;
  /* 固定宽度，避免切换 512 / 1024 / 2K 时下拉框宽度变化导致周围按钮乱晃 */
  width: 60px; flex: 0 0 auto;
}
.explorer-stage {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #000;
}
#explorerCanvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: grab; display: block; }
#explorerCanvas:active { cursor: grabbing; }

/* 桌面端：参数 / 形状编辑 / 关键帧面板统一浮在画面左侧黑边，把高度让给图像 */
.explorer-side {
  position: absolute; top: 14px; bottom: 14px; left: 14px;
  width: min(26vw, 440px); z-index: 6; min-height: 0;
  display: flex; flex-direction: column;
  background: rgba(10,10,16,.92);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(6px); overflow: hidden;
}
/* 浮层里的页签内容占满整块高度并自行滚动 */
.explorer-side .explorer-tab-page { flex: 1; min-height: 0; overflow-y: auto; }
.explorer-side .explorer-panel { grid-template-columns: 1fr; padding: 10px 12px; }
.explorer-side .explorer-shape-panel {
  display: flex; flex-direction: column; min-height: 0; flex: 1;
  border: 0; background: transparent;
}
.explorer-side .explorer-shape-panel .shape-panel-body {
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 10px; overflow-y: auto; min-height: 0; flex: 1;
}
/* 四象限画布在浮层里放大到约 2 倍（原 156px → 312px），并在框内水平居中 */
.explorer-side .explorer-shape-panel .shape-stage { width: min(100%, 312px); max-width: 100%; margin: 0 auto; }
.explorer-side .shape-list { max-height: 140px; }
.explorer-side .animation-panel { padding: 10px 12px; gap: 10px; }
.explorer-side .keyframe-list { flex-wrap: wrap; overflow-x: visible; }
.explorer-side .timeline-track { min-width: 120px; }
/* 内容浮到左侧时，底部面板只保留页签栏，把高度让给画面 */
.explorer.explorer-side-mode .explorer-dock { height: auto; min-height: 0; }
/* 桌面端左侧有调整面板时，让舞台为面板留出宽度，图像在剩余区域内居中，避免紧贴面板 */
.explorer.explorer-side-mode .explorer-stage { padding-left: calc(min(26vw, 440px) + 28px); }
@media (max-width: 860px) {
  .explorer-side { display: none !important; }
}
.explorer-progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: rgba(0, 0, 0, .45); overflow: hidden;
  opacity: 0; transition: opacity .18s; pointer-events: none;
}
.explorer-progress.active { opacity: 1; }
.explorer-progress span {
  display: block; height: 100%; width: 34%;
  background: linear-gradient(90deg, #1f9d55, #3ee089);
  box-shadow: 0 0 10px rgba(62, 224, 137, .75);
  transform: translateX(-110%);
  animation: expProgress 1.1s ease-in-out infinite;
}
/* 确定性进度（火焰渐进采样）：按真实进度填充，不再来回扫动 */
.explorer-progress.determinate span {
  width: 0%;
  transform: none;
  animation: none;
  transition: width .16s linear;
}
@keyframes expProgress {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(400%); }
}
.explorer-dock {
  flex-shrink: 0; height: 300px; min-height: 0; max-height: 60vh;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border); background: var(--panel);
}
.explorer-tabs {
  flex-shrink: 0; display: flex; gap: 6px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.explorer-tab.active { color: var(--accent); border-color: var(--accent); background: var(--bg-elev2); }
.explorer-tab-page { flex: 1; min-height: 0; overflow-y: auto; }
#explorerShapePage.explorer-tab-page { overflow-y: hidden; }
.explorer-panel {
  padding: 12px 16px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 18px;
}

/* ---------------- 形状编辑（内嵌面板） ---------------- */
.shape-panel {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev2);
  overflow: hidden;
}
.shape-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.shape-panel-title { font-weight: 600; font-size: 12px; }
.shape-panel-body {
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px;
}
.shape-panel.collapsed .shape-panel-body { display: none; }
.shape-panel-unavailable {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-dim, #8a95b4);
  background: rgba(120, 70, 40, 0.08);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  letter-spacing: .3px;
}
.shape-panel.disabled .shape-panel-head {
  background: rgba(80, 80, 80, 0.2);
  color: var(--text-dim, #8a95b4);
}
.shape-panel.disabled .shape-panel-title {
  color: var(--text-dim, #8a95b4);
}
.shape-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.shape-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #05050b;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,.7);
}
#shapeCanvas, #expShapeCanvas {
  width: 100%; height: 100%;
  touch-action: none; cursor: crosshair;
  display: block;
}
.shape-hud {
  position: absolute; left: 8px; bottom: 6px; right: 8px;
  color: #b9c6e6; font-size: 10px; line-height: 1.4;
  text-shadow: 0 1px 4px #000; pointer-events: none;
}
.shape-side { display: flex; flex-direction: column; gap: 2px; }
.shape-side-title { font-size: 11px; color: var(--text-dim); margin: 8px 0 6px; letter-spacing: .5px; text-transform: uppercase; }
.shape-side-title:first-child { margin-top: 0; }
.shape-list { display: flex; flex-direction: column; gap: 6px; max-height: 170px; overflow-y: auto; }
.shape-list::-webkit-scrollbar { width: 5px; }
.shape-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.shape-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elev2); color: var(--text);
  cursor: pointer; font-size: 12px; text-align: left;
}
.shape-row.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.shape-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.shape-variation { width: 100%; }
#shapeMix, #expShapeMix { width: 100%; }

.explorer-shape-panel { border: 0; border-radius: 0; }
.explorer-shape-panel .shape-panel-head { padding: 6px 10px; }
.explorer-shape-panel .shape-panel-body {
  display: grid; grid-template-columns: minmax(140px, 156px) minmax(150px, 1fr);
  align-items: start; gap: 6px 12px; padding: 6px 12px;
}
.explorer-shape-panel .shape-tools { grid-column: 1 / -1; gap: 4px; }
.explorer-shape-panel .shape-tools .btn.small { padding: 3px 8px; }
.explorer-shape-panel .shape-stage { width: min(100%, 156px); }
.explorer-shape-panel .shape-hud { padding: 3px 5px; left: 4px; bottom: 4px; right: 4px; }
.explorer-shape-panel .shape-side-title { margin: 4px 0 3px; }
/* 形状列表改为小标签横向排列，不再一条占一整行 */
.explorer-shape-panel .shape-list {
  flex-direction: row; flex-wrap: wrap; gap: 4px;
  max-height: 54px; overflow-y: auto;
}
.explorer-shape-panel .shape-row {
  width: auto; padding: 4px 8px; gap: 5px; white-space: nowrap;
}
.explorer-shape-panel .shape-dot { width: 10px; height: 10px; }
.explorer-shape-panel .shape-variation { padding: 4px 20px 4px 6px; }

/* ---------------- 关键帧与视频 ---------------- */
.animation-panel { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.keyframe-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.animation-duration { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 11px; }
.animation-duration input {
  width: 64px; background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px;
  font: 12px var(--mono); outline: none;
}
.animation-duration input:focus { border-color: var(--accent); }
.keyframe-list { display: flex; gap: 8px; overflow-x: auto; min-height: 38px; padding-bottom: 2px; }
.keyframe-row {
  flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elev2); color: var(--text); cursor: pointer; font-size: 11px;
}
.keyframe-row.active { border-color: var(--accent); color: var(--accent); }
.keyframe-row small { color: var(--text-mute); font-size: 9px; }
.keyframe-empty { color: var(--text-mute); font-size: 11px; align-self: center; }
.timeline-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.timeline-actions { display: flex; align-items: center; gap: 10px; }
.timeline-track { position: relative; flex: 1; min-width: 160px; display: flex; align-items: center; }
.timeline-scrubber { width: 100%; accent-color: var(--accent); cursor: pointer; }
/* 关键帧标记层：覆盖在滑块轨道上，左右内缩约半个滑块拇指，位置更贴合拇指中心 */
.timeline-markers { position: absolute; left: 7px; right: 7px; top: 0; bottom: 0; pointer-events: none; }
.timeline-marker {
  position: absolute; top: 50%; width: 9px; height: 9px; padding: 0;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--text-mute); border: 1px solid var(--bg-elev); border-radius: 2px;
  cursor: pointer; pointer-events: auto; transition: background var(--transition), box-shadow var(--transition);
}
.timeline-marker:hover { background: var(--accent); }
.timeline-marker.active { background: var(--accent); box-shadow: 0 0 0 2px rgba(122,162,247,.35); }
.timeline-marker:disabled { cursor: not-allowed; opacity: .45; }
.timeline-time { min-width: 92px; text-align: right; color: var(--text-dim); font: 11px var(--mono); }
.animation-status { min-height: 18px; color: var(--text-mute); font-size: 11px; }
.animation-status.is-exporting { color: #D0FE17; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------------- 通道背景 ---------------- */
body.alpha-bg .card-canvas-wrap,
body.alpha-bg .explorer-stage {
  background-image: conic-gradient(#2b2b33 0 25%, #1b1b21 0 50%, #2b2b33 0 75%, #1b1b21 0);
  background-size: 18px 18px;
}

/* ---------------- 导出格式弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(2px);
}
.modal-card {
  width: min(440px, 100%);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 10px;
}
.modal-title { font-size: 14px; font-weight: 600; }
.modal-desc { font-size: 12px; line-height: 1.6; color: var(--text-dim); }
.modal-field {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; font-size: 12px; color: var(--text-dim);
}
.modal-field .ctl-select { min-width: 110px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* ---------------- 联系作者 ---------------- */
.btn-contact {
  background: #D0FE17;
  color: #0b0b12;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  padding: 7px 16px;
  font-size: 12px;
  letter-spacing: .5px;
  box-shadow: 0 2px 12px rgba(208, 254, 23, .35);
}
.btn-contact:hover { filter: brightness(1.08); color: #0b0b12; transform: translateY(-1px); }

/* 导出视频按钮：与探索标题一致的荧光绿 */
#btnExpVideo {
  background: #D0FE17;
  border-color: #D0FE17;
  color: #0b0b12;
  box-shadow: 0 2px 12px rgba(208, 254, 23, .35);
}
#btnExpVideo:hover { filter: brightness(1.08); color: #0b0b12; }
.btn-contact:active { transform: translateY(0); }
/* 手机端专用：与「通道背景」同处控制栏，贴最右；桌面端隐藏 */
#btnContactMobile { display: none; }
/* 「通道背景 + 联系作者」组：桌面端透明（不改变原有布局），手机端合为一行 */
.topbar-end { display: contents; }
/* 手机端换行占位，桌面端不占位 */
.topbar-break { display: none; }
/* 英文模式手机端第二处换行占位，默认不显示 */
.topbar-break2 { display: none; }

/* 联系作者二维码：改成锚定在按钮下方的气泡浮层（透明遮罩用于点击外部关闭） */
.contact-modal {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.contact-pop {
  position: fixed;
  left: 0; top: 0;
  width: min(300px, 82vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  animation: popIn .22s ease;
}
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }
.contact-qr {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 12px; display: block; background: #000;
}
.contact-caption { font-size: 13px; color: var(--text-dim); letter-spacing: 1px; }
.contact-close {
  position: absolute; top: 4px; right: 8px;
  background: transparent; border: none; color: var(--text-mute);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 6px;
}
.contact-close:hover { color: var(--text); }
/* 气泡箭头：指向“联系作者”按钮，水平位置由脚本写入 --arrow-x */
.contact-pop::before {
  content: '';
  position: absolute;
  top: -7px;
  left: var(--arrow-x, 50%);
  width: 14px; height: 14px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  border-radius: 3px;
  pointer-events: none;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 12px; z-index: 200;
  box-shadow: var(--shadow); animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .layout { flex-direction: column; padding: 10px; }
  .panel {
    width: 100%; position: static; max-height: none;
    order: 2;
  }
  .panel.collapsed .param-controls,
  .panel.collapsed .panel-meta,
  .panel.collapsed .shape-panel,
  .panel.collapsed .panel-foot { display: none; }
  .grid-area { order: 1; }
  .topbar { gap: 10px; padding: 8px 10px; }
  .brand-text { display: none; }
  .topbar-controls { gap: 6px; }
  .ctl-label { display: none; }
  /* 手机端：移除首页参数微调面板、其切换按钮，以及预览卡片的「形状」按钮 */
  .panel { display: none !important; }
  #btnPanelToggle { display: none !important; }
  .card-actions [data-act="shape"] { display: none !important; }
  /* 联系作者：手机端改用控制栏内的按钮，与「通道背景」齐平并贴最右 */
  #btnContact { display: none !important; }
  #btnContactMobile { display: inline-flex !important; }
  /* 手机端二维码尺寸缩小一半（原 300px → 164px，二维码约 136px） */
  .contact-pop { width: min(164px, 46vw); }
  /* 手机端顶栏改为单一弹性行：数量/分辨率/类型在第一行，
     「随机生成 + 通道背景」从第二行起左对齐，并与主题按钮同一行 */
  .topbar { display: flex; flex-wrap: wrap; gap: 8px 6px; }
  .topbar-controls, .topbar-end, .topbar-right { display: contents; }
  .brand { order: 1; }
  .topbar-controls .control-group:nth-child(1) { order: 2; }  /* 数量 */
  .topbar-controls .control-group:nth-child(2) { order: 3; }  /* 分辨率 */
  .topbar-controls .control-group:nth-child(3) { order: 4; }  /* 类型 */
  /* 联系作者：第一行最右，与类型选择齐平 */
  #btnContactMobile { order: 5; margin-left: auto; }
  /* 换行占位：强制把「随机生成/通道背景」挤到第二行 */
  .topbar-break { display: block; order: 6; flex: 0 0 100%; height: 0; }
  #btnRandom { order: 7; }
  #btnExportAll { order: 8; }
  #btnChannel { order: 9; }
  .theme-switcher { order: 10; margin-left: auto; }
  #btnLang { order: 11; }
  /* 英文模式：联系作者保持第一行最右（与中文一致），分形类型选择移到第二行最右，
     主题与语言按钮另起第三行靠右 */
  body[data-lang="en"] #btnContactMobile { order: 5; margin-left: auto; }
  body[data-lang="en"] .topbar-controls .control-group:nth-child(3) { order: 10; margin-left: auto; }
  body[data-lang="en"] .topbar-break2 { display: block; order: 11; flex: 0 0 100%; height: 0; }
  body[data-lang="en"] .theme-switcher { order: 12; margin-left: auto; }
  body[data-lang="en"] #btnLang { order: 13; }
  /* 数量 / 分辨率选择框固定尺寸，避免切换中英文时原生下拉框被挤压变形 */
  #countSelect, #resSelect {
    width: 52px; height: 31px; flex: 0 0 auto;
    padding: 0 20px 0 8px;
  }
  #resSelect { width: 68px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .layout { padding: 8px; gap: 10px; }
  .topbar-controls .btn { padding: 6px 8px; font-size: 11px; }
  .btn-contact { padding: 6px 8px; font-size: 11px; }
  /* 手机端英文按钮文字较长，收窄按钮间与按钮内边距，避免开启通道背景后把联系作者挤到下一行 */
  body[data-lang="en"] .topbar { column-gap: 4px; }
  body[data-lang="en"] .topbar-controls .btn { padding: 6px 7px; font-size: 10.5px; }
  /* 英文分形类型选项文字较长，收窄选择框，避免第二行放不下被挤到下一行 */
  body[data-lang="en"] #typeSelect { font-size: 11px; padding: 6px 4px; max-width: 126px; }
  #btnExportAll { display: none; }
  .explorer-panel { grid-template-columns: 1fr 1fr; }
  .explorer-dock { max-height: 68vh; }
  /* 手机端：关闭按钮与标题同排并靠右，其余工具放到下一行 */
  .explorer-head {
    display: grid; grid-template-columns: 1fr auto; align-items: center;
    row-gap: 8px;
  }
  .explorer-title { grid-column: 1; grid-row: 1; }
  .explorer-head > #btnExpClose { grid-column: 2; grid-row: 1; justify-self: end; margin-left: 8px; }
  .explorer-tools { grid-column: 1 / -1; grid-row: 2; width: 100%; flex-wrap: wrap; margin-left: 0; }
  #btnExpReset { margin-left: auto; }
  .explorer-shape-panel .shape-panel-body { display: flex; }
  .explorer-shape-panel .shape-stage { width: min(100%, 320px); align-self: center; }
  .explorer-tabs { overflow-x: auto; }
  /* 手机端视频界面：导出视频按钮单独换行并靠左，时长/时间文字在其右侧并右对齐 */
  .timeline-actions { order: 4; width: 100%; }
  #btnExpVideo { order: -1; }
  .timeline-time { min-width: 80px; margin-left: auto; }
  /* 手机端英文模式：隐藏探索顶部的“分辨率”文字，仅保留选择框 */
  body[data-lang="en"] .exp-size > span[data-i18n="resolution"] { display: none; }
}
@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
}

/* empty state */
.grid:empty::after {
  content: attr(data-empty);
  grid-column: 1 / -1; text-align: center;
  padding: 60px 20px; color: var(--text-mute); font-size: 13px;
}

/* 手机端：隐藏探索面板内多余的滚动条 */
@media (max-width: 860px) {
  .explorer-tab-page,
  .explorer-tab-page .explorer-panel,
  .animation-panel,
  .shape-panel-body,
  .shape-list,
  .keyframe-list { scrollbar-width: none; -ms-overflow-style: none; }
  .explorer-tab-page::-webkit-scrollbar,
  .explorer-tab-page .explorer-panel::-webkit-scrollbar,
  .animation-panel::-webkit-scrollbar,
  .shape-panel-body::-webkit-scrollbar,
  .shape-list::-webkit-scrollbar,
  .keyframe-list::-webkit-scrollbar { width: 0; height: 0; display: none; }
}
