:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #f3f5f7;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body { margin: 0; }

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem max(1rem, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid #d7dce1;
  background: rgba(255, 255, 255, 0.96);
}

h1 { margin: 0; font-size: 1.1rem; }
h2 { margin: 0 0 1rem; font-size: 1rem; }
h3 { margin: 0 0 0.65rem; font-size: 0.9rem; }

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 1rem auto 4rem;
  display: grid;
  gap: 1rem;
}

.panel {
  padding: 1rem;
  border: 1px solid #d7dce1;
  border-radius: 7px;
  background: #fff;
}

.field { display: grid; gap: 0.35rem; min-width: 0; }
.field label, summary { font-size: 0.84rem; font-weight: 650; }
.field small, small, .muted { color: #68727d; font-size: 0.78rem; }

input, select, textarea, button, .file-button {
  font: inherit;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #b8c0c8;
  border-radius: 5px;
  background: #fff;
  color: inherit;
}

input, select { height: 2.35rem; padding: 0 0.65rem; }
textarea {
  min-height: 22rem;
  margin-top: 0.7rem;
  padding: 0.75rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

input:focus, select:focus, textarea:focus, button:focus-visible, .file-button:focus-visible {
  outline: 2px solid #2264d1;
  outline-offset: 1px;
}

button, .file-button {
  min-height: 2.35rem;
  padding: 0.5rem 0.8rem;
  border: 1px solid #aeb6bf;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}

button:disabled { cursor: not-allowed; opacity: 0.5; }
input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.65; }
.is-busy .file-button { pointer-events: none; cursor: not-allowed; opacity: 0.5; }
.is-busy #drawingPad { pointer-events: none; cursor: wait; opacity: 0.75; }
.secondary, .file-button { background: #fff; color: #202832; }
.primary { border-color: #1552b3; background: #1552b3; color: #fff; }
.primary-sized { min-width: 13rem; }

.inline, .toolbar, .section-heading, .run-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inline input { flex: 1; }
.section-heading { justify-content: space-between; margin-bottom: 0.8rem; }
.section-heading h2 { margin: 0; }
.toolbar { flex-wrap: wrap; }
.run-bar { justify-content: flex-end; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
  gap: 1rem;
}

.workspace-controls {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.workspace-controls .input-grid { grid-template-columns: 1fr 1fr; }
.workspace-controls .input-grid .wide { grid-column: 1 / -1; }
.scratchpad-panel { min-width: 0; }

.model-grid {
  display: grid;
  grid-template-columns: minmax(250px, 2fr) minmax(120px, 0.7fr) minmax(250px, 2fr) minmax(160px, 1fr) minmax(100px, 0.6fr);
  gap: 0.8rem;
  margin-top: 1rem;
}

.input-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 0.8rem;
}

#drawingPad {
  display: block;
  width: 810px;
  height: 1065px;
  max-width: none;
  border: 1px solid #aeb8c2;
  border-radius: 4px;
  background: #fffdf7;
  cursor: crosshair;
  touch-action: none;
}

.drawing-pad-scroll {
  width: 100%;
  max-height: min(1065px, 70vh);
  overflow: auto;
  margin-bottom: 0.35rem;
  border-radius: 4px;
  overscroll-behavior: contain;
}

.drawing-pad-scroll:focus-visible {
  outline: 2px solid #2264d1;
  outline-offset: 2px;
}

details + details { margin-top: 0.8rem; }
summary { cursor: pointer; user-select: none; }
.prompt-actions { justify-content: flex-end; margin-top: 0.8rem; }

.status {
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: #edf1f4;
  color: #4b5661;
  font-size: 0.78rem;
}
.status.working { background: #fff3cd; color: #694f00; }
.status.success { background: #e2f5e8; color: #135b2a; }
.status.error { background: #fde7e7; color: #842029; }

.cost-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.cost-grid article {
  padding: 0.8rem;
  border: 1px solid #d9dee3;
  border-radius: 5px;
  background: #fafbfc;
}

.total-card { background: #eef4ff !important; border-color: #b9cff4 !important; }
.cost { margin-bottom: 0.6rem; font-size: 1.45rem; font-weight: 750; font-variant-numeric: tabular-nums; }
dl { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.8rem; margin: 0; font-size: 0.77rem; }
dt { color: #68727d; }
dd { margin: 0; font-variant-numeric: tabular-nums; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

pre {
  min-height: 15rem;
  max-height: 38rem;
  overflow: auto;
  margin: 0;
  padding: 0.8rem;
  border: 1px solid #d9dee3;
  border-radius: 5px;
  background: #f7f8fa;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.76rem;
  line-height: 1.45;
}

.image-result {
  min-height: 15rem;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #d9dee3;
  border-radius: 5px;
  background: #f7f8fa;
}

.image-result img { display: block; width: 100%; height: auto; }

@media (max-width: 900px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .model-grid, .input-grid { grid-template-columns: 1fr 1fr; }
  .result-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  header { position: static; }
  main { width: min(100% - 1rem, 1180px); }
  .model-grid, .input-grid, .cost-grid { grid-template-columns: 1fr; }
  .workspace-controls .input-grid { grid-template-columns: 1fr; }
  .workspace-controls .input-grid .wide { grid-column: auto; }
  .inline { align-items: stretch; flex-wrap: wrap; }
  .inline input { flex-basis: 100%; }
  .run-bar { align-items: stretch; flex-direction: column; }
  .primary-sized { width: 100%; }
}
