:root {
  --color-primary: #176b87;
  --color-primary-hover: #12566d;
  --color-on-primary: #ffffff;
  --color-accent: #16836d;
  --color-background: #eef4f7;
  --color-surface: #ffffff;
  --color-surface-soft: #f7fafb;
  --color-foreground: #17354a;
  --color-text: #2e4a5d;
  --color-muted: #6f8492;
  --color-border: #d7e2e8;
  --color-border-strong: #bfd0d9;
  --color-error: #b63d4b;
  --color-success: #18735e;
  --color-ring: #2487a6;
  --shadow-sm: 0 1px 2px rgba(26, 54, 72, 0.05);
  --shadow-md: 0 10px 30px rgba(26, 54, 72, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --z-sticky: 20;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--color-background); scroll-behavior: smooth; }
body { margin: 0; background: var(--color-background); color: var(--color-foreground); font-family: "Fira Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button, select, input[type="color"] { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--color-ring) 28%, transparent); outline-offset: 2px; }

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }
.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; transform: translateY(-150%); padding: 10px 14px; color: #fff; background: var(--color-primary); border-radius: var(--radius-sm); text-decoration: none; }
.skip-link:focus { transform: translateY(0); }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.icon { display: block; flex: 0 0 auto; }

.topbar { min-height: 64px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px; padding: 0 28px; background: var(--color-surface); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: var(--z-sticky); }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-symbol { width: 38px; height: 38px; display: grid; place-items: center; color: #fff; background: var(--color-primary); border-radius: 11px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; letter-spacing: -0.02em; }
.brand span { margin-top: 1px; color: var(--color-muted); font-size: 11px; }
.topbar-center { display: flex; align-items: center; gap: 10px; color: var(--color-muted); font-size: 12px; }
.document-name { max-width: 220px; color: var(--color-text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { display: inline-flex; align-items: center; gap: 6px; }
.save-state i { width: 7px; height: 7px; background: var(--color-success); border-radius: 50%; box-shadow: 0 0 0 3px #dcefe9; }
.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.local-badge { min-height: 38px; display: inline-flex; align-items: center; gap: 7px; padding: 0 11px; color: #4d6878; background: #f4f8fa; border: 1px solid var(--color-border); border-radius: 999px; font-size: 12px; font-weight: 650; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border-radius: 9px; border: 1px solid transparent; font-size: 13px; font-weight: 720; transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease; }
.button-primary { color: var(--color-on-primary); background: var(--color-primary); box-shadow: 0 5px 14px rgba(23,107,135,.18); }
.button-primary:hover { background: var(--color-primary-hover); }
.button-secondary { color: var(--color-primary); background: #f3f9fb; border-color: #bcd6e1; }
.button-secondary:hover { background: #e8f4f8; border-color: #8ebaca; }
.button-quiet { min-height: 36px; padding: 0 9px; color: var(--color-primary); background: transparent; }
.button-quiet:hover { background: #edf6f8; }

.context-bar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 12px 28px; background: linear-gradient(100deg, #f9fbfc 0%, #f2f8fa 58%, #f7faf8 100%); border-bottom: 1px solid var(--color-border); }
.context-bar > div:first-child { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
.context-kicker { grid-row: 1 / span 2; padding-right: 12px; border-right: 1px solid var(--color-border); color: var(--color-primary); font-family: "Fira Code", ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; font-weight: 700; letter-spacing: .11em; }
.context-bar strong { font-size: 15px; }
.context-bar small { color: var(--color-muted); font-size: 11px; }
.context-stats { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.context-stats > span { min-height: 34px; display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; color: #5f7684; background: rgba(255,255,255,.8); border: 1px solid var(--color-border); border-radius: 999px; font-size: 11px; }
.context-stats b { color: var(--color-foreground); font-variant-numeric: tabular-nums; }
.context-stats .status-ok { color: var(--color-success); border-color: #badbd1; background: #f1faf7; font-weight: 700; }
.context-stats .status-error { color: var(--color-error); border-color: #e8c2c7; background: #fff5f6; font-weight: 700; }

.workspace { width: 100%; max-width: 1920px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(390px, 460px) minmax(0, 1fr); gap: 16px; flex: 1; }
.editor-panel, .preview-panel { min-width: 0; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.editor-panel { align-self: start; position: sticky; top: 80px; max-height: calc(100dvh - 96px); display: flex; flex-direction: column; }
.editor-tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 7px; gap: 5px; background: #f3f7f9; border-bottom: 1px solid var(--color-border); }
.editor-tabs button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: #607786; background: transparent; border: 0; border-radius: 9px; font-size: 13px; font-weight: 700; transition: 180ms ease; }
.editor-tabs button:hover { color: var(--color-primary); background: rgba(255,255,255,.58); }
.editor-tabs button.active { color: var(--color-primary); background: #fff; box-shadow: 0 1px 5px rgba(29,56,72,.1); }
.editor-scroll { overflow-y: auto; overscroll-behavior: contain; }
.editor-section { padding: 20px; border-bottom: 1px solid #e6edf1; }
.editor-section:last-child { border-bottom: 0; }
.section-heading { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading > div { display: flex; align-items: center; gap: 9px; }
.section-heading > div > span { min-width: 24px; color: #8aa0ad; font-family: "Fira Code", ui-monospace, monospace; font-size: 10px; font-weight: 600; }
.section-heading h2 { margin: 0; color: var(--color-foreground); font-size: 16px; letter-spacing: -0.015em; }
.section-copy { margin: -4px 0 14px; color: var(--color-muted); font-size: 12px; line-height: 1.55; }
.count-badge { padding: 4px 8px; color: #657d8b; background: #eef4f6; border-radius: 999px; font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums; }

.field-grid { display: grid; gap: 10px; }
.protein-grid { grid-template-columns: 1.2fr .8fr; }
.field, .field-grid label, .domain-row label { display: flex; flex-direction: column; gap: 6px; }
.field { margin-top: 12px; }
.field > span, .field-grid label > span, .domain-row label > span { color: #4c6574; font-size: 11px; font-weight: 700; }
.field > span em { float: right; margin-left: 10px; color: #8da0ab; font-style: normal; font-weight: 500; }
input:not([type="color"]), textarea, select { width: 100%; color: #203e51; background: #fbfdfe; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease; }
input:not([type="color"]), select { min-height: 42px; padding: 0 11px; }
textarea { padding: 11px 12px; resize: vertical; line-height: 1.58; }
input:not([type="color"]):hover, textarea:hover, select:hover { border-color: #9cb7c4; }
input:not([type="color"]):focus, textarea:focus, select:focus { outline: none; border-color: var(--color-ring); box-shadow: 0 0 0 3px rgba(36,135,166,.12); background: #fff; }
.variant-field textarea { min-height: 260px; font-family: "Fira Code", ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; tab-size: 2; }
.helper { margin: 8px 0 0; color: var(--color-muted); font-size: 11px; line-height: 1.55; }
.import-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.import-row small { color: var(--color-muted); font-size: 11px; }
.inline-alert { margin-top: 12px; display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; color: var(--color-error); background: #fff5f6; border: 1px solid #edc8cd; border-radius: 9px; }
.inline-alert strong, .inline-alert span { display: block; }
.inline-alert strong { font-size: 12px; }
.inline-alert span { margin-top: 2px; color: #80646a; font-size: 11px; }

.color-list, .shape-list, .domain-list { display: flex; flex-direction: column; gap: 8px; }
.color-row, .shape-row, .large-color-control { min-height: 58px; display: flex; align-items: center; gap: 11px; padding: 9px 10px; background: var(--color-surface-soft); border: 1px solid #e1e9ed; border-radius: 10px; transition: border-color 160ms ease, background-color 160ms ease; }
.color-row:hover, .shape-row:hover, .large-color-control:hover { background: #fff; border-color: #b9ccd5; }
input[type="color"] { width: 36px; height: 36px; flex: 0 0 auto; padding: 3px; background: #fff; border: 1px solid #c8d7df; border-radius: 9px; }
.color-name, .large-color-control > span, .shape-row > span:nth-child(2) { min-width: 0; flex: 1; }
.color-name b, .color-name small, .large-color-control b, .large-color-control small, .shape-row b, .shape-row small { display: block; }
.color-name b, .large-color-control b, .shape-row b { color: #334f60; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.color-name small, .large-color-control small, .shape-row small { color: var(--color-muted); font-size: 10px; }
.color-row code, .large-color-control code { color: #6b818e; font-family: "Fira Code", ui-monospace, monospace; font-size: 10px; }
.shape-preview { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; color: var(--color-primary); background: #edf5f8; border-radius: 9px; }
.shape-row select { width: 112px; min-height: 36px; font-size: 11px; }
.large-color-control { margin-top: 4px; }

.icon-button { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; color: var(--color-primary); background: #f1f7f9; border: 1px solid #d1e1e7; border-radius: 9px; transition: 160ms ease; }
.icon-button:hover { color: #fff; background: var(--color-primary); border-color: var(--color-primary); }
.icon-button-danger { color: #9d5360; background: #fff7f8; border-color: #ecd4d8; }
.icon-button-danger:hover { background: var(--color-error); border-color: var(--color-error); }
.domain-row { display: grid; grid-template-columns: 36px minmax(110px, 1fr) 68px 68px 40px; gap: 7px; align-items: end; padding: 9px; background: var(--color-surface-soft); border: 1px solid #e1e9ed; border-radius: 10px; }
.domain-row input:not([type="color"]) { min-height: 38px; padding: 0 8px; font-size: 11px; }
.domain-row .domain-color { align-self: end; width: 36px; height: 38px; }
.domain-range-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 8px 4px 2px; border-top: 1px solid #e1e9ed; }
.domain-range-controls label { gap: 2px; }
.domain-range-controls label > span { color: #6f8492; font-size: 10px; font-weight: 650; }
.domain-range-controls input[type="range"] { width: 100%; min-height: 28px; accent-color: var(--color-primary); cursor: ew-resize; }

.preview-panel { min-height: 720px; display: flex; flex-direction: column; }
.preview-toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 12px; border-bottom: 1px solid var(--color-border); }
.result-tabs { display: flex; align-items: center; gap: 3px; }
.result-tabs button { min-height: 40px; padding: 0 12px; color: #657c8a; background: transparent; border: 0; border-radius: 8px; font-size: 12px; font-weight: 700; transition: 160ms ease; }
.result-tabs button:hover { color: var(--color-primary); background: #f1f7f9; }
.result-tabs button.active { color: var(--color-primary); background: #eaf4f7; }
.result-tabs button span { margin-left: 5px; padding: 2px 6px; color: #607785; background: #fff; border-radius: 999px; font-size: 9px; }
.export-menu { display: flex; align-items: center; gap: 4px; }
.export-menu > span { margin-right: 4px; color: var(--color-muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.export-menu button { min-width: 42px; min-height: 36px; padding: 0 8px; color: #546e7d; background: #fff; border: 1px solid var(--color-border); border-radius: 7px; font-size: 10px; font-weight: 750; transition: 160ms ease; }
.export-menu button:hover { color: var(--color-primary); border-color: #91b8c7; background: #f4fafc; }
.download-notice { min-width: 110px; color: var(--color-success); font-size: 10px; font-weight: 700; text-align: right; }

.canvas-area { min-height: 700px; flex: 1; padding: 18px; background-color: #edf2f4; background-image: linear-gradient(rgba(94,121,136,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(94,121,136,.08) 1px, transparent 1px); background-size: 24px 24px; overflow: auto; }
.canvas-label { min-width: 900px; display: flex; align-items: center; justify-content: space-between; margin: 0 auto 8px; color: #778c98; font-size: 10px; }
.canvas-label span { font-family: "Fira Code", ui-monospace, monospace; font-weight: 700; letter-spacing: .1em; }
.svg-paper { min-width: 900px; max-width: 1500px; margin: auto; background: #fff; border: 1px solid #d7e1e6; box-shadow: var(--shadow-md); }
.svg-paper svg { width: 100%; height: auto; display: block; }

.table-wrap { flex: 1; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; padding: 12px 14px; color: #607786; background: #f3f7f9; border-bottom: 1px solid var(--color-border); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 12px 14px; color: #516a79; border-bottom: 1px solid #e9eff2; vertical-align: middle; }
tbody tr:hover { background: #f8fbfc; }
td strong { color: #29495c; }
td.numeric { font-variant-numeric: tabular-nums; }
td code { color: #365b70; font-family: "Fira Code", ui-monospace, monospace; font-size: 10px; }
.type-pill { display: inline-flex; align-items: center; gap: 5px; text-transform: capitalize; }
.phenotype-dot { width: 8px; height: 8px; display: inline-block; margin-right: 7px; border-radius: 50%; box-shadow: 0 0 0 2px #fff, 0 0 0 3px #dbe4e8; }

.qc-view { padding: 28px; background: #f7fafb; flex: 1; }
.qc-hero { display: flex; align-items: center; gap: 15px; padding: 20px; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.qc-icon { width: 48px; height: 48px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; background: var(--color-success); border-radius: 50%; box-shadow: 0 0 0 6px #e3f2ed; }
.qc-icon.warn { background: var(--color-error); box-shadow: 0 0 0 6px #fae7e9; }
.qc-hero h2 { margin: 0; font-size: 18px; }
.qc-hero p { margin: 4px 0 0; color: var(--color-muted); font-size: 12px; }
.qc-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.qc-cards > div { padding: 15px; background: #fff; border: 1px solid var(--color-border); border-radius: 10px; }
.qc-cards span, .qc-cards strong, .qc-cards small { display: block; }
.qc-cards span { color: var(--color-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.qc-cards strong { margin: 4px 0; color: var(--color-foreground); font-size: 20px; font-variant-numeric: tabular-nums; }
.qc-cards small { color: #8497a2; font-size: 10px; }
.error-list { margin-top: 12px; padding: 16px; color: #72575c; background: #fff; border: 1px solid #ebcdd1; border-radius: 10px; }
.error-list h3 { margin: 0 0 10px; color: var(--color-error); font-size: 13px; }
.error-list > div { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 11px; }
.signature { margin-top: 12px; padding: 13px 15px; color: #607886; background: #fff; border: 1px solid var(--color-border); border-radius: 10px; font-size: 11px; }
.signature summary { cursor: pointer; font-weight: 700; }
.signature code { display: block; margin-top: 10px; color: #365b70; font-family: "Fira Code", ui-monospace, monospace; font-size: 9px; line-height: 1.6; overflow-wrap: anywhere; }

footer { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 28px; color: #788d99; border-top: 1px solid var(--color-border); font-size: 10px; }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-center { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .editor-panel { position: static; max-height: none; }
  .editor-scroll { overflow: visible; }
  .preview-panel { min-height: 640px; }
}

@media (max-width: 760px) {
  body { font-size: 16px; }
  .topbar { min-height: 60px; padding: 8px 14px; gap: 10px; }
  .brand span, .local-badge { display: none; }
  .button-primary { min-width: 44px; padding: 0 11px; }
  .button-primary .icon { margin: 0; }
  .context-bar { align-items: flex-start; flex-direction: column; padding: 13px 14px; gap: 10px; }
  .context-bar > div:first-child { grid-template-columns: 1fr; }
  .context-kicker { grid-row: auto; padding: 0; border: 0; }
  .context-stats { gap: 5px; }
  .workspace { padding: 8px; gap: 8px; }
  .editor-panel, .preview-panel { border-radius: 12px; }
  .editor-section { padding: 16px; }
  .protein-grid { grid-template-columns: 1fr; }
  .domain-row { grid-template-columns: 36px minmax(120px, 1fr) 40px; }
  .domain-row label:nth-of-type(2), .domain-row label:nth-of-type(3) { grid-row: 2; }
  .domain-row label:nth-of-type(2) { grid-column: 2; }
  .domain-row label:nth-of-type(3) { grid-column: 3; }
  .domain-row .icon-button { grid-column: 3; grid-row: 1; }
  .preview-toolbar { align-items: stretch; flex-direction: column; }
  .result-tabs, .export-menu { overflow-x: auto; }
  .export-menu > span { display: none; }
  .download-notice { min-height: 16px; text-align: left; }
  .qc-view { padding: 14px; }
  .qc-cards { grid-template-columns: 1fr 1fr; }
  footer { align-items: flex-start; flex-direction: column; padding: 12px 14px; }
}

@media (max-width: 430px) {
  .brand strong { font-size: 14px; }
  .button-primary { font-size: 0; }
  .context-stats > span { padding: 0 8px; }
  .shape-row { flex-wrap: wrap; }
  .shape-row select { width: 100%; }
  .domain-range-controls { grid-template-columns: 1fr; }
  .qc-cards { grid-template-columns: 1fr; }
}

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