:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --ink: #2c3e50;
  --muted: #6b7c8c;
  --line: #d6e0e8;
  --accent: #456b86;
  --err: #b4452f;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top   top"
    "stage side"
    "foot  foot";
}
@media (min-width: 761px) {
  body { height: 100vh; overflow: hidden; }
}

/* 右侧栏：桌面端整体作为右侧栏（纵列堆叠）；窄屏 display:contents 让子项进入 body 网格重排 */
.side {
  grid-area: side;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
}

/* ---------- 顶栏（仅标题） ---------- */
.topbar {
  grid-area: top;
  display: flex; align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; }
.brand .ver {
  font-size: 12px; font-weight: 600; color: #fff; background: var(--accent);
  padding: 2px 8px; border-radius: 10px; margin-left: 6px;
}

/* ---------- 页脚（ICP 备案） ---------- */
.site-footer {
  grid-area: foot;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 18px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- 主画布 ---------- */
.stage {
  grid-area: stage;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow: hidden; min-height: 300px;
}
.fractal-svg {
  width: 100%; height: 100%;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.fractal-svg svg { display: block; width: 100%; height: 100%; }

/* ---------- 面板通用 ---------- */
.panel { background: var(--panel); padding: 14px 16px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--accent); }
.params { border-bottom: 1px solid var(--line); }
.stats  { border-bottom: 1px solid var(--line); }
/* 仅在窄屏（aside 为 display:contents）时作为 body 网格项生效 */
.params { grid-area: params; }
.stats  { grid-area: stats; }
.help   { grid-area: help; }
/* 仅作用于「分形规则」区块：标题 15px 半粗体，正文/公式 14px 行高 1.6，各条间隔 6px，正文略加深 */
.help details { font-size: 14px; color: #4a5a68; overflow-wrap: break-word; }
.help summary { cursor: pointer; font-size: 15px; font-weight: 600; color: var(--accent); }
.help details li,
.help details p { line-height: 1.6; }
.help ul { margin: 8px 0 0; padding-left: 18px; }
.help ul li { margin-bottom: 6px; }

/* ---------- 步进控件 ---------- */
.stepper-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.ctl-name { font-size: 13px; font-weight: 600; color: var(--muted); }

.stepper { display: flex; align-items: stretch; gap: 8px; }
.step-btn {
  flex: 0 0 auto;
  width: 48px; height: 48px; min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; line-height: 1;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--accent); cursor: pointer;
  user-select: none;
}
.step-btn:hover:not(:disabled) { background: #eef4f8; }
.step-btn:active:not(:disabled) { transform: translateY(1px); }
.step-btn:disabled { opacity: .35; cursor: not-allowed; }

#depth, #branches {
  flex: 1 1 auto; min-width: 0;
  height: 48px; text-align: center;
  font-size: 20px; font-weight: 700; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 0 8px;
  -moz-appearance: textfield; appearance: textfield;
}
#depth::-webkit-inner-spin-button,
#branches::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#depth:focus, #branches:focus { outline: 2px solid #b9d0e0; border-color: var(--accent); }

.ctl-hint { font-size: 11px; color: var(--muted); margin: 0; line-height: 1.45; }

/* ---------- 恢复默认 ---------- */
.reset-btn {
  margin-top: 4px; padding: 10px 14px;
  font-size: 14px; font-weight: 600;
  border: 1px solid var(--accent); border-radius: 10px;
  background: #fff; color: var(--accent); cursor: pointer;
}
.reset-btn:hover { background: #eef4f8; }

/* ---------- 参数附近的错误提示 ---------- */
.param-msg {
  margin: 10px 0 0; font-size: 13px; color: var(--err); line-height: 1.5;
}
.param-msg[hidden] { display: none; }

/* ---------- 统计 ---------- */
.stat-summary {
  font-size: 15px; padding: 10px 12px; background: #f3f7fa;
  border-radius: 8px; margin-bottom: 8px;
}
.stat-summary b { font-size: 18px; color: var(--accent); }
.stat-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 4px 8px; border-radius: 999px;
  background: #e7eef4; color: var(--muted); font-weight: 600;
}
.chip.bad { background: #fbeae6; color: var(--err); }

/* ---------- 窄屏：参数 → 图形 → 统计 ---------- */
@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-template-areas:
      "top"
      "params"
      "stage"
      "stats"
      "help"
      "foot";
  }
  /* aside 容器不再占位，子项作为 body 网格项参与重排 */
  .side { display: contents; border-left: none; }
  .panel { padding: 12px 14px; }
  .stage { min-height: 320px; padding: 12px; }
  .ctl-hint { max-width: 100%; }
}
