/* ============================================================
   @standard/preview-browser · 页面样式（白色主题）
   ------------------------------------------------------------
   共用：.bar / button / .status / .placeholder / .logs
   demo/index.html   .layout        左侧预览 + 右侧日志
   demo/studio.html  .home          能力卡片 + 搜索 + 预览
   demo/preview.html .preview-split 文件树 + 源码 + 预览（可拖） + 下方控制台
   ============================================================ */

:root {
  color-scheme: light;

  --bg: #ffffff;
  --surface: #fafbfc;
  --surface-2: #f2f4f7;
  --line: #e8eaee;
  --line-strong: #d5d9e0;
  --ink: #101318;
  --text: #22262d;
  --muted: #69707c;
  --faint: #98a0ac;

  --accent: #1f6feb;
  --accent-soft: #eef5ff;
  --ok: #11795f;
  --warn: #9a6700;
  --err: #c0362c;

  --radius: 12px;
  --shadow-card: 0 1px 2px rgba(16, 19, 24, 0.04);
  --shadow-lift: 0 16px 36px -24px rgba(16, 19, 24, 0.5);

  --font-sans:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', sans-serif;
  --font-mono: 'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

::selection {
  background: #dbe8ff;
}

/* ------------------------------------------------------------
   顶栏
   ------------------------------------------------------------ */

.bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  font-size: 15px;
  letter-spacing: -0.01em;
}

.mark {
  position: relative;
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--ink);
}

.mark::after {
  content: '';
  position: absolute;
  inset: 5px 5px 6px 5px;
  border: 1.5px solid #fff;
  border-radius: 2px;
  border-bottom-color: transparent;
  border-right-color: transparent;
}

.tag {
  padding-left: 9px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 0;
}

/* ------------------------------------------------------------
   按钮
   ------------------------------------------------------------ */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: #b8bfca;
  background: var(--surface);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.primary,
#start {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}

.primary:hover:not(:disabled),
#start:hover:not(:disabled) {
  border-color: #000;
  background: #000;
}

.primary[aria-disabled='true'] {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.ghost {
  padding: 5px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.ghost:hover:not(:disabled) {
  border-color: transparent;
  background: var(--surface-2);
  color: var(--text);
}

/* ------------------------------------------------------------
   状态胶囊
   ------------------------------------------------------------ */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 52ch;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.65;
}

.status[data-tone='busy'] {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 32%, #fff);
  background: #fffdf5;
}

.status[data-tone='busy']::before {
  animation: pulse 1.2s ease-in-out infinite;
}

.status[data-tone='ok'] {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 28%, #fff);
  background: #f6fdfa;
}

.status[data-tone='error'] {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 28%, #fff);
  background: #fff7f6;
}

/* ------------------------------------------------------------
   预览舞台（studio / demo 共用）
   ------------------------------------------------------------ */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

#frame {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

#frame[data-visible='1'] {
  display: block;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow: auto;
  padding: 32px 24px;
  text-align: center;
  color: var(--muted);
  background: #fff;
}

.placeholder h1 {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.placeholder p {
  margin: 0;
  max-width: 52ch;
  font-size: 13px;
}

.placeholder .hint {
  color: var(--faint);
  font-size: 12px;
}

.placeholder .primary {
  margin-top: 10px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ------------------------------------------------------------
   日志 / 控制台输出
   ------------------------------------------------------------ */

.logs {
  flex: 1;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 8px 0;
  list-style: none;
  overflow: auto;
  background: #fcfcfd;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
}

.logs:empty::before {
  content: '日志会在这里滚动输出';
  display: block;
  padding: 6px 14px;
  color: var(--faint);
}

.logs li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 1px 14px;
  color: #3c434e;
  white-space: pre-wrap;
  word-break: break-word;
}

.logs li:hover {
  background: var(--surface-2);
}

.log-time {
  flex: none;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.log-line {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.logs li[data-level='command'] {
  color: var(--accent);
}

.logs li[data-level='error'] {
  color: var(--err);
}

.logs li[data-level='ready'] {
  color: var(--ok);
}

/* ------------------------------------------------------------
   demo/index.html：左侧预览 + 右侧日志
   ------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  flex: 1;
  min-height: 0;
}

.layout > .stage {
  border-right: 1px solid var(--line);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------------------------------------
   studio.html：能力卡片首页
   ------------------------------------------------------------ */

.home {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 24px 72px;
  background: linear-gradient(180deg, #fbfcfd 0, #fff 340px);
}

.home-inner {
  max-width: 1160px;
  margin: 0 auto;
}

.hero {
  padding: 40px 0 0;
}

.hero h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(26px, 3.4vw, 36px);
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 10px;
}

.search {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
  cursor: text;
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search svg {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--faint);
}

.search input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  appearance: none;
}

.search input::placeholder {
  color: var(--faint);
}

.search input::-webkit-search-cancel-button {
  appearance: none;
}

.preview-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(16, 19, 24, 0.14);
}

.preview-btn .count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.selection {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
}

.selection .spacer {
  flex: 1;
}

.selection .muted {
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.selection .ghost {
  font-size: 12px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(288px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-card);
  animation: card-in 0.32s ease backwards;
  animation-delay: calc(var(--i, 0) * 24ms);
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease,
    background-color 0.16s ease;
}

.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lift);
  transform: translateY(-1px);
}

.card-hit {
  position: relative;
  display: block;
  height: 100%;
  padding: 16px 16px 14px;
  cursor: pointer;
}

/* 视觉上隐藏但保留键盘可达性 */
.card-hit input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.card-check {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.card-check::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1.5px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 1.8px 1.8px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s ease;
}

.card-hit input:checked + .card-check {
  border-color: var(--ink);
  background: var(--ink);
}

.card-hit input:checked + .card-check::after {
  transform: rotate(45deg) scale(1);
}

.card-hit input:focus-visible + .card-check {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.card-hit input:disabled + .card-check {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.card-hit input:disabled:checked + .card-check {
  border-color: #c2c8d1;
  background: #c2c8d1;
}

.card-body {
  display: block;
  padding-right: 26px;
}

.card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 9px;
}

.card-group {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card-flag {
  margin-left: auto;
  color: var(--faint);
  font-size: 10.5px;
  white-space: nowrap;
}

.card-title {
  display: block;
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.card-name {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11.5px;
  word-break: break-all;
}

.card-desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.65;
}

.card-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  white-space: nowrap;
}

.chip.accent {
  border-color: color-mix(in srgb, var(--accent) 26%, #fff);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip.muted {
  border-style: dashed;
  color: var(--faint);
}

.card[data-state='selected'] {
  border-color: var(--ink);
}

.card[data-state='selected'] .card-flag {
  color: var(--ink);
}

.card[data-state='auto'],
.card[data-state='demo'] {
  border-style: dashed;
  background: var(--surface);
  box-shadow: none;
}

.card[data-state='auto']:hover,
.card[data-state='demo']:hover {
  transform: none;
  border-color: var(--line-strong);
  box-shadow: none;
}

.card[data-state='auto'] .card-title,
.card[data-state='demo'] .card-title {
  color: var(--muted);
}

.card[data-state='demo'] .card-hit {
  cursor: default;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 0;
  color: var(--muted);
  font-size: 13px;
}

.empty p {
  margin: 0;
}

/* ------------------------------------------------------------
   preview.html：文件树 | 源码 | 预览（带地址栏），下方控制台
   ------------------------------------------------------------ */

.preview-split {
  --stage: 62%;

  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, var(--stage)) 13px minmax(0, 1fr);
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* 三栏：文件树 | 编辑器 | 预览。宽度用变量存百分比，拖动分隔条时只改这两个变量。 */
.workbench {
  --stage-w: 44%;
  --tree-w: 20%;

  display: grid;
  grid-template-columns:
    minmax(0, var(--tree-w)) 13px
    minmax(0, 1fr) 13px
    minmax(0, var(--stage-w));
  min-width: 0;
  min-height: 0;
  background: #fff;
}

/* 折叠态：只留预览一列，文件树 / 编辑器 / 两条竖向分隔条都不再占位 */
.workbench.is-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.workbench.is-collapsed > .explorer,
.workbench.is-collapsed > #split-tree,
.workbench.is-collapsed > .code-pane,
.workbench.is-collapsed > #split-stage {
  display: none;
}

/* 折叠 / 展开按钮：浏览器栏的第一个位置，不悬浮、不叠在内容上。
   只有一枚箭头，所以是正方形的小按钮 */
.workbench-toggle {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 0.15s ease,
    border-color 0.15s ease;
}

.workbench-toggle:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--accent);
}

.workbench-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.workbench-toggle svg {
  flex: none;
  width: 15px;
  height: 15px;
}

/* 折叠时箭头翻向右边，指向「展开」 */
.workbench-toggle-chevron {
  transition: transform 0.15s ease;
}

.workbench.is-collapsed .workbench-toggle-chevron {
  transform: rotate(180deg);
}

.feature-chips {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #d7dbe2 transparent;
}

.feature-chips.is-scrollable {
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 22px), transparent 100%);
}

.feature-chips:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 5px;
}

.feature-chips::-webkit-scrollbar {
  height: 4px;
}

.feature-chips::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #d7dbe2;
}

.feature-chip {
  flex: none;
  max-width: 210px;
  overflow: hidden;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workbench > .stage {
  overflow: hidden;
}

/* 预览右上角的「浏览器地址栏」：显示 / 输入地址，回车或点「前往」跳转 */
.preview-page .stage {
  display: flex;
  flex-direction: column;
  background: #fff;
}

.stage-body {
  position: relative;
  flex: 1;
  min-height: 0;
}

.browser-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 9px;
  min-height: 35px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.browser-dots {
  display: flex;
  flex: none;
  gap: 4px;
}

.browser-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e0e4ea;
}

.address-form {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* 主机名太长（webcontainer-api.io 的随机域名），地址栏只显示路径；
   主机收成一个 tag，悬停用原生 tooltip 给出完整地址 */
.address-host {
  flex: none;
  max-width: 92px;
  padding: 1px 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.75;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
  user-select: none;
}

.address-host:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.address {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 24px;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.address::placeholder {
  color: var(--faint);
}

.address:hover:not(:disabled) {
  border-color: var(--line-strong);
}

.address:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, #fff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.address:disabled {
  background: var(--surface-2);
  color: var(--faint);
  cursor: not-allowed;
}

.address-go {
  flex: none;
  height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 11.5px;
}

.address-go:disabled {
  opacity: 0.42;
}

/* ------------------------------------------------------------
   目录树 / 源码面板
   ------------------------------------------------------------ */

.explorer,
.code-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

.pane-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 35px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.pane-title {
  flex: none;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pane-meta {
  flex: none;
  margin-left: auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pane-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-state {
  flex: none;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.6;
  white-space: nowrap;
}

.editor-state:empty {
  display: none;
}

.editor-state[data-tone='warn'] {
  border-color: color-mix(in srgb, var(--warn) 30%, #fff);
  background: #fffdf5;
  color: var(--warn);
}

.editor-state[data-tone='ok'] {
  border-color: color-mix(in srgb, var(--ok) 26%, #fff);
  background: #f6fdfa;
  color: var(--ok);
}

.pane-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 5px;
}

.pane-actions button {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
}

/* 目录树 */

.tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 0 14px;
  background: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  scrollbar-width: thin;
  scrollbar-color: #d7dbe2 transparent;
}

.tree-empty {
  margin: 0;
  padding: 16px 12px;
  color: var(--faint);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.7;
}

.tree-dir > .tree-children {
  display: block;
}

.tree-dir[data-open='0'] > .tree-children {
  display: none;
}

/* 一行 = 行本体 + 行尾操作按钮。悬停 / 选中底色画在这层，
   操作按钮的底色用 `background: inherit` 跟过来，不会露出一块白底。 */
.tree-item {
  position: relative;
  display: flex;
  align-items: center;
}

.tree-item:hover,
.tree-item:focus-within {
  background: var(--surface-2);
}

.tree-item.is-selected {
  background: var(--accent-soft);
}

.tree-row {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 3px 10px 3px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.tree-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tree-row.is-selected {
  color: var(--accent);
}

.tree-row[data-dirty='1'] .tree-name::after {
  content: ' •';
  color: var(--warn);
}

/* 行尾操作图标：默认藏起来，鼠标移入（或键盘聚焦到这一行）才出现。
   右侧由 JS 按按钮数量预留宽度（`--actions-w`），文件名不会钻到图标底下，
   所以按钮组本身不需要铺一层底色。 */

.tree-item[data-actions='1'] > .tree-row {
  padding-right: var(--actions-w, 72px);
}

.tree-actions {
  position: absolute;
  top: 50%;
  right: 4px;
  display: flex;
  align-items: center;
  gap: 1px;
  transform: translateY(-50%);
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.tree-item:hover > .tree-actions,
.tree-item:focus-within > .tree-actions {
  opacity: 1;
  pointer-events: auto;
}

.tree-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #8b93a1;
  cursor: pointer;
}

.tree-action svg {
  display: block;
  width: 13px;
  height: 13px;
}

/* 全局 `button:hover` 会给按钮铺白底：这里带 `:not(:disabled)` 提高优先级盖掉，
   只保留图标自己的浅灰 / 红色反馈。 */
.tree-action:hover:not(:disabled) {
  background: rgba(16, 19, 24, 0.08);
  color: var(--text);
}

.tree-action[data-tone='danger']:hover:not(:disabled) {
  background: rgba(192, 54, 44, 0.12);
  color: var(--err);
}

.tree-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* 内联新建：文件夹里插一行输入框，回车确认 / Esc 取消 */

.tree-new {
  background: var(--accent-soft);
}

.tree-new[data-busy='1'] {
  opacity: 0.6;
}

.tree-new-input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 1px 8px 1px 6px;
  padding: 1px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  outline: none;
}

.tree-new[data-invalid='1'] .tree-new-input {
  border-color: var(--err);
  background: #fff7f6;
}

/* 文件 / 文件夹图标：内联 SVG，尺寸与颜色统一在这里管 */

.tree-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: #a3aab6;
  transition: color 0.12s ease;
}

.tree-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tree-row[data-kind='dir'] > .tree-icon {
  color: #c09a46;
}

.tree-row.is-selected .tree-icon {
  color: var(--accent);
}

.tree-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 源码 */

.editor-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.editor-host {
  position: absolute;
  inset: 0;
  min-width: 0;
  min-height: 0;
}

.editor-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-size: 12.5px;
}

.editor-empty strong {
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
}

.editor-empty span {
  max-width: 40ch;
  color: var(--faint);
  line-height: 1.7;
}

.editor-status {
  flex: none;
  max-height: 72px;
  overflow: auto;
  padding: 5px 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.editor-status[data-tone='warn'] {
  background: #fffdf5;
  color: var(--warn);
}

.editor-status[data-tone='error'] {
  background: #fff7f6;
  color: var(--err);
}

/* Monaco 加载失败时的纯文本兜底 */
.editor-plain {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  outline: 0;
  resize: none;
  background: #fff;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  tab-size: 2;
}

.editor-plain:read-only {
  background: var(--surface);
  color: var(--muted);
}

.splitter {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line);
  background: var(--surface);
  cursor: row-resize;
  touch-action: none;
  user-select: none;
  transition: background-color 0.15s ease;
}

.splitter::before {
  content: '';
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: #d7dbe2;
  transition:
    background-color 0.15s ease,
    width 0.15s ease,
    height 0.15s ease;
}

.splitter:hover,
.splitter[data-drag='1'] {
  background: var(--surface-2);
}

.splitter:hover::before,
.splitter[data-drag='1']::before {
  width: 58px;
  background: #b3bac5;
}

/* 三栏之间的竖向分隔条：只有光标与把手方向不同 */
.splitter.splitter-v {
  border-top: 0;
  border-left: 1px solid var(--line);
  cursor: col-resize;
}

.splitter.splitter-v::before {
  width: 4px;
  height: 44px;
}

.splitter.splitter-v:hover::before,
.splitter.splitter-v[data-drag='1']::before {
  width: 4px;
  height: 58px;
}

.splitter:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

body.is-dragging {
  cursor: row-resize;
  user-select: none;
}

body.is-dragging iframe {
  pointer-events: none;
}

body.is-dragging-x {
  cursor: col-resize;
  user-select: none;
}

body.is-dragging-x iframe {
  pointer-events: none;
}

.console {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #fff;
}

.console-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.console-title {
  display: flex;
  flex: none;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.console-title strong {
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.console-title .muted {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.console-head .status {
  flex: none;
  max-width: 260px;
  padding: 2px 9px;
  font-size: 11.5px;
  overflow: hidden;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 12%, transparent);
}

.console[data-tone='busy'] .live-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 14%, transparent);
  animation: pulse 1.2s ease-in-out infinite;
}

.console[data-tone='error'] .live-dot {
  background: var(--err);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 14%, transparent);
}

.console[data-tone='idle'] .live-dot {
  background: var(--faint);
  box-shadow: none;
}

.console-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 7px;
}

.console-actions button {
  padding: 5px 10px;
  font-size: 12px;
}

.console .logs {
  background: #fcfcfd;
}

/* ------------------------------------------------------------
   响应式
   ------------------------------------------------------------ */

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 1fr) 40vh;
  }

  .layout > .stage {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

}

@media (max-width: 720px) {
  .bar {
    flex-wrap: wrap;
    padding: 10px 14px;
  }

  .actions {
    margin-left: auto;
  }

  .tag {
    display: none;
  }

  .home {
    padding: 0 14px 56px;
  }

  .hero {
    padding-top: 28px;
  }

  .toolbar {
    margin-top: 20px;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .selection {
    flex-wrap: wrap;
    gap: 6px 10px;
  }

  .console-head {
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 7px 12px;
  }

  .console-title {
    order: 1;
  }

  .console-head .status {
    order: 2;
    max-width: none;
    margin-left: auto;
  }

  .console-actions {
    order: 3;
  }

  .console-actions button {
    padding: 4px 8px;
  }

  .feature-chips {
    order: 4;
    flex: 1 0 100%;
  }

  .console-title .muted {
    display: none;
  }
}

@media (max-width: 480px) {
  .preview-btn {
    padding: 0 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------
   动画
   ------------------------------------------------------------ */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------
   确认弹窗（antd 风格）：删除文件 / 文件夹时用
   ------------------------------------------------------------ */

.confirm-dialog {
  width: min(416px, calc(100vw - 32px));
  max-width: none;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  box-shadow:
    0 12px 32px -12px rgba(16, 19, 24, 0.28),
    0 4px 12px rgba(16, 19, 24, 0.08);
}

.confirm-dialog[open] {
  animation: confirm-in 0.14s ease-out;
}

/* 打开后焦点落在弹窗本身（不预选按钮）：整卡不需要焦点框 */
.confirm-dialog:focus,
.confirm-dialog:focus-visible {
  outline: none;
}

.confirm-dialog::backdrop {
  background: rgba(16, 19, 24, 0.45);
}

.confirm-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 22px 24px 6px;
}

.confirm-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  color: var(--err);
}

.confirm-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.confirm-copy {
  min-width: 0;
}

.confirm-title {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
}

.confirm-text {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.confirm-text code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}

.confirm-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 18px 24px 20px;
}

.confirm-button {
  min-width: 64px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  line-height: 1;
}

/* 全局 `button:hover` 会铺一层白底：这里带 `:not(:disabled)` 提高优先级覆盖掉 */
.confirm-button:hover:not(:disabled) {
  border-color: #b8bfca;
  background: var(--surface);
  color: var(--text);
}

.confirm-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.confirm-button-danger,
.confirm-button-danger:hover:not(:disabled) {
  border-color: var(--err);
  background: var(--err);
  color: #fff;
}

.confirm-button-danger:hover:not(:disabled) {
  border-color: #a72d25;
  background: #a72d25;
}

.confirm-button-danger:focus-visible {
  outline-color: color-mix(in srgb, var(--err) 55%, #fff);
}

@keyframes confirm-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}
