.calculator-shell {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(320px, 1.05fr) minmax(320px, 1fr);
  align-items: start;
}

.calculator-shell > [data-results-anchor] {
  grid-column: 1 / -1;
}

.calculator-panel {
  padding: 1.2rem;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.calculator-panel h2,
.calculator-panel h3,
.wizard-header h3,
.result-total,
.result-card strong {
  margin: 0;
  font-family: var(--font-heading);
  letter-spacing: -0.03em;
}

.calculator-panel h2 {
  font-size: 1.65rem;
}

.calculator-header {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.calculator-header p,
.wizard-header p,
.result-card span,
.field-help,
.result-note,
.map-help,
.visual-legend span,
.material-item span,
.share-message {
  color: var(--text-soft);
}

.mode-switch,
.input-toggle,
.unit-toggle,
.calc-tabs,
.wizard-controls,
.share-actions,
.chip-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.mode-switch button,
.input-toggle button,
.unit-toggle button,
.calc-tabs button,
.wizard-controls button,
.pill-button,
.share-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.36);
  color: var(--text);
  min-height: 42px;
  padding: 0.7rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  transition: 180ms ease;
}

:root[data-theme="dark"] .mode-switch button,
:root[data-theme="dark"] .input-toggle button,
:root[data-theme="dark"] .unit-toggle button,
:root[data-theme="dark"] .calc-tabs button,
:root[data-theme="dark"] .wizard-controls button,
:root[data-theme="dark"] .pill-button,
:root[data-theme="dark"] .share-chip {
  background: rgba(255, 255, 255, 0.04);
}

.mode-switch button[aria-pressed="true"],
.input-toggle button[aria-pressed="true"],
.unit-toggle button[aria-pressed="true"],
.calc-tabs button[aria-selected="true"],
.pill-button.is-active,
.share-chip.is-active {
  background: linear-gradient(135deg, rgba(26, 107, 60, 0.14), rgba(255, 107, 53, 0.14));
  border-color: var(--line-strong);
  color: var(--brand);
}

.field-grid {
  display: grid;
  gap: 1rem;
}

.field-row {
  display: grid;
  gap: 0.65rem;
}

.field-row.inline {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.field-row label,
.choice-group legend,
.wizard-choices legend {
  font-weight: 800;
}

.field-row input,
.field-row select,
.field-row textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--text);
  padding: 0.8rem 0.95rem;
}

:root[data-theme="dark"] .field-row input,
:root[data-theme="dark"] .field-row select,
:root[data-theme="dark"] .field-row textarea {
  background: rgba(255, 255, 255, 0.04);
}

.field-row input:focus-visible,
.field-row select:focus-visible,
.field-row textarea:focus-visible,
.choice-option:focus-within,
.wizard-choice:focus-within {
  outline: 2px solid rgba(255, 107, 53, 0.45);
  outline-offset: 2px;
}

.range-row {
  display: grid;
  gap: 0.45rem;
}

.range-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.92rem;
  color: var(--text-soft);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.choice-group,
.wizard-choices {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.7rem;
}

.choice-grid,
.wizard-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-option,
.wizard-choice {
  position: relative;
}

.choice-option input,
.wizard-choice input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.choice-option label,
.wizard-choice label {
  display: grid;
  gap: 0.3rem;
  padding: 0.9rem;
  min-height: 100%;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.36);
  transition: 180ms ease;
}

:root[data-theme="dark"] .choice-option label,
:root[data-theme="dark"] .wizard-choice label {
  background: rgba(255, 255, 255, 0.04);
}

.choice-option input:checked + label,
.wizard-choice input:checked + label {
  border-color: rgba(255, 107, 53, 0.44);
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.12), rgba(26, 107, 60, 0.12));
  transform: translateY(-1px);
}

.choice-option strong,
.wizard-choice strong {
  font-family: var(--font-heading);
  font-size: 1rem;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  width: 54px;
  height: 30px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(19, 48, 32, 0.12);
  transition: 180ms ease;
}

.toggle::after {
  content: "";
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  transition: transform 180ms ease;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-input:checked + .toggle {
  background: rgba(255, 107, 53, 0.38);
}

.toggle-input:checked + .toggle::after {
  transform: translateX(24px);
}

.visual-header,
.results-header,
.wizard-header,
.share-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.85rem;
}

.preview-frame {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--line);
  min-height: 340px;
  background:
    linear-gradient(180deg, rgba(129, 200, 245, 0.3), rgba(245, 240, 232, 0.15) 48%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.02), transparent),
    linear-gradient(180deg, rgba(48, 115, 67, 0.15) 76%, rgba(26, 107, 60, 0.28) 76%);
}

:root[data-theme="dark"] .preview-frame {
  background:
    linear-gradient(180deg, rgba(73, 118, 176, 0.34), rgba(24, 36, 29, 0.22) 48%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
    linear-gradient(180deg, rgba(50, 74, 56, 0.22) 76%, rgba(34, 61, 43, 0.44) 76%);
}

.preview-frame svg {
  width: 100%;
  height: 100%;
  min-height: 340px;
  display: block;
}

.visual-legend {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.visual-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.wizard-panel {
  margin-top: 0.8rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.wizard-step-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 34px;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: rgba(255, 107, 53, 0.08);
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 800;
}

.wizard-tip {
  padding: 0.9rem;
  border-radius: 18px;
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.18);
  color: var(--text);
}

.wizard-progress {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0.9rem 0 1rem;
}

.wizard-progress span {
  height: 6px;
  border-radius: 999px;
  background: rgba(19, 48, 32, 0.12);
}

.wizard-progress span.is-active {
  background: linear-gradient(90deg, var(--accent), var(--brand));
}

.result-stack {
  display: grid;
  gap: 0.9rem;
}

.result-highlight {
  padding: 1.1rem;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(26, 107, 60, 0.14), rgba(255, 107, 53, 0.12));
  border: 1px solid var(--line);
}

.result-highlight .label {
  color: var(--text-soft);
  font-size: 0.88rem;
}

.result-total {
  font-size: clamp(2rem, 4vw, 3rem);
  margin-top: 0.35rem;
}

.result-range {
  color: var(--text-soft);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.result-card {
  padding: 0.95rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid var(--line);
  display: grid;
  gap: 0.25rem;
}

:root[data-theme="dark"] .result-card {
  background: rgba(255, 255, 255, 0.04);
}

.result-card strong {
  font-size: 1.3rem;
}

.materials-list {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.8rem;
}

.material-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.28);
}

:root[data-theme="dark"] .material-item {
  background: rgba(255, 255, 255, 0.03);
}

.material-item strong {
  display: block;
}

.cost-bars {
  display: grid;
  gap: 0.65rem;
}

.cost-bar {
  display: grid;
  gap: 0.3rem;
}

.cost-bar-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
}

.cost-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(19, 48, 32, 0.1);
  overflow: hidden;
}

.cost-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 360ms ease;
}

.chart-wrap {
  min-height: 280px;
  border-radius: 22px;
  border: 1px solid var(--line);
  padding: 1rem;
  background: rgba(255, 255, 255, 0.24);
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

:root[data-theme="dark"] .chart-wrap {
  background: rgba(255, 255, 255, 0.03);
}

.map-panel {
  display: grid;
  gap: 0.8rem;
}

.map-canvas {
  min-height: 280px;
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.share-panel {
  display: grid;
  gap: 0.8rem;
}

.share-output {
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 0.8rem 0.95rem;
  background: rgba(255, 255, 255, 0.24);
  color: var(--text-soft);
  word-break: break-all;
}

:root[data-theme="dark"] .share-output {
  background: rgba(255, 255, 255, 0.03);
}

.advisor-panel {
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.26);
}

:root[data-theme="dark"] .advisor-panel {
  background: rgba(255, 255, 255, 0.03);
}

.advisor-list {
  display: grid;
  gap: 0.75rem;
}

.advisor-item {
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.32);
}

:root[data-theme="dark"] .advisor-item {
  background: rgba(255, 255, 255, 0.04);
}

.advisor-question {
  display: block;
  margin-bottom: 0.3rem;
  font-family: var(--font-heading);
  font-size: 1rem;
}

.advisor-answer {
  margin: 0;
  color: var(--text-soft);
}

.mobile-panel-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin-bottom: 0.9rem;
  padding: 0.72rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.36);
  color: var(--text);
  font-weight: 700;
}

:root[data-theme="dark"] .mobile-panel-toggle {
  background: rgba(255, 255, 255, 0.04);
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  display: grid;
  gap: 0.2rem;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: rgba(17, 39, 27, 0.92);
  color: #f4faf6;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.calculator-inline {
  margin-top: 1.3rem;
}

@media (max-width: 1024px) {
  .calculator-shell {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .calculator-shell,
  .choice-grid,
  .wizard-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .mobile-panel-toggle {
    display: inline-flex;
  }

  .calculator-panel.is-collapsed .preview-frame,
  .calculator-panel.is-collapsed .visual-legend,
  .calculator-panel.is-collapsed [data-visualizer-note] {
    display: none;
  }

  .preview-frame,
  .preview-frame svg {
    min-height: 280px;
  }

  .wizard-progress {
    grid-template-columns: repeat(5, 1fr);
  }

  .mode-switch,
  .input-toggle,
  .unit-toggle,
  .calc-tabs,
  .wizard-controls,
  .share-actions,
  .map-actions {
    flex-direction: column;
  }
}
