:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --paper: #fff;
  --ink: #16181b;
  --muted: #565c65;
  --rule: #d6d9dd;
  --field: #878d95;
  --accent: #2747d4;
  --accent-soft: #eef1fd;
  --ok: #157a4a;
  --warn: #8f5400;
  --error: #b42318;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
}
@media (min-width: 1400px) { :root { font-size: 18px; } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; }
h1, h2, h3, p { margin: 0; font-size: inherit; }
p { line-height: 1.5; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.bar { width: min(100% - 2.5rem, 1200px); margin-inline: auto; }
.skip-link { position: absolute; left: 1rem; top: 1rem; z-index: 3; padding: .6rem 1rem; background: var(--paper); transform: translateY(-200%); }
.skip-link:focus { transform: none; }

/* Masthead: dark mode bar, then the model strip */
.masthead { background: var(--paper); border-bottom: 1px solid var(--ink); }
.masthead > .bar:first-child { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3rem; color: #fff; background: var(--ink); box-shadow: 0 0 0 100vmax var(--ink); clip-path: inset(0 -100vmax); }
.brand { font-size: .9375rem; font-weight: 700; white-space: nowrap; }
.brand span { margin-left: .5rem; font: 400 .75rem var(--mono); color: #b9bec6; text-transform: uppercase; letter-spacing: .08em; }
.modes { display: flex; align-self: stretch; }
.modes button { min-height: 3rem; padding: 0 1rem; border: 0; border-bottom: 3px solid transparent; background: none; color: #c3c8cf; font-size: .9375rem; font-weight: 600; white-space: nowrap; }
.modes button[aria-selected="true"] { color: #fff; border-bottom-color: #fff; }
.modes button:not(:disabled):hover { color: #fff; }
.modes button:disabled:not([aria-selected="true"]) { color: #7f858d; }
.modes button:focus-visible { outline-color: #fff; outline-offset: -4px; }

.model { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .35rem 1.25rem; padding-block: .55rem; }
.model-id { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .75rem; min-width: 0; grid-area: 1 / 2; }
.model h2 { font-size: .9375rem; font-weight: 700; }
#model-detail { color: var(--muted); font-size: .875rem; }
#model-status { display: flex; align-items: center; gap: .45rem; font: 600 .75rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); overflow-wrap: anywhere; }
#model-status::before { flex: none; width: .55rem; height: .55rem; border-radius: 50%; background: var(--field); content: ""; }
#model-status[data-state="loading"] { color: var(--warn); }
#model-status[data-state="loading"]::before { background: var(--warn); }
#model-status[data-state="ready"] { color: var(--ok); }
#model-status[data-state="ready"]::before { background: var(--ok); }
#model-status[data-state="error"] { grid-area: 2 / 1 / auto / -1; align-items: baseline; color: var(--error); text-transform: none; letter-spacing: 0; }
#model-status[data-state="error"]::before { background: var(--error); }
#model-status[data-state="error"] + .model-id { grid-column: 1 / -2; }
#load-model { grid-area: 1 / 3; }
progress { grid-column: 1 / -1; width: 100%; height: .375rem; accent-color: var(--accent); }

/* Buttons */
.primary, .quiet, .stop { min-height: 2.75rem; padding: 0 1.1rem; border: 1px solid transparent; border-radius: 3px; font-size: .9375rem; font-weight: 650; white-space: nowrap; }
.primary { background: var(--ink); color: #fff; }
.primary:not(:disabled):hover { background: var(--accent); }
.primary:disabled { background: #e2e4e7; color: #5b6169; }
.quiet { background: var(--paper); border-color: var(--field); }
.quiet:not(:disabled):hover { border-color: var(--ink); }
.quiet:disabled { color: #6b7079; background: transparent; border-color: var(--rule); }
.stop { background: var(--paper); border-color: var(--error); color: var(--error); }
.stop:not([aria-disabled="true"]):hover { background: #fdf0ee; }
.stop[aria-disabled="true"] { color: var(--muted); border-color: var(--rule); cursor: default; }
.text-button { min-height: 1.75rem; padding: 0; border: 0; background: none; color: var(--accent); font-size: .875rem; font-weight: 600; text-decoration: underline; text-underline-offset: .2em; }
.text-button:disabled { color: var(--muted); }

/* Fields */
label { display: block; margin-bottom: .35rem; font-size: .875rem; font-weight: 650; }
label span { margin-left: .35rem; font: 400 .75rem var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
textarea, input { display: block; width: 100%; padding: .6rem .7rem; background: var(--paper); border: 1px solid var(--field); border-radius: 3px; }
textarea { min-height: 2.75rem; line-height: 1.45; resize: vertical; }
textarea::placeholder { color: #646a73; opacity: 1; }
textarea[readonly] { background: var(--bg); }
textarea:focus-visible, input:focus-visible { outline-offset: 0; border-color: var(--accent); }
input { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem .75rem; min-width: 0; }
.form-actions p { margin-right: auto; color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.form-actions p[data-error="true"] { color: var(--error); font-weight: 600; }
.disclosure { min-width: 0; }
.disclosure summary { min-height: 2.25rem; padding-block: .5rem; color: var(--ink); font-size: .875rem; font-weight: 650; cursor: pointer; }
.disclosure summary:hover { color: var(--accent); }
.disclosure summary span { margin-left: .4rem; color: var(--muted); font-size: .8125rem; font-weight: 400; }
.explore-content { display: grid; gap: .75rem; max-width: 44rem; padding-block: .3rem .65rem; }
.field-help { margin-top: .25rem; color: var(--muted); font-size: .8125rem; overflow-wrap: anywhere; }

.inspector { border-top: 1px solid var(--rule); }
.inspector-pair { margin-block: .75rem; }
.request-messages { margin-block: .65rem 0; padding: .55rem .7rem; border: 1px solid var(--rule); background: var(--paper); }
.request-messages dt { color: var(--muted); font: 600 .75rem var(--mono); }
.request-messages dt:not(:first-child) { margin-top: .65rem; padding-top: .65rem; border-top: 1px solid var(--rule); }
.request-messages dd { margin: .3rem 0 0; font: .8125rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Panels */
main { min-height: 0; overflow: auto; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.25rem; border-bottom: 1px solid var(--rule); }
.toolbar h2 { font-size: 1rem; font-weight: 700; }
.toolbar h2 span, .tag, .side-state, .settings-used, .message h3 { font-family: var(--mono); font-size: .75rem; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.toolbar h2 span { margin-left: .6rem; color: var(--muted); }
.toolbar .quiet { min-height: 2.25rem; font-size: .875rem; }

/* Chat */
.chat-panel { display: flex; flex-direction: column; height: 100%; min-height: 24rem; }
.chat-history { flex: 1; min-height: 8rem; overflow: auto; overscroll-behavior-y: contain; }
.chat-history:focus-visible { outline-offset: -3px; }
.chat-empty { padding-block: 1.5rem; }
.chat-empty p { color: var(--muted); max-width: 60ch; }
.examples { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }
.examples .quiet { font-weight: 500; }
#chat-messages:not(:empty) { padding-block: .25rem 1.5rem; }
.message { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: .25rem 1rem; padding-block: 1rem; border-bottom: 1px solid var(--rule); }
.message h3 { padding-top: .3rem; color: var(--muted); }
.message.assistant h3 { color: var(--ink); font-weight: 700; }
.message > p, .response { max-width: 70ch; font-size: 1.0625rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message .message-note { grid-column: -2; font-size: .875rem; color: var(--warn); }
.message.user > p { font-weight: 550; }
.message.assistant > p:empty::before { content: "Generating…"; color: var(--muted); }
.message .inspector { grid-column: -2; margin-top: .2rem; border-top: 0; }
.composer { padding-block: .7rem calc(.7rem + env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--ink); }
.composer-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .6rem; }
.composer textarea { max-height: 30vh; }
.composer .explore { margin-top: .15rem; }
.composer .explore-content { display: block; }
.composer .form-actions { min-height: 2.25rem; margin-top: .4rem; }
.composer .stop { min-height: 2.25rem; }

/* Compare */
.compare-body { display: grid; gap: 1.25rem; padding-block: 1rem 2rem; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.shared textarea { min-height: 4rem; font-size: 1.0625rem; border-color: var(--ink); }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.5rem; }
.side-a, .side-b { padding-top: .6rem; border-top: 3px solid var(--accent); }
.side-b { border-top-color: var(--ink); }
.tag { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; margin-right: .35rem; border-radius: 2px; background: var(--accent); color: #fff; font-weight: 700; letter-spacing: 0; vertical-align: .05em; }
.side-b .tag { background: var(--ink); }
.instruction-title { font-size: .875rem; font-weight: 650; }
.instruction-title span { margin-left: .35rem; color: var(--muted); font-size: .8125rem; font-weight: 400; }
.instruction-preview { display: -webkit-box; overflow: hidden; margin-top: .3rem; color: var(--muted); font-size: .875rem; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.side-a:has(#custom-instruction[open]) .instruction-preview { display: none; }

.compare-body > .explore { margin-block: -.5rem; }
.run-bar { padding-block: .5rem; border-block: 1px solid var(--rule); }
#compare-form[data-running] .run-bar { position: sticky; top: 0; z-index: 1; background: var(--bg); }
.run-bar .form-actions { min-height: 2.75rem; }
#comparison-stale { margin-top: .25rem; color: var(--warn); font-size: .875rem; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: .4rem; padding: 0; font-size: .875rem; font-weight: 650; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); gap: .75rem; max-width: 39.25rem; padding-block: .25rem .5rem; }
.settings-grid label { font-size: .8125rem; font-weight: 600; }

.output { min-height: 9rem; }
.output-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem .75rem; padding-bottom: .5rem; border-bottom: 1px solid var(--rule); }
.output h3 { font-size: 1rem; font-weight: 700; }
.side-state { display: flex; align-items: center; gap: .4rem; color: var(--muted); }
.side-state::before { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; content: ""; }
.output[data-state="generating"] .side-state { color: var(--accent); }
.output[data-state="generating"] .side-state::before { animation: pulse 1s ease-in-out infinite alternate; }
.output[data-state="complete"] .side-state { color: var(--ok); }
.output[data-state="stopped"] .side-state { color: var(--warn); }
.output[data-state="error"] .side-state { color: var(--error); font-weight: 700; }
.response { padding-top: .75rem; }
.response[data-empty] { color: var(--muted); font-size: .9375rem; }
.settings-used { color: var(--muted); }
.notice { padding: 1rem 0; color: var(--error); text-align: center; }
@keyframes pulse { to { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

@media (max-width: 760px) {
  .bar { width: calc(100% - 1.5rem); }
  .brand span { display: none; }
  .modes button { padding-inline: .7rem; }
  .model { grid-template-columns: minmax(0, 1fr) auto; }
  #model-status { grid-row: 2; grid-column: 1 / -1; }
  .model-id, #load-model { grid-area: 1 / 1; }
  #load-model { grid-column: 2; }
  #model-detail { font-size: .8125rem; line-height: 1.35; }
  .toolbar { min-height: 2.75rem; }
  .chat-panel .toolbar h2 span { display: none; }
  .compare-panel .toolbar h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .6rem; }
  .compare-panel .toolbar h2 span { margin-left: 0; }
  .message { grid-template-columns: minmax(0, 1fr); padding-block: .8rem; }
  .message h3 { padding-top: 0; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-body { gap: 1rem; padding-top: .75rem; }
}
@media (max-width: 360px) {
  .brand { font-size: .875rem; }
  .modes button { padding-inline: .5rem; font-size: .875rem; }
  .chat-empty { padding-block: .85rem; }
  .examples { margin-top: .65rem; }
  .examples .quiet { min-height: 2.25rem; }
  .compare-body { gap: .75rem; }
}
