:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #17345e;
  --muted: #52657f;
  --line: #d9e6f8;
  --soft: #f5f9ff;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #15803d;
  --red: #b91c1c;
  --red-soft: #fee2e2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: #172033;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #172033;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #172033;
  padding: 10px 12px;
  outline: none;
}

textarea {
  line-height: 1.62;
  resize: vertical;
}

textarea[readonly] {
  background: #f8fbff;
  color: #334155;
}

label {
  display: grid;
  gap: 8px;
  color: #1f3558;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  margin-bottom: 18px;
}

.app-header h1 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 32px;
  line-height: 1.15;
}

.top-tabs,
.sub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.top-tab,
.sub-tab,
.prompt-tab {
  padding: 10px 14px;
  font-weight: 850;
}

.top-tab.active,
.sub-tab.active,
.prompt-tab.active,
.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 900;
}

.secondary {
  background: #f8fafc;
}

.full {
  width: 100%;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.panel,
.result-tabs {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.setup-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}

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

.stage-setting {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.stage-setting h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
}

.token-number {
  max-width: 160px;
}

.muted,
.status-line {
  color: var(--muted);
  line-height: 1.55;
}

.workspace {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-row button {
  flex: 0 0 52px;
  width: 52px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--blue-dark);
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.nav-label {
  flex: 1 1 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid #bcd0ff;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--ink);
  font-weight: 900;
}

#passage-input {
  min-height: 294px;
}

.run-mode-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.run-mode-selector label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 850;
}

.run-mode-selector input {
  width: auto;
}

.run-button {
  min-height: 46px;
}

.download-panel {
  padding: 12px;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  background: #eff6ff;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.button-row button {
  padding: 9px 12px;
}

#save-prompt {
  width: 100%;
  flex: 1 1 100%;
  min-width: 100%;
}

.prompt-secondary-row button {
  flex: 1 1 220px;
}

#import-prompts-file {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--red);
  font-weight: 900;
}

#import-prompts-file:hover {
  border-color: #fca5a5;
  background: #fee2e2;
}

.prompt-upload-label {
  margin-top: 10px;
  padding: 12px;
  border: 1px dashed #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: var(--red);
}

.prompt-upload-label input {
  border-color: #fecaca;
  background: #fffafa;
}

.result-pane {
  display: none;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  line-height: 1.72;
}

.result-pane.active {
  display: block;
}

.summary-running-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 1px solid #fecaca;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 900;
}

.output,
pre.output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #1f2a3d;
  font-size: 13px;
}

.model-table,
.usage-table {
  margin-top: 14px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
}

.prompt-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

#system-prompt,
#input-shape,
#output-shape,
#generation-system-prompt,
#inspection-system-prompt,
#generation-input-shape,
#generation-output-shape,
#inspection-input-shape,
#inspection-output-shape {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

#system-prompt,
#generation-system-prompt,
#inspection-system-prompt {
  min-height: 520px;
}

#prompt-pair-title {
  margin: 14px 0 0;
  color: var(--ink);
  font-size: 18px;
}

.shape-grid {
  display: grid;
  gap: 14px;
}

.type-row {
  max-width: 360px;
  margin-top: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok { background: #dcfce7; color: var(--green); }
.badge.fail { background: #fee2e2; color: var(--red); }
.badge.wait { background: #fef3c7; color: #92400e; }

.locked-note {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid #fecaca;
  border-radius: 999px;
  background: #fee2e2;
  color: var(--red);
  font-weight: 900;
}

.run-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(9, 20, 42, 0.36);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
}

@media (max-width: 980px) {
  .app-shell { padding: 16px; }
  .setup-grid,
  .settings-grid,
  .prompt-layout {
    grid-template-columns: 1fr;
  }
}
