:root {
  color-scheme: light;
  --page: #eef1ef;
  --surface: #ffffff;
  --surface-muted: #f6f8f7;
  --ink: #17201c;
  --muted: #5f6d65;
  --line: #d7ddd9;
  --line-strong: #b9c4be;
  --green: #166b50;
  --green-dark: #0d513b;
  --teal: #197b83;
  --amber: #a56516;
  --red: #a63e46;
  --viewer: #101714;
  --focus: #187cc2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--ink); }
body { min-width: 320px; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
button[aria-busy="true"] { min-width: min(var(--idle-width), 100%); cursor: progress; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-header { min-height: 64px; flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-block h1 { margin: 0; font-size: 20px; line-height: 1.1; font-weight: 720; }
.brand-block p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.brand-mark { width: 32px; height: 34px; position: relative; display: grid; align-content: center; gap: 4px; }
.brand-mark span { display: block; height: 4px; border-radius: 4px; transform-origin: center; }
.brand-mark span:nth-child(1) { width: 23px; background: var(--green); transform: translateX(1px) rotate(14deg); }
.brand-mark span:nth-child(2) { width: 30px; background: var(--teal); transform: rotate(-16deg); }
.brand-mark span:nth-child(3) { width: 21px; background: var(--amber); transform: translateX(8px) rotate(13deg); }
.header-status { min-width: 0; max-width: 60%; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 8px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.header-status > span:last-child { overflow-wrap: anywhere; }
.connection-status { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--amber); }
.status-dot.online { background: #238b63; }
.status-dot.offline { background: var(--red); }
.header-divider { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.workspace-note { padding: 10px 22px; border-bottom: 1px solid #e1c28e; background: #fff9ed; color: #734814; font-size: 12px; line-height: 1.5; }

.workspace { flex: 1; min-height: calc(100vh - 64px); display: grid; grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); }
.sequence-panel { min-width: 0; background: var(--surface); border-right: 1px solid var(--line); padding: 22px; overflow-y: auto; }
.panel-heading, .section-title-row, .tool-header, .structure-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-heading { margin-bottom: 17px; }
h2, h3, p { overflow-wrap: anywhere; }
.panel-heading h2, .tool-header h2, .structure-toolbar h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.panel-heading p, .tool-header p, .structure-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
label { display: block; color: #4d5a54; font-size: 12px; line-height: 1.4; font-weight: 650; min-width: 0; }
textarea, input { width: 100%; min-width: 0; margin-top: 7px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 400; }
textarea { resize: vertical; padding: 11px; line-height: 1.55; }
#sequence-input, .mono-sequence, #model-corpus { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
#sequence-input { height: 216px; min-height: 150px; text-transform: uppercase; }
input { height: 36px; padding: 0 9px; }
.button-row { display: flex; align-items: center; gap: 8px; }
.sequence-panel > .button-row { margin-top: 10px; }
.primary-button, .secondary-button, .quiet-button { min-height: 36px; border-radius: 5px; padding: 0 14px; font-weight: 670; border: 1px solid transparent; white-space: nowrap; }
.primary-button { background: var(--green); color: white; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.secondary-button:hover, .quiet-button:hover { background: var(--surface-muted); border-color: #8f9d96; }
.quiet-button { min-height: 31px; padding: 0 10px; background: transparent; color: var(--green); border-color: var(--line); }

.metrics-section { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 17px; }
.section-title-row h3 { margin: 0; font-size: 13px; }
.score-value { color: var(--green); font-size: 24px; line-height: 1; font-weight: 760; font-variant-numeric: tabular-nums; }
.score-summary { display: grid; gap: 5px; text-align: right; flex-shrink: 0; }
.score-label { font-size: 11px; color: var(--muted); }
.metric-list { margin: 15px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.metric-list div { display: flex; flex-direction: column; justify-content: space-between; background: var(--surface); padding: 9px 10px; min-width: 0; }
.metric-list dt { color: var(--muted); font-size: 12px; line-height: 1.4; }
.metric-list dd { margin: 3px 0 0; font-weight: 680; font-variant-numeric: tabular-nums; }
.flag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.flag { padding: 4px 7px; border: 1px solid #dfb8bb; border-radius: 4px; background: #fff7f7; color: #7e3036; font-size: 11px; }
.flag.ok { border-color: #b7d8c9; background: #f2faf6; color: var(--green-dark); }
.research-note { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.work-area { min-width: 0; overflow: hidden; background: var(--surface); }
.tab-bar { height: 49px; display: flex; align-items: stretch; gap: 3px; padding: 0 19px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab-button { border: 0; border-bottom: 2px solid transparent; padding: 0 13px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 670; }
.tab-button:hover { color: var(--ink); }
.tab-button.active { color: var(--green-dark); border-bottom-color: var(--green); }
.tab-view { min-height: calc(100vh - 113px); padding: 24px 28px 36px; overflow-y: auto; }
.tool-header, .structure-toolbar { margin-bottom: 20px; flex-wrap: wrap; }
.tool-header > div:first-child, .structure-toolbar > div:first-child { min-width: 0; flex: 1 1 300px; }
.tool-header > button, .tool-header > .button-row, .structure-toolbar > .button-row { flex: 0 0 auto; }
.tool-header .button-row, .structure-toolbar .button-row { flex-wrap: wrap; }
.message-bar { position: fixed; z-index: 20; right: 24px; bottom: 20px; width: max-content; max-width: min(560px, calc(100% - 32px)); margin: 0; padding: 12px 16px; border: 1px solid #a8cdbd; border-radius: 5px; background: #f0faf5; color: #154d3a; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.message-bar.error { border-color: #dfb8bb; background: #fff5f5; color: #7e3036; }
.message-bar.warning { border-color: #e1c28e; background: #fff9ed; color: #734814; }
.control-strip { display: grid; grid-template-columns: minmax(110px, 1.3fr) repeat(4, minmax(90px, 1fr)); gap: 10px; padding: 14px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.evolution-controls { grid-template-columns: repeat(5, minmax(90px, 1fr)) minmax(130px, 1.1fr); }
.toggle-label { height: 60px; display: flex; align-items: flex-end; gap: 8px; padding-bottom: 9px; }
.toggle-label input { width: 17px; height: 17px; margin: 0; accent-color: var(--green); }
.toggle-label span { line-height: 17px; white-space: nowrap; }
.empty-state { min-height: 280px; padding: 32px 16px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state.compact { min-height: 220px; }
.empty-state h3 { margin: 0; color: #4c5953; font-size: 14px; font-weight: 600; }
.empty-state p { margin: 8px 0 0; font-size: 13px; line-height: 1.5; }
.result-region { margin-top: 18px; }
.result-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-bottom: 12px; color: var(--ink); font-size: 13px; line-height: 1.5; }
.result-run-id { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.5; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-muted); color: #53605a; text-align: left; font-weight: 690; white-space: nowrap; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); }
.numeric-cell { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.result-region table { min-width: 720px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f6faf8; }
td.sequence-cell { max-width: 370px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.table-action { min-height: 28px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 4px; background: white; color: var(--green-dark); font-weight: 670; }
.result-score { font-weight: 750; color: var(--green-dark); }

.evolution-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(250px, 1fr); margin-top: 24px; border-top: 1px solid var(--line); }
.chart-panel, .evolution-best { min-width: 0; padding: 20px 18px; }
.chart-panel { padding-left: 0; }
.evolution-best { border-left: 1px solid var(--line); padding-right: 0; }
.chart-panel .section-title-row { flex-wrap: wrap; gap: 8px; }
#evolution-delta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend span::before { content: ""; width: 16px; height: 3px; background: var(--green); }
.chart-legend .legend-mean::before { background: #7a9ea1; }
#evolution-chart { width: 100%; height: 290px; display: block; margin-top: 12px; }
.mono-sequence { max-height: 215px; overflow: auto; margin: 17px 0; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: white; color: #35423c; line-height: 1.55; font-size: 12px; }

.tab-view.structure-view { padding: 0; overflow: hidden; }
.structure-toolbar { min-height: 76px; margin: 0; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.fold-disclosure { min-height: 38px; padding: 10px 24px; background: #fff8e9; border-bottom: 1px solid #e5cc9f; color: #704b1c; font-size: 12px; line-height: 1.5; }
.fold-disclosure code { font-size: 11px; }
.structure-stage { position: relative; height: calc(100vh - 227px); min-height: 470px; background: var(--viewer); overflow: hidden; }
#viewer3d { position: absolute; inset: 0; }
#viewer3d canvas { width: 100%; height: 100%; display: block; }
.viewer-fallback { position: absolute; inset: 0; display: grid; place-content: center; padding: 30px; color: #cfdbd5; text-align: center; }
.structure-stats { position: absolute; top: 16px; left: 16px; display: flex; margin: 0; padding: 9px 11px; border: 1px solid #35423d; border-radius: 5px; background: rgb(19 27 23 / 88%); color: white; backdrop-filter: blur(6px); }
.structure-stats div { min-width: 0; padding: 0 12px; border-right: 1px solid #3a4841; }
.structure-stats div:first-child { padding-left: 0; }
.structure-stats div:last-child { border: 0; padding-right: 0; }
.structure-stats dt { color: #9eb0a7; font-size: 10px; }
.structure-stats dd { margin: 3px 0 0; font-size: 14px; font-weight: 690; }

.model-controls { max-width: 900px; padding-top: 18px; border-top: 1px solid var(--line); }
#model-corpus { min-height: 310px; }
.compact-input { max-width: 160px; margin-top: 13px; }
.runs-table { margin-top: 18px; }
.runs-table table { min-width: 640px; }
.runs-table td { vertical-align: top; }
.runs-table td:nth-child(1), .runs-table td:nth-child(2) { white-space: nowrap; }
.runs-table td:nth-child(3) { min-width: 200px; font-variant-numeric: tabular-nums; }
.file-links { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.file-links a { color: var(--green-dark); text-decoration: none; border-bottom: 1px solid #8cb8a7; }
.file-links a:hover { color: var(--teal); }

@media (max-width: 940px) {
  .workspace { grid-template-columns: 285px minmax(0, 1fr); }
  .control-strip, .evolution-controls { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
  .evolution-layout { grid-template-columns: 1fr; }
  .chart-panel, .evolution-best { padding: 20px 0; }
  .evolution-best { border-left: 0; border-top: 1px solid var(--line); }
}

@media (min-width: 721px) and (max-width: 840px) {
  .structure-toolbar { height: auto; min-height: 124px; padding: 14px 20px; align-items: stretch; flex-direction: column; }
  .structure-toolbar > div:first-child { flex-basis: auto; }
  .structure-toolbar .button-row { width: 100%; }
  .structure-toolbar button { flex: 1; }
  .structure-stage { height: calc(100vh - 275px); }
}

@media (max-width: 720px) {
  .workspace-note { padding: 9px 14px; }
  .app-header { padding: 12px 16px; gap: 10px; }
  .header-status { flex-basis: 100%; max-width: 100%; justify-content: flex-start; gap: 4px 10px; }
  .header-divider { display: none; }
  .workspace { display: block; min-height: auto; }
  .sequence-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px; }
  #sequence-input { height: 140px; min-height: 120px; }
  input, textarea { font-size: 16px; }
  input:not([type="checkbox"]), .primary-button, .secondary-button, .quiet-button, .table-action { min-height: 44px; }
  .metrics-section { margin-top: 18px; }
  .research-note { margin-bottom: 0; }
  .tab-bar { padding: 0 8px; }
  .tab-button { flex: 1; padding: 0 6px; font-size: 12px; }
  .tab-view { min-height: auto; padding: 20px 16px 30px; }
  .tool-header, .structure-toolbar { align-items: flex-start; flex-direction: column; }
  .tool-header > div:first-child, .structure-toolbar > div:first-child { flex-basis: auto; }
  .tool-header > button, .tool-header > .button-row { width: 100%; }
  .tool-header .button-row button { flex: 1; }
  .control-strip, .evolution-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
  .toggle-label { height: 44px; align-self: end; align-items: center; padding: 0; }
  .empty-state { min-height: 200px; }
  .structure-toolbar { height: auto; min-height: 112px; padding: 16px; }
  .structure-toolbar .button-row { width: 100%; }
  .structure-toolbar button { flex: 1; }
  .fold-disclosure { padding: 9px 16px; }
  .structure-stage { height: 62vh; min-height: 420px; }
  .structure-stats { left: 8px; right: 8px; top: 8px; }
  .structure-stats div { min-width: 0; flex: 1; }
  .message-bar { right: 12px; bottom: 12px; max-width: calc(100% - 24px); }
}

@media (max-width: 420px) {
  .brand-block p { display: none; }
  .panel-heading { gap: 10px; }
  .panel-heading h2 { font-size: 16px; }
  .panel-heading .quiet-button { padding: 0 8px; font-size: 12px; }
  .button-row { flex-wrap: wrap; }
  .structure-stats div { padding: 0 8px; }
  .structure-stats dt { min-height: 28px; }
}
