:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --ink: #17212b;
  --muted: #5f6c76;
  --line: #d9e3e1;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warn: #b45309;
  --good: #047857;
  --shadow: 0 18px 46px rgba(23, 33, 43, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px clamp(16px, 3vw, 32px);
  background: rgba(255, 255, 255, 0.93);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand,
.secondary-action {
  color: inherit;
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 850;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 40px;
  font-weight: 850;
}

.primary-action,
.secondary-action {
  padding: 0 14px;
  font-weight: 780;
}

.primary-action {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.studio {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 20px;
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 20px clamp(12px, 2vw, 28px) 32px;
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-block,
.results-panel,
.metrics-grid article,
.detail-card,
.empty-state,
.option-card,
.trace-step {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-block {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.panel-block h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2vw, 2.1rem);
  line-height: 1.05;
}

.panel-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.field-label,
label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

.number-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.number-with-unit input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 0;
  color: var(--ink);
}

.number-with-unit span {
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 780;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.segmented.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button,
.tabs button,
.perf-toggle {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 780;
}

.segmented button.is-active,
.tabs button.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.perf-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
}

.perf-toggle span {
  color: var(--muted);
}

.performance-panel {
  display: none;
}

.performance-panel.is-open {
  display: block;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.inline-result {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 760;
  line-height: 1.45;
}

.results-panel {
  min-height: calc(100vh - 124px);
  padding: clamp(16px, 2.2vw, 26px);
  box-shadow: var(--shadow);
}

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.results-header h2 {
  margin: 4px 0 6px;
  font-size: clamp(1.65rem, 2.35vw, 2.5rem);
  line-height: 1.04;
}

.results-header p {
  margin: 0;
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.status-pill.is-good {
  background: #ecfdf5;
  color: var(--good);
}

.status-pill.is-warning {
  background: #fff7ed;
  color: var(--warn);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metrics-grid article {
  min-height: 112px;
  padding: 14px;
}

.metrics-grid span,
.metrics-grid small {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.metrics-grid strong {
  display: block;
  margin: 8px 0;
  font-size: clamp(1.2rem, 1.75vw, 1.7rem);
  line-height: 1.1;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab-panel {
  padding-top: 18px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 28px;
  text-align: center;
}

.empty-state span {
  color: var(--muted);
}

.option-grid {
  display: grid;
  gap: 12px;
}

.option-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(7, minmax(78px, auto));
  gap: 10px;
  align-items: center;
  padding: 14px;
}

.option-card.is-selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.option-title strong,
.option-title span,
.metric-cell strong,
.metric-cell span {
  display: block;
}

.option-title span,
.metric-cell span {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-cell strong {
  margin-top: 2px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 16px;
}

.detail-card {
  padding: 16px;
}

.detail-card h3,
.detail-card h4 {
  margin: 0 0 8px;
}

.detail-card p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.55;
}

.stat-list {
  display: grid;
  gap: 10px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stat span {
  color: var(--muted);
}

.stat strong {
  text-align: right;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.report-box,
.json-box,
.doc-list,
.settings-box {
  padding: 14px;
  border-radius: 8px;
  background: #fbfcfd;
  border: 1px solid var(--line);
}

.json-box {
  max-height: 460px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.trace-list {
  display: grid;
  gap: 10px;
}

.trace-step {
  padding: 12px;
}

.trace-step strong,
.trace-step span {
  display: block;
}

.trace-step span {
  margin-top: 4px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

@media (max-width: 1120px) {
  .studio,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .results-panel {
    min-height: auto;
  }

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

  .option-card {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .option-title {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .two-col,
  .metrics-grid,
  .option-card {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    display: grid;
  }

  .icon-button,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .studio {
    padding-inline: 10px;
  }

  .results-header {
    flex-direction: column;
  }
}
