:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #66736c;
  --line: #d8ded9;
  --panel: #f7f8f4;
  --paper: #ffffff;
  --accent: #1d6f5f;
  --accent-dark: #12483e;
  --bad: #b33a2f;
  --good: #267045;
  --warn: #8b5b12;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.prompt-panel,
.viewer,
.summary-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.prompt-panel {
  padding: 20px;
}

.title-row,
.controls,
.book-toolbar,
.page-header,
.string-row,
.mode-row,
.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-row {
  justify-content: space-between;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.model-selector {
  width: min(320px, calc(100vw - 190px));
  margin-top: 8px;
}

.model-selector select:disabled {
  color: var(--ink);
  background: #fff;
  opacity: 1;
}

.loaded-model-caption {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 110px;
  padding: 12px;
  line-height: 1.45;
}

textarea:disabled {
  color: var(--ink);
  background: #f8faf8;
  opacity: 1;
  cursor: not-allowed;
}

.mode-row {
  margin-bottom: 14px;
}

.mode-option {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  width: max-content;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
}

.mode-option input {
  width: 16px;
  height: 16px;
}

input,
select {
  height: 40px;
  padding: 0 10px;
}

.controls {
  display: grid;
  grid-template-columns: 130px 140px 150px;
  margin-top: 14px;
}

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

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

.primary {
  min-width: 124px;
  height: 42px;
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  font-weight: 750;
}

.primary:hover {
  background: var(--accent-dark);
}

.icon {
  width: 40px;
  height: 40px;
  font-size: 28px;
  line-height: 1;
}

.message {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #e1c99b;
  background: #fff7e4;
  color: #5d4210;
}

.instruction-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
  margin-top: 14px;
}

.instruction-panel[hidden] {
  display: none;
}

.structure-input-panel,
.constraint-panel {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.constraint-panel {
  align-content: start;
  gap: 8px;
}

.structure-input-panel {
  align-content: start;
}

.constraint-panel label {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.constraint-panel input {
  height: 34px;
}

.property-control,
.logp-control {
  display: grid;
  grid-template-columns: 108px minmax(140px, 1fr);
  align-items: center;
  gap: 10px;
}

.property-control input[type="range"],
.logp-control input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.section-title {
  justify-content: space-between;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.structure-mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: min(260px, 100%);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eef3ef;
}

.switch-option {
  height: 34px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.switch-option.active {
  color: #fff;
  background: var(--accent);
}

.structure-mode-panel {
  display: grid;
  gap: 12px;
}

.sketch-panel {
  min-width: 0;
}

.template-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-chip {
  min-height: 32px;
  padding: 0 10px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.sketcher-canvas {
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sketch-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 106px;
  gap: 10px;
  align-items: end;
}

.sketch-input-row textarea {
  min-height: 82px;
}

.sketch-actions {
  display: grid;
  gap: 8px;
}

.sketch-actions button {
  height: 34px;
  font-size: 12px;
  font-weight: 800;
}

.sketch-preview {
  display: grid;
  grid-template-columns: minmax(160px, 240px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.sketch-preview img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-right: 1px solid var(--line);
  padding-right: 10px;
}

.sketch-preview-copy {
  min-width: 0;
}

.sketch-preview-copy strong {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.structure-examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 3px;
}

.structure-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  text-align: left;
}

.structure-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 111, 95, 0.15);
}

.structure-card img {
  width: 100%;
  height: 138px;
  object-fit: contain;
  border-bottom: 1px solid var(--line);
}

.structure-card strong {
  color: var(--ink);
  font-size: 13px;
}

.structure-card code {
  max-height: 76px;
}

.structure-empty {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.viewer,
.summary-panel {
  margin-top: 18px;
  padding: 16px;
}

.book-toolbar {
  justify-content: center;
  margin-bottom: 14px;
}

.jump-label {
  display: flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.jump-label select {
  width: 112px;
}

#pageIndex {
  min-width: 70px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.book {
  position: relative;
  min-height: 700px;
  perspective: 1800px;
}

.book.empty {
  min-height: 520px;
}

.book.has-source {
  min-height: 1520px;
}

.empty-state {
  display: grid;
  min-height: 520px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #c8d0ca;
  border-radius: 8px;
  background: #fff;
}

.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  min-height: 700px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 28px rgba(23, 32, 27, 0.08);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 560ms ease, opacity 180ms ease;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.book.has-source .page {
  min-height: 1520px;
}

.page.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

.page.turning {
  transform: rotateY(-12deg);
}

.page-top {
  min-width: 0;
}

.string-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.page-body {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(0, 1.05fr);
  gap: 18px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.molecule-info {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding-top: 2px;
  flex: 0 0 auto;
}

.molecule-info + .molecule-info {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.structure {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 430px;
  border-right: 1px solid var(--line);
  padding-right: 18px;
}

.structure img {
  width: min(100%, 430px);
  max-height: 390px;
}

.attributes {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: auto;
  max-height: 420px;
  padding-right: 4px;
}

.property-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.property-tabs {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef3ef;
}

.property-tab {
  height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.property-tab.active {
  color: #fff;
  background: var(--accent);
}

.property-page {
  display: none;
  min-width: 0;
}

.property-page.active {
  display: block;
}

.advanced-page {
  display: none;
}

.advanced-page.active {
  display: grid;
  gap: 12px;
}

.advanced-section {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #c8ded5;
  border-radius: 8px;
  background: #f4fbf8;
}

.advanced-section h4 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  line-height: 1.2;
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.advanced-metric {
  min-width: 0;
  padding: 8px;
  border: 1px solid #d7e7df;
  border-radius: 6px;
  background: #fff;
}

.advanced-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.advanced-metric strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.page-header {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.badge {
  color: var(--accent-dark);
  background: #dceee9;
}

.pill.good {
  color: var(--good);
  background: #e3f3e8;
}

.pill.bad {
  color: var(--bad);
  background: #f8e2df;
}

.string-block {
  margin: 12px 0;
}

.string-row {
  justify-content: space-between;
  margin-bottom: 6px;
}

.copy {
  min-width: 62px;
  height: 30px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 750;
}

code {
  display: block;
  overflow-wrap: anywhere;
  max-height: 92px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9f8;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

table {
  width: 100%;
  margin-top: 0;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

th,
td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  overflow-wrap: anywhere;
}

.target-delta {
  color: var(--muted);
  white-space: nowrap;
}

th {
  width: 46%;
  color: var(--muted);
  font-weight: 700;
}

.invalid {
  display: grid;
  place-items: center;
  min-height: 420px;
  color: var(--bad);
  border: 1px dashed #e5aaa4;
  border-radius: 8px;
  background: #fff7f6;
  text-align: center;
  padding: 24px;
}

.summary-panel {
  background: #fff;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric-card {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 22px;
}

.metric-card small {
  color: var(--muted);
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 10px;
  }

  .title-row,
  .controls,
  .instruction-panel {
    grid-template-columns: 1fr;
  }

  .sketch-input-row,
  .sketch-preview {
    grid-template-columns: 1fr;
  }

  .sketch-preview img {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 10px;
  }

  .summary-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .title-row {
    align-items: stretch;
  }

  .page {
    position: relative;
    grid-template-rows: auto auto;
    padding: 16px;
  }

  .string-grid,
  .page-body {
    grid-template-columns: 1fr;
  }

  .structure {
    min-height: 260px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 16px;
  }

  .book {
    min-height: 0;
  }

  .book.has-pages {
    min-height: 980px;
  }

  .book.has-pages.has-source {
    min-height: 1740px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page {
    transition: opacity 120ms ease;
  }

  .page.turning {
    transform: none;
  }
}
