:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --paper: #f9fafb;
  --surface: #fff;
  --teal: #14b8a6;
  --teal-dark: #0d9488;
  --action: #0f766e;
  --action-hover: #115e59;
  --teal-soft: #f0fdfa;
  --danger: #b42318;
  --warning: #854d0e;
  --subtle: #f3f4f6;
  --focus: #0f766e;
  --control-radius: 8px;
  --panel-radius: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f3f4f6;
  --muted: #cbd5e1;
  --line: #334155;
  --paper: #020617;
  --surface: #1e293b;
  --teal-dark: #5eead4;
  --teal-soft: #134e4a;
  --danger: #fda29b;
  --warning: #fde68a;
  --subtle: #111827;
  --focus: #5eead4;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, select, a { font: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.skip-link { position: fixed; z-index: 10; top: 8px; left: 8px; padding: 8px 12px; transform: translateY(-160%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.skip-link:focus-visible { transform: translateY(0); }
.skip-link:not(:focus-visible) { clip-path: inset(50%); pointer-events: none; }

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: rgba(249, 250, 251, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.topbar-inner {
  width: 100%;
  max-width: 1152px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
:root[data-theme="dark"] .topbar { background: rgba(2, 6, 23, 0.9); }
.brand, .top-actions, .platform-badge, .top-link, .top-primary, .action-row, .security, .command-header {
  display: flex;
  align-items: center;
}
.brand { gap: 11px; }
.brand img { width: 32px; height: 32px; }
.brand span { color: var(--muted); font-weight: 500; }
.top-actions { gap: 9px; }
.platform-badge { gap: 7px; margin-right: 3px; color: var(--muted); font-size: 14px; }
.platform-badge svg { width: 17px; }
.top-link, .top-primary {
  min-height: 40px;
  justify-content: center;
  gap: 7px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  font-size: 14px;
  font-weight: 500;
}
.top-link { background: var(--surface); }
.top-link:hover { border-color: var(--focus); background: var(--subtle); }
.top-primary { border-color: var(--action); background: var(--action); color: #fff; box-shadow: 0 4px 6px -1px rgba(15, 118, 110, 0.25); }
.top-primary:hover { border-color: var(--action-hover); background: var(--action-hover); }
.top-link svg, .top-primary svg { width: 16px; height: 16px; }

.layout {
  max-width: 1024px;
  margin: 0 auto;
  padding: 36px 24px 72px;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 32px;
}
.steps { padding: 10px 24px 0 0; border-right: 1px solid var(--line); }
.steps > p { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.steps ol { margin: 0; padding: 0; list-style: none; }
.steps li { position: relative; min-height: 66px; padding: 0 0 18px 39px; color: var(--muted); }
.steps li::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 6px;
  width: 9px;
  height: 9px;
  border: 2px solid #d1d5db;
  border-radius: 50%;
  background: var(--paper);
}
.steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 16px;
  top: 20px;
  bottom: -2px;
  width: 1px;
  background: var(--line);
}
.steps li.active { color: var(--ink); }
.steps li.active::before {
  border-color: var(--teal);
  background: var(--teal);
  box-shadow: 0 0 0 5px #d9f7f1;
}
.steps strong, .steps span { display: block; }
.steps strong { font-size: 14px; }
.steps span { margin-top: 4px; font-size: 12px; }

.panel {
  min-width: 0;
  padding: 28px 32px 32px;
}
.eyebrow { margin: 0 0 8px; color: var(--teal-dark); font-size: 13px; font-weight: 600; }
h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.3; }
.lede { max-width: 720px; margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.65; }

.platform-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  overflow: hidden;
}
.platform-switch button {
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.platform-switch button:last-child { border-right: 0; }
.platform-switch button:hover { background: var(--subtle); }
.platform-switch button[aria-pressed="true"] {
  background: var(--teal-soft);
  color: var(--teal-dark);
  box-shadow: inset 0 -2px 0 var(--teal);
}
.platform-switch svg { width: 18px; height: 18px; flex: 0 0 auto; }

.field-label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 500; }
.key-input-wrap { position: relative; border-radius: var(--control-radius); }
.key-input-wrap input {
  width: 100%;
  min-height: 44px;
  padding: 0 48px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--ink);
  outline: 0;
}
.key-input-wrap:focus-within { box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15); }
.key-input-wrap input:focus-visible { border-color: var(--teal); outline: 0; box-shadow: none; }
.key-input-wrap input[aria-invalid="true"] { border-color: var(--danger); }
.key-input-wrap input:disabled { background: var(--subtle); color: var(--muted); }
.key-input-wrap input::-ms-clear,
.key-input-wrap input::-ms-reveal { display: none; }
.key-input-wrap button {
  position: absolute;
  right: 2px;
  top: 2px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.key-input-wrap button:hover { color: var(--teal-dark); }
.key-input-wrap button:focus-visible { outline-offset: -4px; }
.key-input-wrap button:disabled { cursor: not-allowed; opacity: 0.5; }
.key-input-wrap button svg { width: 18px; }
.field-error { margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.field-help { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.field-help.success { color: #166534; }
.field-help.failed, .field-help.error { color: var(--danger); }
.model-label { margin-top: 18px; }
.model-input-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.model-input-wrap .key-input-wrap { min-width: 0; }
.model-select-wrap { position: relative; }
.model-native-select {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.model-select-trigger {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 44px 0 14px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.model-select-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-select-trigger[aria-expanded="true"] { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15); }
.model-select-trigger[aria-invalid="true"] { border-color: var(--danger); }
.model-select-trigger:disabled { cursor: not-allowed; background: var(--subtle); color: var(--muted); }
.model-select-trigger:focus-visible { outline: 0; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15); }
.select-chevron {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 17px;
  height: 17px;
  pointer-events: none;
  color: var(--muted);
  transform: translateY(-50%);
}
.model-select-trigger:disabled .select-chevron { opacity: 0.55; }
.model-options {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  max-height: min(260px, 45vh);
  margin: 0;
  padding: 6px;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}
.model-options[hidden] { display: none; }
.model-options [role="option"] {
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.35;
}
.model-options [role="option"]:hover,
.model-options [role="option"][aria-selected="true"] { background: var(--teal-soft); color: var(--teal-dark); }
.model-fetch { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; min-width: 144px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--control-radius); background: var(--surface); color: var(--teal-dark); cursor: pointer; }
.model-fetch svg { width: 18px; height: 18px; flex-shrink: 0; }
.model-fetch[aria-busy="true"] svg,
.primary[aria-busy="true"] svg { display: none; }
.model-fetch[aria-busy="true"]::before,
.primary[aria-busy="true"]::before {
  content: "";
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.model-fetch:disabled { cursor: not-allowed; opacity: 0.55; }
.model-fetch:not(:disabled):hover { border-color: var(--focus); background: var(--teal-soft); }
.config-safety { margin: 16px 0 18px; overflow: hidden; border: 1px solid #fde7b0; border-radius: 10px; background: var(--surface); }
.config-warning { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 12px 14px; color: var(--warning); background: #fffbeb; font-size: 13px; line-height: 1.55; }
.config-warning svg { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 auto; }
.config-warning span { min-width: 0; overflow-wrap: anywhere; }
.command-effects { border-top: 1px solid var(--line); }
.command-effects-title { margin: 0; padding: 13px 16px 0; color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1.6; }
.command-effects-body { padding: 7px 16px 15px; }
.command-effects-body p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; }
.command-effects-body p + p { margin-top: 5px; }
.command-effects-body code { white-space: nowrap; }

.action-row { justify-content: space-between; gap: 20px; }
.security { gap: 8px; margin: 0; color: var(--muted); font-size: 13px; }
.security svg { width: 18px; color: #18794e; }
.primary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--control-radius);
  background: var(--action);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(20, 184, 166, 0.25), 0 2px 4px -2px rgba(20, 184, 166, 0.25);
}
.primary:hover { background: var(--action-hover); }
.primary:disabled { cursor: not-allowed; opacity: 0.55; }
.primary svg { width: 18px; }

.command-panel { margin-top: 20px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.command-header { align-items: center; justify-content: space-between; gap: 16px; padding: 1px 1px 11px; border-bottom: 1px solid rgba(13, 148, 136, 0.16); }
.command-header > div { min-width: 0; }
.command-header strong, .command-header small { display: block; }
.command-header strong { font-size: 15px; }
.command-header small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.command-header button {
  min-height: 34px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.command-header button:disabled { cursor: not-allowed; color: var(--muted); opacity: 0.7; }
.command-header button:not(:disabled):hover { border-color: var(--focus); background: var(--subtle); }
.command-header button svg { width: 16px; }
.command-panel pre {
  max-height: 160px;
  margin: 12px 0 9px;
  padding: 12px 13px;
  overflow: auto;
  border-radius: 8px;
  background: #111827;
  color: #eaf5f2;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.command-panel pre:focus { outline: 3px solid rgba(20, 184, 166, 0.32); outline-offset: 2px; }
.command-panel pre code { padding: 0; background: transparent; color: inherit; line-height: 1.55; }
.command-panel > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.setup-status {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid #dce3ea;
  border-radius: var(--control-radius);
  background: var(--surface);
}
.setup-status.failed { border-color: #f0b4ae; background: #fff5f4; }
.status-icon {
  width: 34px;
  height: 34px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  background: #e7f8f4;
  color: var(--teal-dark);
}
.setup-status.failed .status-icon { background: #fee4e2; color: var(--danger); }
.status-icon svg { width: 18px; }
.setup-status:not(.failed) .status-icon [data-lucide="loader-circle"] { animation: spin 1s linear infinite; }
.setup-status p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

.completion { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.completion-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 14px; }
.completion-heading > span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #dcfce7;
  color: #15803d;
}
.completion-heading svg { width: 22px; }
.completion-heading p { margin: 0 0 2px; color: #15803d; font-size: 12px; font-weight: 800; }
.completion-heading h2 { margin: 0; font-size: 21px; }
code {
  padding: 2px 4px;
  background: #e8eef1;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}
.error { margin-top: 16px; padding: 12px 14px; border: 1px solid #f0b4ae; border-radius: var(--control-radius); background: #fff5f4; color: var(--danger); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.platform-switch button:focus-visible { outline-offset: -3px; }
button, a, input, select { touch-action: manipulation; -webkit-tap-highlight-color: rgba(20, 184, 166, 0.2); }

:root[data-theme="dark"] code { background: var(--surface); }
:root[data-theme="dark"] .command-panel pre code { background: transparent; }
:root[data-theme="dark"] .error, :root[data-theme="dark"] .setup-status.failed { background: #451a1a; border-color: #b42318; }
:root[data-theme="dark"] .config-warning { background: #422006; }
:root[data-theme="dark"] .config-safety { border-color: #713f12; }
:root[data-theme="dark"] .setup-status.failed .status-icon { background: #7a271a; }
:root[data-theme="dark"] .completion-heading p, :root[data-theme="dark"] .field-help.success { color: #86efac; }
:root[data-theme="dark"] .status-icon { background: var(--teal-soft); }
:root[data-theme="dark"] .security svg { color: #86efac; }
h1, h2 { text-wrap: balance; }
.topbar, .top-actions { flex-wrap: wrap; }
.topbar { padding-block: 12px; }
.top-actions { justify-content: flex-end; }
.primary { overflow-wrap: anywhere; }

html.embedded body { background: var(--surface); }
html.embedded .topbar, html.embedded .steps { display: none; }
html.embedded .layout { display: block; max-width: 980px; margin: 0; padding: 24px; }
html.embedded .panel { padding: 24px; border: 0; box-shadow: none; }

@media (max-width: 820px) {
  .topbar { min-height: 64px; padding: 12px 18px; }
  .brand span { display: none; }
  .layout { grid-template-columns: 1fr; gap: 18px; padding: 24px 18px 48px; }
  .steps { padding: 0; border: 0; overflow-x: auto; }
  .steps > p, .steps li span { display: none; }
  .steps ol { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .steps li { min-width: 0; min-height: 42px; padding: 0 2px 0 22px; }
  .steps li::before { left: 3px; top: 4px; }
  .steps li:not(:last-child)::after { display: none; }
  .steps strong { font-size: 12px; line-height: 1.25; overflow-wrap: anywhere; }
  .panel { padding: 26px 20px; }
  h1 { font-size: 27px; }
  .action-row { align-items: stretch; flex-direction: column-reverse; }
  .primary { width: 100%; }
  .panel .primary, .panel .model-fetch, .topbar .top-primary { min-height: 44px; }
  .security { justify-content: center; }
  html.embedded .layout { padding: 16px; }
  html.embedded .panel { padding: 12px; }
}

@media (max-width: 620px) {
  .platform-badge { display: none; }
  .platform-switch { grid-template-columns: 1fr; }
  .platform-switch button { border-right: 0; border-bottom: 1px solid #ccd5de; }
  .platform-switch button:last-child { border-bottom: 0; }
  .platform-switch button[aria-pressed="true"] { box-shadow: inset 3px 0 0 var(--teal); }
  .top-link, .top-primary { padding: 0 10px; }
  .command-header { align-items: flex-start; flex-wrap: wrap; }
}

@media (max-width: 430px) {
  .model-input-wrap { grid-template-columns: minmax(0, 1fr); }
  .topbar { gap: 10px; padding: 10px 12px; }
  .brand { gap: 8px; }
  .brand img { width: 29px; height: 29px; }
  .top-link, .top-primary { padding: 0 9px; font-size: 13px; }
  .top-link svg, .top-primary svg { display: none; }
  .panel { padding: 22px 16px; }
}

@media (max-width: 350px) {
  .topbar-inner { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}
