:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --ink: #18201d;
  --ink-muted: #69736e;
  --line: #dce2de;
  --line-strong: #c6cfca;
  --accent: #147655;
  --accent-hover: #0e6044;
  --accent-soft: #e7f3ed;
  --amber: #9a5b12;
  --amber-soft: #fff4df;
  --danger: #b43a35;
  --danger-soft: #fff0ef;
  --code-bg: #171c1a;
  --code-ink: #dce9e2;
  --focus: #2d8f6d;
  --shadow: 0 18px 50px rgba(27, 38, 33, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
textarea {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.topbar {
  height: 68px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.topbar__inner {
  display: flex;
  width: min(1440px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: 0 28px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  align-items: center;
  gap: 11px;
}

.brand__mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  color: #ffffff;
  border-radius: 8px;
  background: var(--accent);
  place-items: center;
}

.brand__mark svg {
  width: 22px;
  height: 22px;
}

.brand > span:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.brand strong {
  font-size: 15px;
  font-weight: 720;
  line-height: 1.25;
}

.brand small {
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.2;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.privacy-status,
.kernel-badge {
  display: inline-flex;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-muted);
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
  align-items: center;
}

.privacy-status__dot {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #21a36f;
  box-shadow: 0 0 0 3px #e3f5ed;
}

.kernel-badge {
  color: #685226;
  border-color: #eadfca;
  background: #fffaf0;
}

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 30px 28px 22px;
}

.workspace {
  display: grid;
  min-height: calc(100vh - 150px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  grid-template-columns: minmax(370px, 0.84fr) minmax(0, 1.16fr);
}

.config-pane,
.preview-pane {
  min-width: 0;
}

.config-pane {
  padding: 28px;
  border-right: 1px solid var(--line);
}

.preview-pane {
  display: flex;
  padding: 28px;
  background: var(--surface-soft);
  flex-direction: column;
}

.pane-heading,
.preview-toolbar,
.preview-title-row,
.field__label-row,
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-heading,
.preview-toolbar {
  min-height: 48px;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 720;
  line-height: 1.25;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

.button {
  display: inline-flex;
  height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    transform 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:focus-visible,
.mode-tab:focus-visible,
input:focus-visible,
textarea:focus-visible,
#yamlPreview:focus-visible {
  outline: 3px solid rgba(45, 143, 109, 0.2);
  outline-offset: 2px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button--small {
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.button--icon {
  width: 38px;
  height: 38px;
  padding: 0;
}

.button--quiet {
  color: var(--ink-muted);
  border-color: transparent;
  background: transparent;
}

.button--quiet:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-soft);
}

.button--secondary {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--surface);
}

.button--secondary:hover:not(:disabled) {
  border-color: #aab7b0;
  background: #fafcfb;
}

.button--primary {
  color: #ffffff;
  background: var(--accent);
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button__icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.mode-tabs {
  display: grid;
  height: 42px;
  margin: 24px 0 22px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eef1ee;
  grid-template-columns: 1fr 1fr;
}

.mode-tab {
  min-width: 0;
  padding: 0 10px;
  border-radius: 5px;
  color: var(--ink-muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-tab.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(25, 35, 30, 0.09);
}

.chain-strip {
  display: flex;
  min-height: 48px;
  margin-bottom: 22px;
  padding: 9px 12px;
  border: 1px solid #dce9e2;
  border-radius: 7px;
  background: #f0f7f3;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.chain-strip > svg {
  width: 17px;
  height: 17px;
  color: #6e8177;
  flex: 0 0 17px;
}

.chain-strip__item {
  display: inline-flex;
  min-width: 0;
  color: #315045;
  font-size: 13px;
  font-weight: 650;
  align-items: center;
  gap: 7px;
}

.chain-strip__index {
  display: inline-grid;
  width: 23px;
  height: 23px;
  color: #ffffff;
  border-radius: 50%;
  background: var(--accent);
  font-size: 11px;
  place-items: center;
  flex: 0 0 23px;
}

.field + .field {
  margin-top: 20px;
}

.field__label-row {
  min-height: 24px;
  margin-bottom: 7px;
  gap: 14px;
}

label {
  color: #2d3833;
  font-size: 13px;
  font-weight: 680;
}

.field__status,
.output-state {
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
}

.field__status[data-state="valid"],
.output-state[data-state="ready"] {
  color: var(--accent);
}

.field__status[data-state="invalid"] {
  color: var(--danger);
}

.output-state[data-state="stale"] {
  color: var(--amber);
}

input,
textarea {
  display: block;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: #ffffff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 112px;
  padding: 10px 12px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #9aa39f;
}

input:hover,
textarea:hover {
  border-color: #aebbb4;
}

input:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(45, 143, 109, 0.1);
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 58, 53, 0.08);
}

.form-error {
  display: flex;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid #efc7c4;
  border-radius: 6px;
  color: #8d2b27;
  background: var(--danger-soft);
  font-size: 13px;
  align-items: flex-start;
  gap: 8px;
}

.form-error svg {
  width: 17px;
  height: 17px;
  margin-top: 1px;
  flex: 0 0 17px;
}

.button--generate {
  width: 100%;
  margin-top: 24px;
}

.preview-toolbar {
  margin-bottom: 18px;
}

.preview-title-row {
  justify-content: flex-start;
  gap: 10px;
}

.output-state {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.output-state[data-state="ready"] {
  border-color: #c9e4d7;
  background: var(--accent-soft);
}

.output-state[data-state="stale"] {
  border-color: #efdbb9;
  background: var(--amber-soft);
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.subscription-output {
  margin: 0 0 14px;
  padding: 13px 14px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  transition: opacity 150ms ease;
}

.subscription-output.is-stale {
  opacity: 0.58;
}

.subscription-output__heading,
.subscription-output__title,
.subscription-output__actions {
  display: flex;
  align-items: center;
}

.subscription-output__heading {
  min-height: 24px;
  margin-bottom: 9px;
  justify-content: space-between;
  gap: 14px;
}

.subscription-output__title {
  min-width: 0;
  color: #2d3833;
  font-size: 13px;
  gap: 7px;
}

.subscription-output__title svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex: 0 0 16px;
}

.subscription-host {
  max-width: 48%;
  overflow: hidden;
  color: var(--ink-muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subscription-output__row {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.subscription-output__row input {
  height: 38px;
  min-width: 0;
  color: #315046;
  border-color: #c7d9d0;
  background: #f5faf7;
  font-size: 11.5px;
}

.subscription-output__actions {
  gap: 6px;
}

.subscription-output__warning {
  margin: 8px 0 0;
  color: #8a5c22;
  font-size: 11px;
  line-height: 1.4;
}

.preview-surface {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid #29322e;
  border-radius: 7px;
  background: var(--code-bg);
  flex: 1;
}

.empty-preview {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 32px;
  color: #aab7b0;
  text-align: center;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.empty-preview p {
  margin: 24px 0 4px;
  color: #dce5e0;
  font-size: 15px;
  font-weight: 650;
}

.empty-preview > span {
  color: #7f8d86;
  font-size: 12px;
}

.route-visual {
  display: grid;
  width: min(410px, 100%);
  grid-template-columns: 44px minmax(22px, 1fr) 44px minmax(22px, 1fr) 44px minmax(22px, 1fr) 44px;
  align-items: center;
}

.route-visual__node {
  display: inline-grid;
  width: 44px;
  height: 44px;
  border: 1px solid #53615a;
  border-radius: 50%;
  color: #d7e2dc;
  background: #222a26;
  font-size: 13px;
  font-weight: 750;
  place-items: center;
}

.route-visual__node--exit {
  color: #ffffff;
  border-color: #2b9b73;
  background: #176647;
}

.route-visual__node--device svg,
.route-visual__node--target svg {
  width: 19px;
  height: 19px;
}

.route-visual__line {
  position: relative;
  display: block;
  height: 1px;
  background: #46534d;
}

.route-visual__line::after {
  position: absolute;
  top: -3px;
  right: -1px;
  width: 6px;
  height: 6px;
  border-top: 1px solid #66756d;
  border-right: 1px solid #66756d;
  content: "";
  transform: rotate(45deg);
}

.route-visual__line i {
  position: absolute;
  top: -2px;
  left: 35%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #39b583;
}

#yamlPreview {
  width: 100%;
  height: 100%;
  min-height: 520px;
  margin: 0;
  padding: 22px 24px 30px;
  overflow: auto;
  color: var(--code-ink);
  background: var(--code-bg);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.65;
  tab-size: 2;
  white-space: pre;
}

#yamlPreview.is-stale {
  opacity: 0.62;
}

.footer {
  width: min(1440px, 100%);
  min-height: 48px;
  margin: 0 auto;
  padding: 0 28px 10px;
  color: var(--ink-muted);
  font-size: 12px;
}

.footer__privacy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.footer__privacy svg {
  width: 14px;
  height: 14px;
}

.toast {
  max-height: 0;
  margin: 0;
  padding: 0 12px;
  overflow: hidden;
  border: 0 solid #bcdacb;
  border-radius: 6px;
  color: #176647;
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transition:
    max-height 160ms ease,
    margin 160ms ease,
    padding 160ms ease,
    border-width 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  max-height: 46px;
  margin: -6px 0 12px;
  padding: 8px 12px;
  border-width: 1px;
  opacity: 1;
}

@media (max-width: 900px) {
  .page-shell {
    padding: 20px;
  }

  .workspace {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .config-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-surface,
  #yamlPreview {
    min-height: 460px;
  }
}

@media (max-width: 620px) {
  .topbar {
    height: 62px;
  }

  .topbar__inner {
    padding: 0 16px;
  }

  .brand__mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand small,
  .privacy-status,
  .kernel-badge {
    display: none;
  }

  .page-shell {
    padding: 12px;
  }

  .config-pane,
  .preview-pane {
    padding: 20px 16px;
  }

  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-actions {
    width: 100%;
  }

  .preview-actions .button {
    flex: 1;
  }

  .subscription-output__row {
    grid-template-columns: 1fr;
  }

  .subscription-output__actions {
    width: 100%;
  }

  .subscription-output__actions .button--primary {
    flex: 1;
  }

  .chain-strip {
    gap: 7px;
  }

  .chain-strip__item {
    font-size: 12px;
  }

  .chain-strip__index {
    width: 21px;
    height: 21px;
    flex-basis: 21px;
  }

  .preview-surface,
  #yamlPreview {
    min-height: 410px;
  }

  #yamlPreview {
    padding: 18px;
    font-size: 12px;
  }

  .route-visual {
    grid-template-columns: 38px minmax(14px, 1fr) 38px minmax(14px, 1fr) 38px minmax(14px, 1fr) 38px;
  }

  .route-visual__node {
    width: 38px;
    height: 38px;
  }

  .footer {
    min-height: 46px;
    padding: 0 16px 8px;
  }
}

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