:root {
  --bg: #fafaf9;
  --bg-2: #f5f5f4;
  --fg: #1c1917;
  --muted: #78716c;
  --muted-2: #a8a29e;
  --card-bg: #ffffff;
  --border: #ececeb;
  --border-strong: #d6d3d1;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fed7aa;
  --accent-bg: #fff7ed;
  --accent-fg: #ffffff;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;
  --topbar-h: 64px;
  --bottombar-h: 64px;
  --shadow-primary: 0 1px 2px rgba(194, 65, 12, 0.18), 0 4px 12px rgba(194, 65, 12, 0.16), 0 0 0 1px rgba(194, 65, 12, 0.08);
  --shadow-card: 0 1px 2px rgba(28, 25, 23, 0.04);
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--bottombar-h);
  height: 100vh;
}

/* ---- topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px 0 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.topbar::after {
  content: '';
  position: absolute;
  inset: auto 0 -1px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0, var(--accent-soft) 18%, var(--accent-soft) 82%, transparent 100%);
  opacity: 0.5;
  pointer-events: none;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.back:hover { background: var(--bg-2); color: var(--fg); }
.back:hover .logo-mark { background: var(--accent-hover); }
.back-arrow {
  font-size: 16px;
  line-height: 1;
  width: 16px;
  text-align: center;
}
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  transition: background 0.12s;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
  min-width: 0;
}
.brand-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-num {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.4px;
  line-height: 1;
}
.brand strong {
  font-size: 14.5px;
  font-weight: 650;
  color: var(--fg);
  letter-spacing: -0.2px;
}
.brand-sub {
  font-size: 11.5px;
  color: var(--muted);
}

/* ---- steps indicator ---- */
.steps {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin: 0 auto;
  list-style: none;
}
.steps li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted-2);
  font-size: 12.5px;
  transition: color 0.18s;
}
.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--muted-2);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.18s;
}
.step-label {
  font-weight: 500;
  letter-spacing: 0.2px;
}
.step-sep {
  width: 16px;
  height: 1px;
  background: var(--border-strong);
  margin: 0 2px;
}
/* active / past steps driven by body[data-step] */
body[data-step="1"] .steps li[data-step="1"],
body[data-step="2"] .steps li[data-step="2"],
body[data-step="3"] .steps li[data-step="3"] {
  color: var(--accent);
}
body[data-step="1"] .steps li[data-step="1"] .step-dot,
body[data-step="2"] .steps li[data-step="2"] .step-dot,
body[data-step="3"] .steps li[data-step="3"] .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 4px var(--accent-bg);
}
body[data-step="2"] .steps li[data-step="1"],
body[data-step="3"] .steps li[data-step="1"],
body[data-step="3"] .steps li[data-step="2"] {
  color: var(--ok);
}
body[data-step="2"] .steps li[data-step="1"] .step-dot,
body[data-step="3"] .steps li[data-step="1"] .step-dot,
body[data-step="3"] .steps li[data-step="2"] .step-dot {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

/* ---- actions ---- */
.actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ---- url popover ---- */
.url-wrap {
  position: relative;
  display: inline-flex;
}
#btn-url[aria-expanded="true"] {
  background: var(--accent-bg);
  color: var(--accent);
}
.url-popover {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 380px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 8px 8px;
  padding: 12px 12px 11px;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(28, 25, 23, 0.14), 0 2px 6px rgba(28, 25, 23, 0.04);
  z-index: 50;
  animation: popover-in 0.14s ease-out;
}
.url-popover[hidden] { display: none; }
.url-popover::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 24px;
  width: 10px;
  height: 10px;
  background: var(--card-bg);
  border-left: 1px solid var(--border-strong);
  border-top: 1px solid var(--border-strong);
  transform: rotate(45deg);
}
.url-popover input[type="url"] {
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  background: var(--bg);
  color: var(--fg);
  min-width: 0;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.url-popover input[type="url"]:focus {
  border-color: var(--accent);
  background: var(--card-bg);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.url-popover .primary-sm {
  height: 32px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font-weight: 600;
  padding: 0 14px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.url-popover .primary-sm:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.url-popover .primary-sm:disabled {
  background: var(--bg-2);
  border-color: var(--border);
  color: var(--muted-2);
  cursor: not-allowed;
}
.url-popover .url-hint {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
}
.url-popover .url-hint code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--fg);
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- buttons ---- */
button, label.ghost {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  white-space: nowrap;
}
button:hover:not(:disabled), label.ghost:hover {
  background: var(--bg-2);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.ghost, label.ghost {
  color: var(--muted);
}
button.ghost:hover, label.ghost:hover {
  color: var(--fg);
}

button.primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
  padding: 0 18px 0 14px;
  height: 38px;
  box-shadow: var(--shadow-primary);
  letter-spacing: 0.1px;
  font-size: 13.5px;
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-0.5px);
}
button.primary:active:not(:disabled) {
  transform: translateY(0);
}
button.primary:disabled {
  background: var(--bg-2);
  border-color: var(--border);
  color: var(--muted-2);
  box-shadow: none;
}
.primary-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
button.primary:disabled .primary-num {
  background: var(--border);
  color: var(--muted-2);
}

/* ---- split main ---- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
  min-height: 0;
}
.pane {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  min-height: 0;
  position: relative;
}
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  height: 44px;
}
.pane-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.1px;
}
.pane-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
}
.editor-pane .pane-num {
  background: var(--accent-bg);
  border-color: var(--accent-soft);
  color: var(--accent);
}
.pane-options {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

/* segmented toggle (源码 / 渲染) */
.seg {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 0;
}
.seg-btn {
  height: 22px;
  padding: 0 10px;
  border-radius: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
  letter-spacing: 0.1px;
}
.seg-btn:hover:not(.is-active) {
  color: var(--fg);
  background: transparent;
}
.seg-btn.is-active {
  background: var(--card-bg);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08), 0 0 0 1px var(--border);
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.toggle:hover { color: var(--fg); }
.toggle input {
  margin: 0;
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
}
.toggle input:checked ~ span { color: var(--fg); font-weight: 500; }
.preview-pane .pane-num {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}
.small { font-size: 12px; }
.muted { color: var(--muted); }

#editor {
  flex: 1;
  width: 100%;
  border: 0;
  padding: 20px 24px;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg);
  resize: none;
  outline: none;
  background: var(--card-bg);
  tab-size: 2;
}
#editor::placeholder {
  color: var(--muted-2);
  white-space: pre-wrap;
}

#preview,
#raw-preview {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--bg);
}
#editor[hidden],
#raw-preview[hidden] { display: none; }

/* ---- bottom bar ---- */
.bottom-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}
.status {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  display: inline-block;
  box-shadow: 0 0 0 3px transparent;
  transition: background 0.18s, box-shadow 0.18s;
}
.status.ok { color: var(--ok); }
.status.ok::before { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.status.warn { color: var(--warn); }
.status.warn::before { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }

.warnings {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  background: var(--bg-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottombar-h) + 16px);
  transform: translateX(-50%);
  background: var(--fg);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 2px 4px rgba(0, 0, 0, 0.06);
  z-index: 100;
  animation: toast-in 0.18s ease-out;
  font-weight: 500;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- responsive ---- */
@media (max-width: 1100px) {
  .steps .step-label { display: none; }
  .steps { gap: 4px; }
  .step-sep { width: 12px; }
}
@media (max-width: 900px) {
  .brand-sub { display: none; }
  .steps { display: none; }
}
@media (max-width: 720px) {
  body { grid-template-rows: var(--topbar-h) 1fr 1fr var(--bottombar-h); }
  .split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .topbar { padding: 0 12px; gap: 10px; }
  .bottom-bar { padding: 0 12px; }
  .actions button, .actions label.ghost { padding: 0 8px; }
  .brand-num { display: none; }
  .url-popover { width: calc(100vw - 24px); right: -8px; }
  .url-popover::before { right: 16px; }
}
