:root {
  color-scheme: light;
  --bg: #f5f3f9;
  --card: #fff;
  --text: #241933;
  --muted: #655b75;
  --subtle: #655b75;
  --line: #e4deec;
  --soft: #eee8f9;
  --accent: #6d39c4;
  --accent-text: #6531b7;
  --accent-hover: #5c2bac;
  --total: #281743;
  --total-end: #392259;
  --warning: #85400e;
  --warning-bg: #fff3e5;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-synthesis: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181220;
  --card: #231a2e;
  --text: #f8f3ff;
  --muted: #d1c5df;
  --subtle: #bbacce;
  --line: #443553;
  --soft: #382752;
  --accent: #7946d1;
  --accent-text: #d6baff;
  --accent-hover: #6835c0;
  --total: #34224d;
  --total-end: #493071;
  --warning: #ffd2a4;
  --warning-bg: #422a24;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, .segments input:focus-visible + span {
  outline: 2px solid var(--accent-text);
  outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
svg { width: 1.25rem; height: 1.25rem; flex: none; }

.app {
  width: min(100%, 454px);
  margin-inline: auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(21px, env(safe-area-inset-bottom));
}
.heading { display: flex; align-items: center; gap: 11px; margin-bottom: 23px; }
.heading h1 { font-size: clamp(20px, 5.9vw, 26px); letter-spacing: -.055em; font-weight: 750; }
.brand-icon {
  display: grid; flex: none; place-items: center; width: 40px; height: 40px;
  background: var(--accent); color: white; border-radius: 13px;
  box-shadow: 0 4px 10px #5b2bb62e;
}
.brand-icon svg { width: 24px; height: 24px; }
.demo-label {
  margin-left: auto; align-self: center; padding: 5px 9px; border-radius: 999px;
  background: var(--soft); color: var(--accent-text); font-size: 11px; font-weight: 700;
}
.section-label { display: block; padding: 0; color: var(--text); font-size: 13px; font-weight: 700; }
.search-box {
  display: flex; align-items: center; gap: 8px; margin-top: 7px; min-height: 54px;
  padding: 4px 5px 4px 11px; border: 1px solid var(--line); border-radius: 15px;
  background: var(--card);
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { color: var(--accent-text); }
.search-box input {
  width: 100%; min-width: 0; flex: auto; border: 0; padding: 5px 0; color: var(--text);
  background: transparent; font-size: 16px; outline: none;
}
.search-box input::placeholder { font-size: 13px; color: var(--muted); }
.search-button {
  flex: none; min-height: 44px; padding: 0 14px; border: 0; border-radius: 11px; font-size: 13px;
  background: var(--accent); color: white; font-weight: 700;
}
.search-button:hover { background: var(--accent-hover); }
.search-hint { margin: 5px 2px 0; color: var(--subtle); font-size: 11px; line-height: 1.45; }
.status-message, .calc-warning {
  margin-top: 10px; padding: 9px 12px; color: var(--warning);
  background: var(--warning-bg); border-radius: 11px; font-size: 13px; line-height: 1.4;
}
.matches { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.matches button {
  width: 100%; display: grid; text-align: left; gap: 4px; min-height: 52px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
}
.matches button:hover { border-color: var(--accent); }
.match-title { font-weight: 700; font-size: 14px; }
.match-meta { color: var(--muted); font-size: 12px; }

.product-card {
  display: flex; align-items: center; gap: 12px; min-height: 77px; margin-top: 15px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
}
.product-icon {
  display: grid; flex: none; place-items: center; width: 49px; height: 49px;
  color: var(--accent-text); background: var(--soft); border-radius: 11px;
}
.product-icon svg { width: 29px; height: 29px; }
.product-copy { min-width: 0; }
.product-copy h2 { font-size: 15px; line-height: 1.3; letter-spacing: -.015em; overflow-wrap: anywhere; }
#product-account { color: var(--accent-text); font-size: 12px; font-weight: 650; margin-top: 2px; }
#product-meta { color: var(--subtle); font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }

.scheme { min-width: 0; margin: 15px 0 0; border: 0; padding: 0; }
.segments {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px;
  margin-top: 6px; background: var(--soft); border-radius: 13px;
}
.segments label { position: relative; cursor: pointer; }
.segments input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.segments span {
  display: grid; min-height: 44px; place-items: center; color: var(--muted); border-radius: 10px;
  font-size: 13px; font-weight: 750; letter-spacing: .025em;
}
.segments input:checked + span { color: var(--accent-text); background: var(--card); box-shadow: 0 1px 4px #39225520; }

.fields { display: grid; gap: 7px; margin-top: 12px; }
.field {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 49px;
  padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-weight: 650; font-size: 14px;
}
.field:focus-within { border-color: var(--accent); }
.field input, .field output {
  width: 42%; min-width: 0; min-height: 44px; display: flex; align-items: center; justify-content: end;
  padding: 0; border: 0; background: transparent; outline: none;
  color: var(--text); font-size: 16px; font-weight: 750; text-align: right; font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--muted); font-weight: 450; }
.field input[aria-invalid="true"] { color: var(--warning); }
.field:has(input[aria-invalid="true"]) { border-color: var(--warning); }
.price-output output { color: var(--accent-text); }

.cost-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.cost {
  display: flex; flex-direction: column; align-items: flex-start; min-height: 89px;
  padding: 9px 11px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--card);
}
.cost-heading { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.cost-heading svg { width: 16px; height: 16px; color: var(--accent-text); }
.cost h3 { font-size: 12px; font-weight: 650; }
.cost-value {
  display: block; margin-top: 3px; font-size: clamp(16px, 4.6vw, 22px); font-weight: 750;
  letter-spacing: -.034em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.cost-meta, .factor-button { color: var(--subtle); font-size: 11px; }
.cost-meta { margin-top: 5px; }
.factor-button {
  display: flex; align-items: center; gap: 2px; margin: -1px 0 -4px -5px;
  min-height: 30px; margin-top: 0; padding: 0 4px 0 5px; border: 0; border-radius: 5px; background: none;
}
.factor-button:hover { color: var(--accent-text); }
.factor-button svg { width: 13px; height: 13px; color: var(--accent-text); }

.total {
  color: #fff; padding: 13px 14px 12px; margin-top: 10px; border-radius: 16px;
  background: linear-gradient(115deg, var(--total), var(--total-end));
  box-shadow: 0 5px 15px #2b1a4523;
}
.total-head, .total-foot { display: flex; gap: 4px 9px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.total-head h2 { font-size: 11px; font-weight: 750; letter-spacing: .095em; color: #e1d4f6; }
.share { padding: 4px 7px; border-radius: 999px; background: #ffffff22; color: #f2e7ff; font-size: 11px; font-weight: 650; }
.total-value {
  display: block; margin: 1px 0 6px; font-size: clamp(30px, 9.8vw, 43px); line-height: 1.04;
  font-weight: 760; letter-spacing: -.06em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.total-value.negative { color: #ffd1d9; }
.total-foot { color: #e1d4f6; font-size: 11px; line-height: 1.35; }
.mode-button {
  display: flex; justify-content: center; align-items: center; gap: 7px; min-height: 46px; width: 100%;
  margin-top: 9px; border: 1px solid var(--line); border-radius: 13px; background: var(--card);
  color: var(--accent-text); font-weight: 700; font-size: 13px;
}
.mode-button:hover { border-color: var(--accent); }
.mode-button svg { width: 18px; height: 18px; }
.freshness {
  display: flex; justify-content: center; align-items: center; gap: 5px;
  font-size: 11px; color: var(--subtle); margin-top: 11px; text-align: center; line-height: 1.4;
}
.freshness svg { width: 15px; height: 15px; }

dialog { max-width: min(380px, calc(100% - 32px)); padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); }
dialog::backdrop { background: #140b22a0; }
dialog h2 { margin-bottom: 13px; font-size: 17px; }
dialog .field { background: var(--bg); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 12px; }
.dialog-actions button:not(.search-button) { min-height: 44px; border: 0; border-radius: 9px; padding: 0 12px; background: var(--soft); color: var(--text); }
@media (max-width: 345px) {
  .app { padding-inline: 12px; }
  .heading { gap: 8px; }
  .search-button { padding-inline: 10px; }
  .search-box input::placeholder { font-size: 12px; }
  .cost { padding-inline: 8px; }
}
