:root {
  color-scheme: light;
  --ink: #172536;
  --ink-soft: #526275;
  --line: #cfd9e2;
  --line-strong: #91a3b4;
  --paper: #ffffff;
  --ice: #eef4f7;
  --blue: #2758c7;
  --blue-deep: #183b8f;
  --cyan: #087d90;
  --amber: #c77a23;
  --code: #101b28;
  --code-soft: #172638;
  --success: #1d8366;
  --danger: #c24f4a;
  --display: "Avenir Next Condensed", "DIN Alternate", "Arial Narrow", sans-serif;
  --body: "Avenir Next", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", ui-monospace, monospace;
  font-family: var(--body);
  color: var(--ink);
  background: var(--ice);
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgb(92 119 142 / 6%) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(rgb(92 119 142 / 6%) 1px, transparent 1px) 0 0 / 36px 36px,
    var(--ice);
}

button,
select,
textarea { font: inherit; }

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

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(39 88 199 / 35%);
  outline-offset: 2px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding: 13px clamp(20px, 4vw, 72px);
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 88%);
  backdrop-filter: blur(16px);
}

.identity {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.identity > span:last-child { display: grid; gap: 1px; }
.identity strong { font-size: 17px; letter-spacing: -0.01em; }
.identity small {
  color: var(--ink-soft);
  font: 600 11px/1.2 var(--mono);
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.graph-mark {
  position: relative;
  display: block;
  width: 43px;
  height: 34px;
}

.graph-mark i {
  position: absolute;
  z-index: 1;
  width: 9px;
  height: 9px;
  border: 2px solid var(--paper);
  border-radius: 2px;
  background: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}

.graph-mark i:nth-child(1) { top: 12px; left: 0; }
.graph-mark i:nth-child(2) { top: 2px; right: 0; background: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }
.graph-mark i:nth-child(3) { right: 0; bottom: 2px; background: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.graph-mark b {
  position: absolute;
  left: 8px;
  width: 29px;
  height: 12px;
  border-top: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
}
.graph-mark b:nth-of-type(1) { top: 7px; }
.graph-mark b:nth-of-type(2) { top: 18px; transform: scaleY(-1); }

.masthead nav { display: flex; align-items: center; gap: 6px; }
.masthead nav a {
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
.masthead nav a:hover { color: var(--ink); background: #edf2f6; }
.masthead nav .github-link {
  margin-left: 4px;
  color: var(--paper);
  background: var(--ink);
}
.masthead nav .github-link:hover { color: var(--paper); background: #26384d; }

.language-switch {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #edf2f6;
}
.language-switch button {
  min-width: 42px;
  min-height: 34px;
  padding: 5px 9px;
  border: 0;
  border-radius: 6px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.language-switch button[aria-pressed="true"] {
  color: var(--paper);
  background: var(--blue-deep);
  box-shadow: 0 2px 7px rgb(24 59 143 / 22%);
}

main { padding: 0 clamp(16px, 3vw, 54px) 36px; }

.intro {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(280px, 520px);
  align-items: end;
  gap: 48px;
  max-width: 1840px;
  margin: 0 auto;
  padding: clamp(38px, 5vw, 74px) 0 32px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font: 700 12px/1.3 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.intro h1 {
  max-width: 760px;
  margin: 0;
  color: var(--ink);
  font: 700 clamp(46px, 5vw, 80px)/0.92 var(--display);
  letter-spacing: -0.045em;
}

.intro-copy {
  max-width: 500px;
  margin: 0 0 4px;
  padding-left: 22px;
  border-left: 3px solid var(--cyan);
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.65;
}

html[lang="zh-CN"] .intro h1 {
  font-family: "PingFang SC", "Microsoft YaHei", var(--body);
  font-weight: 750;
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.workbench {
  position: relative;
  display: grid;
  grid-template-columns: 260px minmax(560px, 1fr) minmax(380px, 460px);
  max-width: 1840px;
  min-height: 780px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 22px 54px rgb(27 50 72 / 14%);
}

.controls {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: #f7fafb;
}

.rail-heading { display: flex; align-items: flex-start; gap: 10px; }
.rail-index {
  flex: 0 0 auto;
  color: var(--cyan);
  font: 700 11px/1.5 var(--mono);
  letter-spacing: 0.08em;
}
.rail-heading p,
.protocol-panel header p {
  margin: 0 0 2px;
  color: var(--ink-soft);
  font: 700 10px/1.3 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.rail-heading h2,
.protocol-panel h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.015em;
}
.section-heading { margin-top: 31px; }

.field-label {
  display: block;
  margin: 18px 0 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.sample-note {
  min-height: 52px;
  margin: 9px 1px 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.45;
}

.direction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.direction-grid button,
.theme-list button,
.canvas-actions button,
.protocol-panel button {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--paper);
  cursor: pointer;
}

.direction-grid button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px;
  font-size: 12px;
  font-weight: 700;
}
.direction-grid button em { font-style: normal; }
.direction-grid button span { margin-right: 5px; color: var(--blue); font-size: 17px; }
.direction-grid button:hover,
.theme-list button:hover,
.canvas-actions button:hover { border-color: var(--line-strong); color: var(--ink); }
.direction-grid button[aria-pressed="true"] {
  border-color: var(--blue);
  color: var(--paper);
  background: var(--blue);
}
.direction-grid button[aria-pressed="true"] span { color: inherit; }

.theme-list { display: grid; gap: 8px; margin-top: 14px; }
.theme-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}
.theme-list button::after {
  width: 9px;
  height: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  content: "";
}
.theme-list button[data-theme="classic"]::after { background: #2d7a62; }
.theme-list button[data-theme="ink"]::after { background: #1e3a5f; }
.theme-list button[data-theme="midnight"]::after { background: #c4893a; }
.theme-list button[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); }
.theme-list button[aria-pressed="true"]::after { box-shadow: 0 0 0 3px rgb(39 88 199 / 15%); }

.canvas-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 31px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.canvas-actions button { min-height: 40px; padding: 8px; font-size: 11px; font-weight: 700; }
.canvas-actions button:last-child { grid-column: 1 / -1; }

.canvas-stage {
  position: relative;
  display: grid;
  grid-template-rows: 38px 48px minmax(560px, 1fr) 78px;
  min-width: 0;
  background: var(--paper);
}

.level-ruler {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--line-strong);
  background: #f9fbfc;
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.08em;
}
.level-ruler span { margin-right: 4px; color: var(--ink-soft); }
.level-ruler i { flex: 1; height: 1px; background: var(--line); }
.level-ruler b { color: var(--blue); font-weight: 700; }

.canvas-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font: 650 11px/1.3 var(--mono);
}
.canvas-status > div { display: flex; align-items: center; gap: 7px; }
.canvas-status strong { color: var(--ink); font-weight: 700; }
.status-light {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgb(199 122 35 / 13%);
}
.status-light.valid { background: var(--success); box-shadow: 0 0 0 3px rgb(29 131 102 / 13%); }
.status-light.invalid { background: var(--danger); box-shadow: 0 0 0 3px rgb(194 79 74 / 13%); }

.canvas-host { position: relative; min-height: 560px; overflow: hidden; }
#dag { width: 100%; height: 100%; }

.canvas-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #f9fbfc;
}
.canvas-footer > div { min-width: 0; }
.canvas-footer span {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font: 700 10px/1.2 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.canvas-footer strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font: 600 12px/1.3 var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnostics { display: flex; flex: 0 0 auto; gap: 16px; margin: 0; }
.diagnostics div { text-align: right; }
.diagnostics dt { color: var(--ink-soft); font: 650 9px/1.2 var(--mono); text-transform: uppercase; }
.diagnostics dd { margin: 3px 0 0; color: var(--blue); font: 700 14px/1 var(--mono); }

.protocol-panel {
  display: grid;
  grid-template-rows: auto minmax(390px, 1fr) auto auto auto;
  min-width: 0;
  padding: 24px;
  color: #dce9f2;
  background: var(--code);
}
.protocol-panel header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 15px; }
.protocol-panel header p { color: #8295a9; }
.protocol-panel header .rail-index { margin-right: 5px; color: #69d3df; }
.protocol-panel h2 { color: #f3f8fb; }
.protocol-panel header button,
.editor-actions button {
  min-height: 38px;
  padding: 7px 11px;
  border-color: #304258;
  color: #b7c7d5;
  background: var(--code-soft);
  font-size: 11px;
  font-weight: 700;
}
.protocol-panel button:hover { border-color: #58728d; color: #fff; }

.editor-wrap { position: relative; min-height: 390px; }
textarea {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 390px;
  resize: none;
  border: 1px solid #2c4055;
  border-radius: 8px;
  padding: 14px 14px 38px;
  color: #d7e4ee;
  caret-color: #6fd5df;
  background: #0b1520;
  font: 500 12px/1.58 var(--mono);
  tab-size: 2;
}
textarea::selection { color: #fff; background: #2758c7; }
.editor-hint {
  position: absolute;
  right: 10px;
  bottom: 9px;
  padding: 3px 6px;
  border-radius: 4px;
  color: #71869a;
  background: rgb(16 27 40 / 88%);
  font: 600 9px/1.2 var(--mono);
}

.validation-result {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid #304258;
  border-radius: 6px;
  color: #9fb1c1;
  background: var(--code-soft);
  font: 600 11px/1.45 var(--mono);
}
.validation-result.valid { border-color: rgb(58 166 132 / 50%); color: #88d1bb; }
.validation-result.invalid { border-color: rgb(210 91 84 / 55%); color: #f0aaa5; }

.issue-list {
  display: none;
  max-height: 116px;
  margin: 8px 0 0;
  padding: 0 0 0 20px;
  overflow: auto;
  color: #e6aaa6;
  font: 500 10px/1.5 var(--mono);
}
.issue-list.visible { display: block; }
.issue-list li + li { margin-top: 5px; }

.editor-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 8px; margin-top: 12px; }
.editor-actions .primary-action { border-color: var(--blue); color: #fff; background: var(--blue); }
.editor-actions .primary-action:hover { border-color: #4f7ee5; background: #3264d5; }

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  max-width: 1840px;
  margin: 0 auto;
  padding: 20px clamp(20px, 4vw, 64px) 30px;
  color: var(--ink-soft);
  font: 600 10px/1.4 var(--mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

@media (max-width: 1380px) {
  .workbench { grid-template-columns: 250px minmax(500px, 1fr); }
  .protocol-panel { grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr) 260px; grid-template-rows: auto minmax(360px, 54vh) auto auto; gap: 0 18px; }
  .protocol-panel header { grid-column: 1 / -1; }
  .editor-wrap { grid-row: 2 / 5; min-height: 360px; }
  .validation-result { align-self: start; margin-top: 0; }
  .issue-list { grid-column: 2; }
  .editor-actions { grid-column: 2; align-self: end; }
}

@media (max-width: 840px) {
  .masthead { min-height: 72px; padding: 10px 16px; }
  .masthead nav .project-link:not(.github-link) { display: none; }
  .intro { grid-template-columns: 1fr; gap: 20px; padding: 34px 0 22px; }
  .intro h1 { font-size: clamp(42px, 13vw, 62px); }
  .intro-copy { padding-left: 14px; }
  .workbench { display: flex; flex-direction: column; border-radius: 11px; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .direction-grid { grid-template-columns: repeat(2, 1fr); }
  .theme-list { grid-template-columns: repeat(3, 1fr); }
  .canvas-actions { grid-template-columns: repeat(3, 1fr); }
  .canvas-actions button:last-child { grid-column: auto; }
  .canvas-stage { grid-template-rows: 38px 48px 560px auto; }
  .canvas-footer { align-items: flex-start; flex-direction: column; }
  .diagnostics { width: 100%; justify-content: space-between; }
  .diagnostics div { text-align: left; }
  .protocol-panel { display: grid; grid-template-columns: 1fr; grid-template-rows: auto 460px auto auto auto; padding: 16px; }
  .protocol-panel header,
  .editor-wrap,
  .validation-result,
  .issue-list,
  .editor-actions { grid-column: 1; grid-row: auto; }
  .editor-wrap { min-height: 460px; }
  .page-footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .identity { gap: 9px; }
  .identity strong { font-size: 14px; }
  .identity small { font-size: 9px; }
  .graph-mark { width: 36px; transform: scale(0.88); transform-origin: left center; }
  .masthead nav { gap: 0; }
  .masthead nav .project-link { display: none; }
  .language-switch { margin-right: 0; }
  main { padding-right: 10px; padding-left: 10px; }
  .intro-copy { font-size: 15px; }
  .controls { padding: 24px 18px; }
  .theme-list,
  .canvas-actions { grid-template-columns: 1fr; }
  .canvas-actions button:last-child { grid-column: auto; }
  .canvas-status { align-items: flex-start; flex-direction: column; justify-content: center; gap: 3px; }
  .canvas-stage { grid-template-rows: 38px 58px 520px auto; }
  .canvas-host { min-height: 520px; }
  .protocol-panel { padding: 18px 14px; }
  .editor-actions { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  main { padding-inline: 10px; }
  .identity strong { font-size: 13px; }
  .identity small { font-size: 8px; }
  .github-link { padding-inline: 9px !important; }
  .direction-grid { grid-template-columns: 1fr 1fr; }
  .theme-list { grid-template-columns: 1fr; }
  .canvas-stage { grid-template-rows: 34px 52px 470px auto; }
  .canvas-status { align-items: flex-start; flex-direction: column; justify-content: center; gap: 2px; }
  .canvas-host { min-height: 470px; }
}

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