/* ========= HTML 在线运行工具页 ========= */
* { box-sizing: border-box; }

.tool-body {
  margin: 0; min-height: 100vh;
  background: #f4f6fa;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  color: #2b3a52;
}

.tool-body [hidden] { display: none !important; }
svg { display: inline-block; vertical-align: middle; }

/* ---- 进入工具加载层 ---- */
.tool-loading {
  position: fixed; inset: 0; z-index: 999;
  background: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  transition: opacity .35s ease;
}
.tool-loading.hide { opacity: 0; pointer-events: none; }
.tool-spinner {
  width: 42px; height: 42px;
  border: 4px solid #e3ecf8;
  border-top-color: #6FA8FF;
  border-radius: 50%;
  animation: hr-spin .8s linear infinite;
}
@keyframes hr-spin { to { transform: rotate(360deg); } }
.tool-loading-text { font-size: 14px; color: #98a1b3; letter-spacing: 1px; }

/* ---- 顶栏 ---- */
.tool-topbar {
  height: 56px; padding: 0 32px;
  background: #fff;
  border-bottom: 1px solid #e8edf5;
  display: flex; align-items: center; justify-content: space-between;
}
.tool-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; color: #5c6b84; text-decoration: none;
  transition: color .15s;
}
.tool-back:hover { color: #1e3a5f; }
.tool-back svg { width: 16px; height: 16px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-brand {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: #1e3a5f;
  background: #f0f4fa;
  padding: 4px 14px; border-radius: 20px;
  border: 1px solid #e2e9f2;
}
.topbar-brand svg { width: 13px; height: 13px; }
.tool-no { font-size: 13px; color: #98a1b3; }
.tool-no b { color: #1e3a5f; font-family: Consolas, monospace; }

/* ---- 主容器 ---- */
.tool-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px 40px;
}

/* ---- 头部 ---- */
.tool-head { text-align: center; margin-bottom: 20px; }
.tool-head h1 {
  margin: 0 0 8px;
  font-size: 26px; font-weight: 700; color: #1e3a5f;
  display: inline-flex; align-items: center; gap: 10px;
}
.tool-head h1 svg { width: 26px; height: 26px; color: #1e3a5f; }
.tool-head p { margin: 0; font-size: 14px; color: #6b7890; }

/* ---- 运行工具栏 ---- */
.run-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px; flex-wrap: wrap;
}
.run-bar-left { display: flex; gap: 10px; }
.run-bar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #98a1b3; flex-wrap: wrap; justify-content: flex-end; }

/* 实时预览开关 */
.live-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  cursor: pointer; user-select: none;
  margin-right: 4px;
}
.live-toggle input { display: none; }
.live-track {
  width: 38px; height: 21px;
  border-radius: 20px;
  background: #d5deeb;
  position: relative;
  transition: background .2s;
}
.live-thumb {
  position: absolute; top: 2.5px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s;
}
.live-toggle input:checked + .live-track { background: #1e3a5f; }
.live-toggle input:checked + .live-track .live-thumb { transform: translateX(16px); }
.live-text { font-size: 13px; color: #5c6b84; }
.run-status { font-family: Consolas, monospace; }
.run-status.ok { color: #2f9e5e; }

.btn-run {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 26px;
  border: none; border-radius: 9px;
  background: #1e3a5f; color: #fff;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(30, 58, 95, .25);
  transition: background .2s, transform .15s, box-shadow .2s;
}
.btn-run svg { width: 15px; height: 15px; }
.btn-run:hover { background: #2a4f7a; transform: translateY(-1px); box-shadow: 0 6px 20px rgba(30, 58, 95, .32); }
.btn-run:active { transform: scale(.97); }

.btn-ghost2 {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 18px;
  border-radius: 9px;
  background: #fff; color: #5c6b84;
  border: 1.5px solid #d5deeb;
  font-size: 14px; font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.btn-ghost2 svg { width: 15px; height: 15px; }
.btn-ghost2:hover { color: #1e3a5f; border-color: #1e3a5f; background: #f8fafc; }

/* ---- 双栏编辑/预览 ---- */
.playground {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  height: 560px;
}
.pane {
  background: #fff;
  border: 1px solid #e8edf5;
  border-radius: 14px;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 2px 8px rgba(30, 58, 95, .05);
}
.pane-head {
  flex-shrink: 0;
  height: 42px;
  display: flex; align-items: center; gap: 7px;
  padding: 0 14px;
  background: #f8fafc;
  border-bottom: 1px solid #eef2f7;
}
.pane-dot { width: 11px; height: 11px; border-radius: 50%; }
.pane-dot.red { background: #ff5f57; }
.pane-dot.yellow { background: #febc2e; }
.pane-dot.green { background: #28c840; }
.pane-dot.blue { background: #6FA8FF; }
.pane-title { margin-left: 6px; font-size: 13px; font-weight: 600; color: #5c6b84; }
.pane-sandbox {
  margin-left: auto;
  font-size: 11px; color: #8aa3bc;
  background: #eef4fc;
  padding: 2px 10px; border-radius: 12px;
  border: 1px solid #dde9f7;
}

#codeInput {
  flex: 1;
  width: 100%;
  border: none; outline: none; resize: none;
  padding: 16px 18px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.7;
  color: #2b3a52;
  background: #fff;
  tab-size: 2;
}
#codeInput::placeholder { color: #b6bfd0; line-height: 1.7; }

.preview-box { flex: 1; position: relative; background: #fff; }
#previewFrame {
  width: 100%; height: 100%;
  border: none;
  background: #fff;
}
.preview-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  color: #c0c9d8;
  background: #fff;
  pointer-events: none;
}
.preview-empty svg { width: 52px; height: 52px; }
.preview-empty p { margin: 0; font-size: 14px; }

/* ---- 底部提示 ---- */
.run-tip {
  margin-top: 14px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12.5px; color: #98a1b3;
}
.run-tip svg { width: 14px; height: 14px; }

/* ---- API 接入条 ---- */
.api-bar {
  margin-top: 18px;
  padding: 12px 20px;
  background: #f0f4fa;
  border: 1px solid #e2e9f2;
  border-left: 4px solid #1e3a5f;
  border-radius: 10px;
  display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between;
  gap: 8px 16px;
}
.api-text {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 13px; color: #6b7890;
}
.api-text svg { width: 16px; height: 16px; color: #1e3a5f; flex-shrink: 0; }
.api-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: #1e3a5f; font-weight: 500;
  background: #fff;
  padding: 5px 18px; border-radius: 20px;
  border: 1px solid #d5deeb;
  white-space: nowrap;
  transition: all .15s;
}
.api-link:hover { border-color: #1e3a5f; background: #f8fafc; }
.api-link svg { width: 13px; height: 13px; }

/* ---- 响应式:窄屏上下排列 ---- */
@media (max-width: 860px) {
  .tool-topbar { padding: 0 16px; }
  .tool-wrap { padding: 20px 16px 32px; }
  .playground { grid-template-columns: 1fr; height: auto; }
  .pane { height: 380px; }
  .topbar-brand { display: none; }
}
