:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f8f9fc;
  --surface-strong: #eef2f8;
  --text: #172033;
  --text-muted: #68738a;
  --text-faint: #8a94a8;
  --border: #dfe4ee;
  --border-strong: #cbd3e2;
  --primary: #5b5ce2;
  --primary-dark: #4647c3;
  --primary-soft: #eeefff;
  --success: #168267;
  --success-soft: #e8f7f1;
  --warning: #b76e00;
  --warning-soft: #fff4dc;
  --danger: #c4455c;
  --danger-soft: #fff0f3;
  --shadow: 0 18px 50px rgba(29, 39, 68, 0.08);
  --radius: 18px;
  --radius-small: 12px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(91, 92, 226, 0.11), transparent 30rem),
    linear-gradient(180deg, #f8f9fd 0%, var(--bg) 100%);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

code {
  padding: 0.1em 0.35em;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0 28px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.hero__brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(145deg, var(--primary), #8182f2);
  border-radius: 15px;
  box-shadow: 0 10px 24px rgba(91, 92, 226, 0.28);
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 6px;
  font-size: 16px;
}

.hero__description {
  max-width: 390px;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.55;
  text-align: right;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 0.82fr) minmax(0, 1.6fr);
  gap: 22px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(211, 218, 232, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.composer {
  position: sticky;
  top: 22px;
  padding: 24px;
}

.panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.model-chip,
.model-badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 5px 9px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid #d9dbff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.field {
  display: block;
}

.field__label {
  display: block;
  margin-bottom: 9px;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

textarea {
  display: block;
  width: 100%;
  min-height: 210px;
  resize: vertical;
  padding: 15px 16px;
  color: var(--text);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

textarea::placeholder {
  color: var(--text-faint);
}

textarea:focus {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(91, 92, 226, 0.12);
}

.field-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 1px 20px;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.4;
}

.form-actions {
  display: flex;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 0 16px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 750;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button--primary {
  flex: 1;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  box-shadow: 0 8px 18px rgba(91, 92, 226, 0.22);
}

.button--primary:not(:disabled):hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 10px 22px rgba(91, 92, 226, 0.28);
}

.button--secondary {
  color: var(--text-muted);
  background: #ffffff;
  border: 1px solid var(--border-strong);
}

.button--secondary:not(:disabled):hover {
  color: var(--text);
  background: var(--surface-muted);
  border-color: #b9c2d4;
}

.button__spinner {
  display: none;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.is-loading .button__spinner {
  display: inline-block;
}

.composer__note {
  display: flex;
  gap: 9px;
  margin-top: 22px;
  padding: 12px 13px;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 11px;
}

.composer__note p {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
}

.note-icon {
  display: grid;
  flex: 0 0 18px;
  height: 18px;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
}

.results {
  min-height: 520px;
  padding: 24px;
}

.results__header {
  margin-bottom: 20px;
}

.empty-state,
.error-state {
  display: flex;
  min-height: 390px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.empty-state {
  color: var(--text-muted);
}

.empty-state__icon,
.error-state__icon {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  margin-bottom: 15px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 18px;
  font-size: 29px;
  font-weight: 800;
}

.empty-state p,
.error-state p {
  max-width: 330px;
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.55;
}

.error-state {
  justify-content: flex-start;
  padding: 60px 20px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #f4ccd5;
  border-radius: 14px;
}

.error-state__icon {
  color: var(--danger);
  background: #ffffff;
}

.error-state h3 {
  color: var(--danger);
}

.result-content {
  display: grid;
  gap: 18px;
}

.summary-grid,
.answer-grid {
  display: grid;
  gap: 12px;
}

.summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.answer-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.answer-card,
.usage-strip {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.metric-card,
.answer-card {
  padding: 16px;
}

.metric-card__top,
.answer-card__top,
.usage-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.metric-card__label,
.answer-card__label,
.usage-item__label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.metric-card__value {
  margin-bottom: 5px;
  font-size: 29px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.metric-card__caption,
.answer-card__caption,
.usage-item__value {
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.metric-card--urgent {
  background: linear-gradient(145deg, #f7f7ff, #eef0ff);
  border-color: #d9dbff;
}

.metric-card--urgent .metric-card__value {
  color: var(--primary-dark);
}

.metric-card--choice .metric-card__value,
.answer-card__choice {
  color: var(--success);
}

.metric-card--score .metric-card__value {
  color: var(--warning);
}

.progress-track {
  height: 8px;
  overflow: hidden;
  background: #e2e6ef;
  border-radius: 999px;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 350ms ease;
}

.progress-bar--success {
  background: var(--success);
}

.progress-bar--warning {
  background: #d98a00;
}

.progress-bar--danger {
  background: var(--danger);
}

.answer-card__title {
  margin-bottom: 4px;
  font-size: 15px;
}

.answer-card__choice {
  margin-bottom: 13px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.probability-list {
  display: grid;
  gap: 9px;
}

.probability-row {
  display: grid;
  grid-template-columns: minmax(70px, 0.8fr) minmax(70px, 1.2fr) 42px;
  align-items: center;
  gap: 9px;
  font-size: 11px;
}

.probability-row__label {
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.probability-row__value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.legend-list {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.legend-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 7px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.legend-row:last-child {
  border-bottom: 0;
}

.legend-row__key {
  color: var(--text);
  font-weight: 750;
}

.usage-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 15px 17px;
}

.usage-item + .usage-item {
  padding-left: 17px;
  border-left: 1px solid var(--border-strong);
}

.usage-item__value {
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.usage-item__label {
  margin-bottom: 4px;
}

.raw-response {
  overflow: hidden;
  background: #172033;
  border: 1px solid #2b3650;
  border-radius: 13px;
  color: #d9e0ee;
}

.raw-response summary {
  padding: 12px 15px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  list-style-position: inside;
}

.raw-response pre {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  padding: 15px;
  color: #c7d1e6;
  background: #111827;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.footer {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin-top: 24px;
  color: var(--text-faint);
  font-size: 11px;
}

.footer__separator {
  color: var(--border-strong);
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .composer {
    position: static;
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
    gap: 15px;
  }

  .hero__description {
    max-width: 560px;
    text-align: left;
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 25px;
  }

  .composer,
  .results {
    padding: 18px;
  }

  .summary-grid,
  .answer-grid,
  .usage-strip {
    grid-template-columns: 1fr;
  }

  .usage-item + .usage-item {
    padding-left: 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-strong);
    border-left: 0;
  }

  .form-actions {
    flex-direction: column;
  }

  .button--secondary {
    width: 100%;
  }

  .field-meta {
    display: block;
  }

  .field-meta span {
    display: block;
    margin-bottom: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
