:root {
  color-scheme: light;
  --background: #fbfaff;
  --surface: #fff;
  --ink: #292638;
  --muted: #686477;
  --line: #e3deed;
  --accent: #6651c7;
  --accent-dark: #4c37a8;
  --accent-soft: #f0ebff;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--ink); font: 14px/1.55 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
button, summary, select { cursor: pointer; }
button { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .52; }
a { color: var(--accent); text-underline-offset: 3px; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible,
textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

.workspace { width: min(100% - 64px, 960px); margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; min-height: 96px; border-bottom: 1px solid var(--line); }
h1 { color: #392e69; font-size: 23px; line-height: 1.2; font-weight: 550; letter-spacing: -.75px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.connection-button, .quiet-button { border: 0; background: none; padding: 8px 2px; font-size: 13px; color: var(--muted); }
.connection-button { display: inline-flex; align-items: center; gap: 7px; }
.connection-button:hover, .quiet-button:hover { color: var(--ink); }
.status-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #07845c; }
.status-dot.warming { background: #bd8109; }
.status-dot.offline { background: #c13e5c; }

main { padding-top: 26px; }
.auth-notice { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 13px 16px; margin-bottom: 26px; border: 1px solid #ddd4f6; border-radius: 5px; background: var(--accent-soft); font-size: 14px; color: #51456f; }
.auth-notice .text-button { white-space: nowrap; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 34px; margin-bottom: 14px; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -.1px; }
.usage-example { margin-bottom: 24px; border: 1px solid #ddd4f6; border-radius: 6px; background: var(--accent-soft); }
.usage-example > summary { width: auto; margin: 0; padding: 11px 16px; color: var(--accent-dark); font-size: 14px; font-weight: 550; list-style-position: inside; }
.usage-example > summary::marker { color: var(--accent); }
.usage-content { padding: 4px 18px 18px; color: #51456f; line-height: 1.75; }
.usage-steps { margin: 0; padding-left: 22px; }
.usage-steps li + li { margin-top: 18px; }
.usage-steps li::marker { color: var(--accent); font-weight: 600; }
.usage-steps p + p { margin-top: 8px; }
.usage-content pre { margin: 12px 0; padding: 15px; border: 1px solid #e0d8f2; border-radius: 4px; background: var(--surface); color: #413565; font: 13px/1.85 var(--mono); overflow-x: auto; }
.usage-content code { color: #413565; font: 13px var(--mono); }
.example-picker { display: flex; align-items: center; gap: 10px; min-width: 0; }
.example-picker label { color: var(--muted); font-size: 14px; }
.example-picker select { width: 220px; min-width: 0; max-width: 100%; padding: 8px 28px 8px 10px; font-size: 13px; background: var(--surface); border: 1px solid #d6cfe4; border-radius: 4px; }
.code-editor { position: relative; padding-left: 49px; background: var(--surface); border: 1px solid #d6cfe4; border-radius: 5px; overflow: hidden; }
.code-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px #6651c71a; }
.line-numbers { position: absolute; inset: 0 auto 0 0; width: 49px; padding: 21px 13px 20px 7px; text-align: right; color: #8b819d; font: 13px/1.85 var(--mono); overflow: hidden; user-select: none; white-space: pre; }
#model-editor { display: block; width: 100%; min-width: 0; height: 238px; min-height: 84px; max-height: 650px; padding: 21px 22px 20px 0; border: 0; border-radius: 0; background: transparent; color: #352e46; resize: vertical; font: 13px/1.85 var(--mono); tab-size: 4; white-space: pre; overflow: auto; }
#model-editor:focus-visible { outline: none; }
.analysis-controls { display: grid; grid-template-columns: minmax(260px, 1.35fr) minmax(130px, .8fr) minmax(175px, 1fr) auto; align-items: end; gap: 14px; margin-top: 22px; }
.analysis-controls.functions-mode { grid-template-columns: minmax(260px, 1fr) minmax(175px, 1fr) auto; }
.analysis-controls.reparam-mode { grid-template-columns: minmax(260px, 1fr) auto; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 450; color: var(--ink); }
.field select, .field input { display: block; width: 100%; height: 40px; padding: 7px 10px; border: 1px solid #d6cfe4; border-radius: 4px; background: var(--surface); font-size: 13px; }
.field small { display: block; margin-top: 9px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.run-actions { display: flex; grid-column: -2 / -1; grid-row: 1; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 13px; border: 1px solid #d6cfe4; border-radius: 4px; background: var(--surface); font-size: 13px; line-height: 1.4; font-weight: 500; text-decoration: none; white-space: nowrap; }
.button.secondary:hover:not(:disabled) { background: var(--accent-soft); border-color: #b8a7e7; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
#run-button { min-width: 128px; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 14px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.custom-functions { grid-column: 1 / -1; grid-row: 2; }
.custom-functions input { font-family: var(--mono); }
.options { margin-top: 19px; }
summary { width: fit-content; color: var(--muted); font-size: 14px; list-style-position: outside; margin-left: 16px; }
summary::marker { color: #8f7db6; }
summary:hover { color: var(--ink); }
.options-content { display: flex; align-items: end; flex-wrap: wrap; gap: 18px 24px; padding: 17px 0 2px; }
.probability-field { width: 168px; }
.option-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.option-actions .button { min-height: 36px; padding: 7px 10px; font-size: 13px; }
.validation-message { margin-top: 15px; padding: 11px 13px; border-left: 2px solid #07845c; background: #eaf8f2; color: #087b57; font-size: 14px; overflow-wrap: anywhere; }
.validation-message.error { background: #fff0f3; border-color: #c13e5c; color: #a32d4a; }

.results-section { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.results-section .section-heading { min-height: 25px; margin-bottom: 14px; }
.result-label { font-size: 13px; color: var(--muted); }
.result-label.complete { color: #07845c; }
.empty-state { min-height: 64px; padding-top: 10px; color: var(--muted); font-size: 14px; }
.stale-banner { margin-bottom: 18px; padding: 10px 12px; border-left: 2px solid #bd8109; background: #fff7e5; color: #855600; font-size: 14px; }
.running-state { padding: 9px 0 26px; }
.running-heading { display: flex; align-items: baseline; gap: 18px; }
.running-state h3, .error-state h3 { font-size: 14px; line-height: 1.5; font-weight: 550; }
.running-state p { color: var(--muted); font-size: 14px; margin-top: 7px; }
.elapsed { color: var(--accent); font: 13px var(--mono); }
.error-state { padding: 15px 17px 17px; margin: 6px 0 23px; border: 1px solid #e6d7c9; border-radius: 5px; background: #fffcf6; }
.error-state h3 { color: #80654b; }
.error-state p { margin-top: 7px; color: #856c55; font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.error-state .button { margin-top: 14px; }
.result-overview { margin: 1px 0 20px; padding: 15px 18px; border-left: 3px solid var(--accent); border-radius: 3px; background: var(--accent-soft); }
.result-overview h3 { font-size: 17px; line-height: 1.5; font-weight: 550; color: #3f3073; }
.result-overview p { font-size: 14px; color: #615376; margin-top: 5px; line-height: 1.7; }
.result-table-wrap { overflow-x: auto; }
.function-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.function-list li { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.function-list code { color: #343c36; font: 13px/1.7 var(--mono); white-space: pre-wrap; }
.reparam-results h3 { margin: 22px 0 10px; font-size: 14px; font-weight: 550; }
.reparam-results h3:first-child { margin-top: 0; }
.reparam-results pre { margin: 0; padding: 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: #343c36; font: 12px/1.85 var(--mono); }
.reparam-results td:nth-child(2) { font: 12px/1.7 var(--mono); overflow-wrap: anywhere; }
.reparam-results td:nth-child(3) { color: var(--muted); font-size: 14px; }
.reparam-constraints { margin-top: 22px; }
.reparam-constraints p { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
table { border-collapse: collapse; width: 100%; text-align: left; font-size: 14px; }
th { padding: 11px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 450; }
td { padding: 13px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
th + th, td + td { padding-left: 24px; }
td:first-child { font: 13px var(--mono); color: #343c36; overflow-wrap: anywhere; }
td small { display: inline; margin-left: 12px; font: 13px var(--sans); color: var(--muted); }
.classification { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; white-space: nowrap; }
.classification::before { content: ''; width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: currentColor; }
.classification.global { color: #087b57; }
.classification.local { color: #986000; }
.classification.non { color: #b33353; }
.result-footer { display: flex; align-items: start; justify-content: space-between; gap: 18px; padding-top: 15px; }
.result-meta { margin-top: 10px; font-size: 14px; line-height: 1.8; color: var(--muted); }
#export-results { min-height: 36px; font-size: 13px; padding: 7px 10px; }
.interpretation { margin-top: 22px; }
.interpretation-content { max-width: 650px; padding-top: 5px; font-size: 14px; color: var(--muted); }
dl { margin: 12px 0; }
dl > div { display: grid; grid-template-columns: 160px 1fr; gap: 12px; margin-top: 8px; }
dt { font-weight: 500; color: #5e7052; }
dd { margin: 0; }
.interpretation-content p { line-height: 1.8; }
.page-footer { display: grid; gap: 18px; margin: 38px 0 28px; padding-top: 22px; border-top: 1px solid var(--line); font-size: 14px; }
.maintainer-contacts { color: var(--muted); line-height: 1.8; }
.page-footer a { color: var(--accent-dark); }
.page-footer a:hover { color: var(--accent); }
.footer-links { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.data-policy p { margin-top: 12px; color: var(--muted); }
.data-policy .error { color: #b33353; }
.project-logos { display: flex; align-items: center; gap: 18px; }
.project-logos a { display: flex; align-items: center; gap: 6px; }
.project-logos img { display: block; width: auto; height: 23px; max-width: 75px; object-fit: contain; }

/* Native dialogs keep keyboard focus within the active interaction. */
dialog { width: min(440px, calc(100% - 36px)); max-height: calc(100% - 48px); padding: 0; border: 1px solid #d8e2cc; border-radius: 7px; background: var(--surface); color: var(--ink); box-shadow: 0 18px 70px #21301a24; }
dialog::backdrop { background: #1e2b1838; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px 0; }
.dialog-heading h2 { font-size: 18px; font-weight: 550; letter-spacing: -.35px; }
.close-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 3px; background: none; color: #93a082; font-size: 23px; line-height: 1; }
.close-button:hover { background: #f1f6e9; color: #57713f; }
.dialog-body { padding: 21px 24px 25px; }
.dialog-body .field label { font-size: 14px; color: var(--ink); }
.dialog-body .field input { height: 40px; }
.advanced-connection { margin-top: 23px; }
.advanced-connection > .field { margin-top: 16px; }
#connection-status { font-size: 14px; line-height: 1.7; color: #087b57; overflow-wrap: anywhere; margin-top: 17px; }
#connection-status:empty { display: none; }
#connection-status.error { color: #9b7454; }
#connect-button { margin-top: 22px; }
#help-dialog { width: min(520px, calc(100% - 36px)); }
.help-content { font-size: 14px; line-height: 1.85; color: var(--muted); }
.help-content p + p { margin-top: 13px; }
.help-content strong { color: #3e493f; font-weight: 550; }
.help-content pre { margin: 15px 0; padding: 13px 15px; border: 1px solid #e3ebd9; border-radius: 4px; background: #f8fbf2; color: #637e49; font: 12px/1.85 var(--mono); overflow-x: auto; }
.help-content code { padding: 1px 3px; border-radius: 2px; background: var(--accent-soft); font-size: 13px; font-family: var(--mono); }
.help-content > a { display: inline-block; margin-top: 18px; }
.help-content > .logo-credits { margin-left: 16px; color: var(--muted); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); max-width: min(520px, calc(100% - 36px)); padding: 12px 17px; border: 1px solid #dae3ce; border-radius: 5px; background: #fff; color: #5d7a42; box-shadow: 0 5px 22px #25381814; font-size: 12px; z-index: 20; }
.toast.error { color: #8a694a; border-color: #deceba; }

@media (max-width: 800px) {
  .workspace { width: calc(100% - 40px); }
  .page-header { min-height: 90px; gap: 16px; }
  h1 { font-size: 20px; letter-spacing: -.55px; }
  .header-actions { gap: 12px; }
  .connection-button, .quiet-button { font-size: 13px; }
  .analysis-controls, .analysis-controls.functions-mode, .analysis-controls.reparam-mode { grid-template-columns: 1fr 1.12fr; gap: 17px 14px; }
  #operation-field { grid-column: 1 / -1; }
  .analysis-controls.functions-mode #scope-field { grid-column: 1 / -1; }
  .run-actions { grid-column: 1 / -1; grid-row: auto; justify-content: flex-end; flex-direction: row-reverse; }
  .custom-functions { grid-row: auto; }
  #run-button { min-width: 135px; }
  .option-actions { gap: 7px; }
  .options-content { gap: 15px; }
  .results-section { margin-top: 30px; }
  td small { display: block; margin: 5px 0 0; }
}

@media (max-width: 480px) {
  .workspace { width: calc(100% - 32px); }
  .page-header { flex-wrap: wrap; justify-content: flex-start; gap: 8px 22px; padding: 23px 0 19px; min-height: 0; }
  h1 { font-size: 21px; flex: 1 0 100%; }
  .header-actions { gap: 18px; }
  .connection-button, .quiet-button { padding: 3px 0; font-size: 13px; }
  main { padding-top: 25px; }
  .auth-notice { align-items: flex-start; flex-direction: column; gap: 8px; padding: 12px; }
  .section-heading { gap: 12px; }
  .example-picker { gap: 8px; }
  .example-picker select { width: 175px; }
  .code-editor { padding-left: 35px; }
  .line-numbers { width: 35px; padding-left: 4px; padding-right: 10px; font-size: 12px; }
  #model-editor { padding-right: 13px; font-size: 12px; height: 216px; }
  .analysis-controls { margin-top: 22px; gap: 15px 12px; }
  .field select, .field input { font-size: 13px; }
  .button { min-height: 37px; }
  .results-section { padding-top: 22px; }
  .empty-state { min-height: 64px; font-size: 14px; }
  .result-footer { flex-direction: column; gap: 12px; }
  .classification { font-size: 13px; gap: 5px; white-space: normal; }
  th + th, td + td { padding-left: 15px; }
  dl > div { grid-template-columns: 1fr; gap: 2px; margin-top: 13px; }
  .page-footer { margin-top: 34px; }
  .dialog-heading { padding: 18px 20px 0; }
  .dialog-body { padding: 18px 20px 22px; }
  .dialog-body .field input { font-size: 16px; }
  .toast { font-size: 11px; width: calc(100% - 32px); }
}
