:root {
  --ink: #10213d;
  --muted: #68768d;
  --line: #dce3ed;
  --soft-line: #edf1f6;
  --blue: #2f68e8;
  --blue-soft: #edf3ff;
  --orange: #ee4d2d;
  --red: #eb5b4f;
  --teal: #109c92;
  --purple: #7868d8;
  --surface: #ffffff;
  --page: #f5f7fa;
  --shadow: 0 16px 44px rgba(20, 36, 62, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  min-height: 92px;
  padding: 18px clamp(22px, 4vw, 64px);
  border-bottom: 1px solid rgba(220, 227, 237, .9);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(14px);
}

.header-copy { display: flex; align-items: center; gap: 16px; }

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 12px;
  color: #fff;
  background: var(--orange);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.02em;
}

h1, h2, h3, p { margin-top: 0; }

h1 { margin-bottom: 5px; font-size: clamp(23px, 2.2vw, 34px); line-height: 1.15; letter-spacing: -.035em; }
.header-copy p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

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

.control-button {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #33445e;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.control-button:hover { border-color: #aebbd0; background: #f8faff; }
.control-button:focus-visible { outline: 3px solid rgba(47, 104, 232, .22); outline-offset: 2px; }
.zoom-value { min-width: 48px; color: var(--muted); font-size: 12px; text-align: center; }

main { width: min(1880px, calc(100% - 40px)); margin: 28px auto 50px; }

.overview,
.diagram-section,
.definition-section,
.notes-section {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.overview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 22px 26px;
  border-radius: 14px 14px 0 0;
}

.overview h2,
.section-heading h2,
.definition-copy h2,
.notes-section > h2 { margin-bottom: 6px; font-size: 18px; letter-spacing: -.02em; }

.overview p,
.section-heading p,
.definition-copy p { max-width: 820px; margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

.legend { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; color: #43536b; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.legend-line { position: relative; width: 34px; height: 0; border-top: 2px solid; }
.legend-line::after { position: absolute; right: -1px; top: -5px; width: 0; height: 0; content: ""; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 7px solid currentColor; }
.legend-line.main { color: var(--blue); }
.legend-line.failure { color: var(--red); border-top-style: dashed; }
.legend-line.feedback { color: var(--teal); border-top-style: dashed; }
.legend-note { width: 16px; height: 16px; border: 2px solid var(--purple); border-radius: 4px; background: #f3f0ff; }

.diagram-section { border-top: 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 22px 26px 16px; border-bottom: 1px solid var(--soft-line); }
.scroll-hint { white-space: nowrap; }

.diagram-viewport {
  width: 100%;
  min-height: 620px;
  overflow: auto;
  padding: 18px 16px 28px;
  background-image: radial-gradient(#dbe2ed 1px, transparent 1px);
  background-size: 18px 18px;
  outline: none;
}

#sequenceDiagram { display: block; max-width: none; transition: width .2s ease, height .2s ease; }

.sequence-sticky-shell {
  position: sticky;
  top: 92px;
  z-index: 14;
  width: 100%;
  overflow: hidden;
  border-bottom: 1px solid #d9e1ec;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 9px 22px rgba(20, 36, 62, .1);
  backdrop-filter: blur(12px);
}

.sequence-sticky-viewport { position: relative; width: 100%; height: 100%; overflow: hidden; }
.sequence-sticky-track { position: absolute; top: 0; left: 16px; will-change: transform; }
.sequence-sticky-content { position: relative; transform-origin: left top; }

.sticky-phase {
  position: absolute;
  top: 8px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
}

.phase-opportunity { background: #fff0e6; border-color: #ffd7bf; }
.phase-creative { background: #eaf3ff; border-color: #cfe2fb; }
.phase-production { background: #f0edff; border-color: #dcd6ff; }
.phase-publish { background: #fff7d9; border-color: #f5e8a9; }
.phase-feedback { background: #e3f7f4; border-color: #c4ebe6; }

.sticky-participant {
  position: absolute;
  top: 50px;
  height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #071c3d;
  border-radius: 10px;
  color: #fff;
  background: #0d2a57;
}

.sticky-participant strong { font-size: 15px; }
.sticky-participant span { color: #c9d7ec; font-size: 9.5px; }
.lifeline { stroke: #b8c2d1; stroke-width: 1.2; stroke-dasharray: 5 6; }

.message-line { stroke-width: 2; fill: none; }
.event-main .message-line { stroke: var(--blue); }
.event-failure .message-line { stroke: var(--red); stroke-dasharray: 7 5; }
.event-feedback .message-line { stroke: var(--teal); stroke-dasharray: 8 5; }
.event-decision .message-line { stroke: var(--purple); }
.event-title { font-size: 13px; font-weight: 760; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.event-detail { fill: var(--muted); font-size: 10.5px; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
.event-main .event-title { fill: #2056cf; }
.event-failure .event-title { fill: #d8493e; }
.event-feedback .event-title { fill: #087f77; }
.event-decision .event-title { fill: #6655c5; }
.self-line { stroke-linejoin: round; }

.definition-section { display: grid; grid-template-columns: 1fr; gap: 20px; padding: 28px 30px; border-top: 0; }

.state-chain { display: flex; align-items: center; width: 100%; min-width: 0; overflow-x: auto; padding: 6px 2px 14px; scrollbar-width: thin; scrollbar-color: #bac6d8 transparent; }
.state-item { min-width: 170px; min-height: 46px; display: flex; flex: 0 0 auto; align-items: center; gap: 9px; padding: 10px 13px; border: 1px solid #cfd9e8; border-radius: 9px; background: #f9fbfe; white-space: nowrap; }
.state-item span { width: 22px; height: 22px; display: grid; place-items: center; flex: none; border-radius: 50%; color: #fff; background: var(--blue); font-size: 11px; font-weight: 760; }
.state-item strong { font-size: 11px; }
.chain-arrow { width: 32px; min-width: 32px; height: 12px; overflow: visible; }
.chain-arrow path { fill: none; stroke: #8b99ad; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.notes-section { padding: 28px 30px 32px; border-top: 0; border-radius: 0 0 14px 14px; }
.notes-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin-top: 18px; }
.notes-grid article { padding-left: 16px; border-left: 3px solid #d5dfed; }
.notes-grid h3 { margin-bottom: 7px; font-size: 13px; }
.notes-grid p { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }

footer { display: flex; justify-content: space-between; gap: 20px; width: min(1880px, calc(100% - 40px)); margin: 0 auto 34px; color: #7c899c; font-size: 11px; }

@media (max-width: 920px) {
  .page-header { position: static; align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; overflow-x: auto; padding-bottom: 3px; }
  main { width: min(100% - 24px, 1880px); margin-top: 14px; }
  .overview { align-items: flex-start; flex-direction: column; gap: 18px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .sequence-sticky-shell { top: 0; }
  .definition-section { grid-template-columns: 1fr; gap: 18px; }
  .notes-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  footer { width: calc(100% - 24px); }
}

@media (max-width: 560px) {
  .page-header { padding: 16px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 10px; }
  .header-copy { align-items: flex-start; }
  .header-copy p { font-size: 12px; line-height: 1.5; }
  .overview, .section-heading, .definition-section, .notes-section { padding-left: 18px; padding-right: 18px; }
  .legend { gap: 12px 18px; }
  .notes-grid { grid-template-columns: 1fr; }
  .scroll-hint { white-space: normal; }
  footer { flex-direction: column; gap: 6px; }
}

@media print {
  body { background: #fff; }
  .page-header { position: static; }
  .header-actions, .scroll-hint { display: none; }
  main { width: 100%; margin: 12px 0; }
  .overview, .diagram-section, .definition-section, .notes-section { box-shadow: none; }
  .diagram-viewport { overflow: visible; }
}

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