:root {
  --paper: #f7f8fb;
  --surface: #ffffff;
  --sunken: #f1f3f8;
  --rule: #e0e3ec;
  --rule-strong: #c9cedd;
  --ink: #14161d;
  --muted: #666d80;
  --signal: #4f3ddb;
  --signal-soft: #ede9ff;
  --warm: #a4600d;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 7px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* The whole app is one viewport: only the writing surface and the side panel
   ever scroll, and the page itself never does. */
.shell {
  height: 100dvh;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 26px 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.identity {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  min-width: 0;
}

.identity h1 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 1;
}

.identity h1 span {
  margin-left: 0.3em;
  color: var(--signal);
  font-size: 0.42em;
  letter-spacing: 0.08em;
  vertical-align: 0.85em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.runtime {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 100px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--muted);
  white-space: nowrap;
}

.runtime-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rule-strong);
  flex: none;
}

.runtime-dot[data-state="ready"] {
  background: var(--signal);
}

.runtime-dot[data-state="busy"] {
  background: var(--warm);
  animation: pulse 1.1s ease-in-out infinite;
}

.runtime-dot[data-state="error"] {
  background: #c0392b;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* ---------- layout ---------- */

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 20px;
  min-height: 0;
  align-items: stretch;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 9px;
  min-width: 0;
  min-height: 0;
}

.stage-head,
.stage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- writing surface ---------- */

.surface {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 0;
  overflow-y: auto;
}

.surface:focus-within {
  border-color: var(--signal);
}

#prompt,
.transcript {
  width: 100%;
  margin: 0;
  padding: 18px 20px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

#prompt {
  display: block;
  height: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  resize: none;
  outline: none;
}

#prompt::placeholder {
  color: #9aa1b4;
}

/* An id selector outranks the UA rule for [hidden], so the editor and the
   transcript need this to actually swap instead of stacking. */
#prompt[hidden],
.transcript[hidden] {
  display: none;
}

.transcript .given {
  color: var(--ink);
}

/* The signature: each generated token keeps its own confidence. The underline
   opacity is the probability the model assigned to the token it emitted, so a
   hesitant passage looks visibly fainter than a decisive one. */
.token {
  color: var(--signal);
  border-bottom: 2px solid rgb(79 61 219 / var(--confidence, 1));
  padding-bottom: 1px;
}

.transcript .cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 1px;
  background: var(--signal);
  vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------- buttons ---------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.primary {
  padding: 9px 20px;
  border: 1px solid var(--signal);
  background: var(--signal);
  color: #fff;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: #3f2ec4;
  border-color: #3f2ec4;
}

.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ghost {
  padding: 8px 15px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
}

.ghost:hover:not(:disabled) {
  border-color: var(--signal);
  color: var(--signal);
}

.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

:where(button, input, textarea, label):focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.actions {
  display: flex;
  gap: 8px;
}

.readout {
  display: flex;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--muted);
}

.notice {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-left: 2px solid var(--warm);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.82rem;
}

.samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.samples button {
  padding: 5px 11px;
  border: 1px solid var(--rule);
  border-radius: 100px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.73rem;
}

.samples button:hover {
  color: var(--signal);
  border-color: var(--signal);
}

/* ---------- side panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.block {
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  flex: none;
}

.block h2 {
  margin: 0 0 9px;
  font-size: 0.68rem;
  font-weight: 400;
}

.builds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.builds.models {
  grid-template-columns: repeat(3, 1fr);
}

/* Three builds do not fit side by side on one line at this width, so the size
   drops under the name instead of forcing a second row of cards. */
.builds.models .build {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 6px;
}

.builds.models .build-size {
  grid-column: 2;
  margin-left: 0;
}

.build {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sunken);
  cursor: pointer;
}

.build.unavailable {
  opacity: 0.45;
  cursor: not-allowed;
}

.build:has(input:checked) {
  border-color: var(--signal);
  background: var(--signal-soft);
}

.build input {
  accent-color: var(--signal);
  margin: 0;
  flex: none;
}

.build-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.build-size {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.bar {
  position: relative;
  height: 20px;
  margin-top: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--sunken);
}

.bar-fill {
  height: 100%;
  width: 0;
  background: var(--signal-soft);
  transition: width 0.2s linear;
}

.bar-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink);
}

/* Two columns so five sliders occupy three rows instead of five; the panel has
   to clear the whole viewport without scrolling on a laptop screen. */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 14px;
}

.control span {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.control b {
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--ink);
}

.control input[type="range"] {
  width: 100%;
  margin: 3px 0 0;
  accent-color: var(--signal);
}

.toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle input {
  accent-color: var(--signal);
}

.hint {
  margin: -4px 0 10px;
  font-size: 0.73rem;
  color: var(--muted);
}

.hint.tight {
  margin: 7px 0 0;
  line-height: 1.35;
}

.hint:empty {
  display: none;
}

.builds.spaced {
  margin-top: 7px;
}

.candidates {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.candidates li {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--sunken);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  overflow: hidden;
}

.candidates li::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  background: var(--signal-soft);
}

.candidates li.picked::before {
  background: #d9d1ff;
}

.candidates .label,
.candidates .value {
  position: relative;
}

.candidates .label {
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

.candidates .value {
  color: var(--muted);
  flex: none;
}

/* ---------- colophon ---------- */

.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

.colophon p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.colophon .facts {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  white-space: nowrap;
}

/* Narrow or short viewports cannot hold the two-column layout, so the shell
   gives up its fixed height and the page scrolls normally. */
@media (max-width: 900px), (max-height: 680px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100dvh;
  }

  .workbench {
    grid-template-columns: minmax(0, 1fr);
  }

  .surface {
    min-height: 300px;
  }

  .panel {
    overflow: visible;
  }
}

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