:root {
  --bg: #f3f7f1;
  --surface: #ffffff;
  --surface-alt: #eef5ef;
  --text: #13291c;
  --muted: #5b6d61;
  --line: #d5dfd7;
  --brand: #1c6b42;
  --brand-strong: #0f4527;
  --accent: #c5a64e;
  --accent-soft: #fbf4de;
  --blue: #0b68c7;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --success: #067647;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --shadow: 0 16px 40px rgba(15, 69, 39, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --focus: rgba(11, 104, 199, 0.26);
}

[data-theme="dark"] {
  --bg: #0d1511;
  --surface: #15201a;
  --surface-alt: #1a2921;
  --text: #eef8f1;
  --muted: #afc1b5;
  --line: #2a3c31;
  --brand: #49a06f;
  --brand-strong: #d8f4e1;
  --accent: #e4c05d;
  --accent-soft: #34290f;
  --blue: #7ab7ff;
  --danger: #f97066;
  --danger-soft: #3b1816;
  --success: #6ce9a6;
  --success-soft: #123121;
  --warning: #fdb022;
  --warning-soft: #35260e;
  --shadow: 0 22px 48px rgba(0, 0, 0, 0.34);
  --focus: rgba(122, 183, 255, 0.26);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(197, 166, 78, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(28, 107, 66, 0.05), transparent 22%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--brand-strong);
  border-radius: 12px;
  text-decoration: none;
  z-index: 30;
}

.skip-link:focus {
  top: 12px;
}

.app-shell {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #b8902e);
  color: var(--brand-strong);
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.brand-copy h1 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.45rem);
  line-height: 1.08;
}

.brand-copy p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-toggle,
.ghost-btn,
.primary-btn,
.secondary-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff;
  border-color: transparent;
}

.secondary-btn {
  background: var(--surface-alt);
}

.theme-toggle:hover,
.ghost-btn:hover,
.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 20px;
}

.hero-card,
.layout-card,
.result-card,
.history-card,
.info-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.hero-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 2vw, 2rem);
}

.hero-card p {
  margin: 0;
  color: var(--muted);
  max-width: 72ch;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.84rem;
}

.app-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}

.layout-card {
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title h3 {
  margin: 0;
  font-size: 1.1rem;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

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

.mode-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}

.mode-btn.is-active {
  border-color: var(--brand);
  background: rgba(28, 107, 66, 0.08);
}

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

.grid.two {
  grid-template-columns: 1fr;
}

.grid.three {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  font-weight: 700;
  font-size: 0.92rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  min-height: 120px;
  resize: vertical;
}

.field-help {
  color: var(--muted);
  font-size: 0.82rem;
}

.field-error {
  color: var(--danger);
  font-size: 0.82rem;
  min-height: 1em;
}

.quick-panel,
.advanced-panel {
  display: none;
}

.quick-panel.is-active,
.advanced-panel.is-active {
  display: block;
}

.is-hidden {
  display: none !important;
}

.progress-card {
  margin: 16px 0 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.progress-line {
  position: relative;
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: rgba(28, 107, 66, 0.12);
  margin-bottom: 14px;
}

.progress-line-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.28s ease;
}

.progress-steps {
  display: grid;
  gap: 10px;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

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

.progress-step span {
  color: var(--muted);
  font-size: 0.84rem;
}

.progress-step-index {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(28, 107, 66, 0.08);
  color: var(--brand-strong);
  font-weight: 800;
}

.progress-step.is-current {
  border-color: rgba(28, 107, 66, 0.28);
}

.progress-step.is-current .progress-step-index,
.progress-step.is-complete .progress-step-index {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff;
}

.formula-card {
  padding: 18px;
  background: linear-gradient(135deg, rgba(28, 107, 66, 0.08), rgba(197, 166, 78, 0.12));
  border: 1px solid rgba(28, 107, 66, 0.12);
  border-radius: var(--radius);
}

.formula-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.formula-top h4,
.result-head h3,
.history-card h3,
.info-card h3 {
  margin: 0;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.brand {
  background: rgba(28, 107, 66, 0.12);
  color: var(--brand-strong);
}

.badge.gold {
  background: var(--accent-soft);
  color: #946c05;
}

.badge.blue {
  background: rgba(11, 104, 199, 0.12);
  color: var(--blue);
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.badge.warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.formula-grid,
.summary-grid,
.prediction-grid,
.alternatives-grid,
.history-list,
.insight-grid {
  display: grid;
  gap: 12px;
}

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

.mini-stat,
.summary-item,
.alternative-card,
.history-item,
.prediction-item,
.insight-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface);
}

.mini-stat strong,
.summary-item strong,
.prediction-item strong {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}

.mini-stat span,
.summary-item span,
.prediction-item span {
  font-size: 1rem;
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.result-card,
.history-card,
.info-card {
  padding: 18px;
}

.result-card-animated {
  animation: resultLift 0.36s ease;
}

.result-head,
.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.aggregate-hero {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at top right, rgba(197, 166, 78, 0.18), transparent 28%),
    linear-gradient(135deg, rgba(28, 107, 66, 0.12), rgba(28, 107, 66, 0.04));
  border: 1px solid rgba(28, 107, 66, 0.12);
  margin-bottom: 16px;
}

.aggregate-value {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 900;
  line-height: 1;
}

.aggregate-caption {
  color: var(--muted);
}

.meter {
  display: grid;
  gap: 10px;
}

.meter-track {
  position: relative;
  overflow: hidden;
  height: 14px;
  border-radius: 999px;
  background: rgba(28, 107, 66, 0.12);
}

.meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: 999px;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.breakdown-table,
.steps-list,
.warnings-list {
  width: 100%;
}

.breakdown-table {
  border-collapse: collapse;
  margin-top: 6px;
}

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

.breakdown-table th {
  color: var(--muted);
  width: 44%;
  font-weight: 700;
}

.steps-list,
.warnings-list {
  margin: 0;
  padding-left: 18px;
}

.steps-list li + li,
.warnings-list li + li {
  margin-top: 8px;
}

.validation-banner,
.helper-banner {
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.validation-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.18);
}

.helper-banner {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid rgba(181, 71, 8, 0.18);
}

.alternative-card h4,
.insight-card h4 {
  margin: 0 0 8px;
}

.alt-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item {
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.history-item:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

.history-empty,
.result-empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

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

.ai-panel textarea {
  min-height: 110px;
}

.ai-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes resultLift {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (min-width: 760px) {
  .progress-steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

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

  .hero {
    grid-template-columns: 1.6fr 1fr;
  }

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

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

@media (min-width: 1024px) {
  .app-layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
    align-items: start;
  }

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