:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #faf9fc;
  --text: #17151b;
  --muted: #6f6b76;
  --line: #e5e2e9;
  --accent: #6f35d4;
  --accent-dark: #5421b1;
  --accent-soft: #f0e9ff;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --success: #087a55;
  --radius: 14px;
  --shadow: 0 18px 55px rgba(45, 35, 68, 0.09);
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 68px;
  padding: 0 clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 760; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: white; background: var(--accent); font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.save-state { color: var(--muted); font-size: 13px; }

.button { border: 0; border-radius: 10px; min-height: 42px; padding: 0 17px; font-weight: 680; transition: transform .15s ease, background .15s ease; white-space: nowrap; }
.button:active { transform: translateY(1px); }
.button-ghost { background: #f1eff4; color: #3b3740; }
.button-ghost:hover { background: #e8e5eb; }
.button-primary { width: 100%; background: var(--accent); color: white; margin-top: 18px; }
.button-primary:hover { background: var(--accent-dark); }
.button-save { align-self: end; background: var(--accent); color: white; }
.button-save:hover { background: var(--accent-dark); }

.page { max-width: 1460px; margin: 0 auto; padding: 42px clamp(18px, 4vw, 56px) 72px; }
.intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 460px); align-items: end; gap: 48px; margin-bottom: 34px; }
.kicker { margin: 0 0 9px; color: var(--accent); font-size: 13px; font-weight: 760; text-transform: uppercase; letter-spacing: .08em; }
h1 { margin: 0; font-size: clamp(34px, 4.5vw, 62px); line-height: .98; letter-spacing: -.055em; max-width: 880px; }
.intro-copy { margin: 0; color: var(--muted); line-height: 1.55; font-size: 16px; max-width: 48ch; }

.saved-calculations { margin-bottom: 24px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.saved-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.saved-heading .kicker { margin-bottom: 5px; }
.saved-heading h2 { margin: 0; font-size: 22px; letter-spacing: -.035em; }
.saved-heading > span { color: var(--muted); font-size: 12px; }
.save-calculation-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 12px; margin-top: 18px; }
.save-calculation-form .field label { margin-bottom: 6px; }
.saved-calculations-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.saved-empty { grid-column: 1 / -1; margin: 0; padding: 15px 0 2px; color: var(--muted); font-size: 13px; }
.saved-item { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.saved-item-head { display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 8px; align-items: start; }
.saved-load { min-width: 0; padding: 0; border: 0; background: transparent; color: var(--text); text-align: left; }
.saved-load strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.saved-load:hover strong { color: var(--accent-dark); }
.saved-delete { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: #efedf1; color: #716a78; font-size: 19px; line-height: 1; }
.saved-delete:hover { background: var(--danger-soft); color: var(--danger); }
.saved-item-category { min-height: 30px; margin: 8px 0 10px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.saved-item-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.saved-item-meta span { padding: 5px 7px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-dark); font-size: 10px; font-weight: 700; }
.saved-item-profit { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--line); }
.saved-item-profit span { color: var(--muted); font-size: 10px; }
.saved-item-profit strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.saved-item-profit.negative strong { color: var(--danger); }

.calculator-layout { display: grid; grid-template-columns: minmax(0, 1fr) 410px; gap: 24px; align-items: start; }
.form-stack { display: grid; gap: 16px; }
.form-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(20px, 3vw, 30px); }
.section-heading { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 26px; }
.section-heading h2, .breakdown h2, .price-guide h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.step { width: 34px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; font-weight: 800; }

.fields-grid { display: grid; gap: 18px; }
.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { min-width: 0; }
.field-wide { width: 100%; margin-bottom: 22px; }
.field label, .field legend { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 720; }
fieldset.field { border: 0; padding: 0; }
.field small { display: block; color: var(--muted); margin-top: 7px; line-height: 1.35; }

input, select {
  width: 100%;
  height: 46px;
  border: 1px solid #d8d4dd;
  border-radius: 10px;
  padding: 0 13px;
  background: white;
  color: var(--text);
  outline: none;
  transition: border .15s ease, box-shadow .15s ease;
}
input:hover, select:hover { border-color: #b8b1c2; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(111,53,212,.13); }
input::placeholder { color: #918c98; }
input[type="number"] { appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { appearance: none; }

.input-affix { position: relative; }
.input-affix input { padding-right: 50px; font-variant-numeric: tabular-nums; }
.input-affix span { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.discount-result { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 18px; padding: 14px 16px; border-radius: 11px; background: var(--accent-soft); }
.discount-result > div { display: flex; flex-direction: column; gap: 3px; }
.discount-result span { color: var(--accent-dark); font-size: 13px; font-weight: 740; }
.discount-result small { color: #756989; }
.discount-result strong { color: var(--accent-dark); font-size: 22px; letter-spacing: -.03em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.spp-panel { display: grid; grid-template-columns: 160px minmax(0, 1fr) auto; gap: 16px; align-items: end; margin-top: 10px; padding: 14px 16px; border: 1px solid #d9ccef; border-radius: 11px; background: #fbf9fe; }
.spp-panel .field { gap: 6px; }
.spp-copy { align-self: center; }
.spp-copy span { display: block; color: var(--text); font-size: 13px; font-weight: 760; }
.spp-copy small, .spp-copy em { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.spp-copy em { color: #6f35d4; font-style: normal; }
.spp-value { align-self: center; text-align: right; }
.spp-value strong { display: block; color: var(--accent-dark); font-size: 22px; letter-spacing: -.03em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.spp-value small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.search-wrap { position: relative; }
.search-wrap input { padding-right: 42px; }
.clear-search { position: absolute; right: 8px; top: 7px; width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; }
.category-field { position: relative; z-index: 5; }
.category-results { position: absolute; top: 76px; left: 0; right: 0; max-height: 320px; overflow: auto; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.category-option { width: 100%; border: 0; background: white; padding: 11px 12px; border-radius: 8px; text-align: left; color: var(--text); line-height: 1.35; }
.category-option:hover, .category-option.active { background: var(--accent-soft); }
.category-option strong { color: var(--accent-dark); font-weight: 760; }
.category-empty { padding: 18px; color: var(--muted); font-size: 14px; }
.category-meta { margin-top: 8px; min-height: 19px; color: var(--muted); font-size: 13px; }

.segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 5px; border-radius: 12px; background: #f2f0f4; }
.segment label { margin: 0; cursor: pointer; }
.segment input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segment span { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 9px; font-size: 14px; font-weight: 750; transition: background .15s ease, box-shadow .15s ease; }
.segment small { margin: 2px 0 0; color: var(--muted); font-size: 11px; font-weight: 500; }
.segment input:checked + span { background: white; color: var(--accent-dark); box-shadow: 0 2px 9px rgba(42,31,62,.1); }
.segment input:focus-visible + span { outline: 3px solid rgba(111,53,212,.2); }

.dimension-row { display: grid; grid-template-columns: minmax(110px,1fr) 18px minmax(110px,1fr) 18px minmax(110px,1fr) minmax(160px,.85fr); gap: 8px; align-items: end; }
.dimension-sign { align-self: center; margin-top: 21px; color: #aaa4b0; text-align: center; }
.volume-box { min-height: 76px; border-radius: 11px; padding: 10px 13px; background: var(--accent-soft); display: flex; flex-direction: column; justify-content: center; }
.volume-box span { color: var(--accent-dark); font-size: 11px; }
.volume-box strong { font-size: 21px; letter-spacing: -.03em; margin: 2px 0; }
.volume-box small { color: #6d6380; font-size: 10px; }

.check-row { display: flex; gap: 11px; align-items: flex-start; margin-top: 17px; padding: 13px; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.check-row span { display: flex; flex-direction: column; gap: 2px; }
.check-row strong { font-size: 13px; }
.check-row small { color: var(--muted); line-height: 1.4; }
.scheme-note { margin-top: 14px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.exchange-row { display: grid; grid-template-columns: 1fr minmax(180px, 230px); gap: 22px; align-items: center; margin-top: 18px; padding: 15px; border-radius: 11px; background: #f6f3fb; }
.exchange-row > div:first-child { display: flex; flex-direction: column; gap: 4px; }
.exchange-row strong { font-size: 13px; }
.exchange-row small { color: var(--muted); line-height: 1.4; }
.exchange-field label { color: var(--muted); font-size: 11px; }
.storage-panel { margin-top: 22px; padding: 20px; background: var(--surface-2); border-radius: 12px; }
.storage-panel[hidden] { display: none; }
.subheading { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 18px; }
.subheading h3 { margin: 0; font-size: 15px; }
.subheading span { color: var(--accent-dark); background: var(--accent-soft); border-radius: 7px; padding: 5px 8px; font-size: 11px; font-weight: 680; }
.target-field { max-width: calc(50% - 9px); margin-top: 18px; }

.results { position: sticky; top: 84px; background: #18151e; color: white; border-radius: var(--radius); padding: 22px; box-shadow: 0 24px 70px rgba(31,20,47,.2); }
.result-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #292530; border-radius: 9px; padding: 4px; }
.result-toggle button { border: 0; border-radius: 7px; min-height: 34px; background: transparent; color: #aaa3b5; font-size: 12px; font-weight: 700; }
.result-toggle button.active { background: #3a3443; color: white; }
.profit-hero { padding: 26px 2px 22px; }
.profit-hero > span { color: #b6afc0; font-size: 13px; }
.profit-hero strong { display: block; margin: 6px 0 10px; font-size: clamp(36px, 4vw, 48px); line-height: 1; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.profit-hero.negative strong { color: #ff8d84; }
.profit-meta { display: flex; gap: 8px; }
.profit-meta span { background: #2c2733; color: #d8d1df; border-radius: 7px; padding: 6px 8px; font-size: 11px; }
.result-warning { border-radius: 9px; padding: 11px 12px; margin: 0 0 14px; background: rgba(255,120,105,.14); color: #ffc2bc; font-size: 12px; line-height: 1.4; }
.result-summary { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid #37323f; border-bottom: 1px solid #37323f; }
.result-summary div { padding: 14px 0; }
.result-summary div:nth-child(even) { padding-left: 14px; border-left: 1px solid #37323f; }
.result-summary div:nth-child(n+3) { border-top: 1px solid #37323f; }
.result-summary span, .breakdown-row span, .price-guide span, .investment-guide span { display: block; color: #a9a2b2; font-size: 11px; }
.result-summary strong { display: block; margin-top: 4px; font-size: 15px; font-variant-numeric: tabular-nums; }
.expense-totals { margin-top: 18px; padding: 15px; border: 1px solid #3a3442; border-radius: 11px; }
.expense-totals h2 { margin: 0 0 10px; color: white; font-size: 14px; }
.expense-totals > div { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 9px 0; }
.expense-totals > div + div { border-top: 1px solid #302b37; }
.expense-totals span { color: #b5aebe; font-size: 11px; }
.expense-totals span small { display: block; margin-top: 3px; color: #766f7e; font-size: 9px; line-height: 1.35; }
.expense-totals strong { color: white; font-size: 12px; font-variant-numeric: tabular-nums; }
.expense-totals b { min-width: 48px; padding: 5px 7px; border-radius: 7px; background: #2c2733; color: #cbb7ef; text-align: center; font-size: 10px; font-variant-numeric: tabular-nums; }
.expense-totals .grand-total span, .expense-totals .grand-total strong { color: white; font-weight: 750; }
.expense-totals .grand-total b { background: var(--accent); color: white; }

.breakdown { padding: 22px 0 4px; }
.breakdown-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.breakdown-title h2, .price-guide h2 { color: white; font-size: 14px; }
.breakdown-title > span { color: #b8a3df; font-size: 11px; }
.breakdown-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: start; padding: 8px 0; }
.breakdown-row strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.breakdown-row span small { display: block; margin-top: 3px; color: #7f7889; font-size: 10px; line-height: 1.35; }
.breakdown-row.total { border-top: 1px solid #37323f; margin-top: 5px; padding-top: 13px; }
.breakdown-row.total span, .breakdown-row.total strong { color: white; }

.price-guide, .investment-guide { border: 1px solid #3a3442; border-radius: 11px; padding: 15px; margin-top: 15px; }
.price-guide h2, .investment-guide h2 { margin-bottom: 12px; }
.price-guide > div, .investment-guide > div:not(.markup-highlight) { display: flex; justify-content: space-between; gap: 14px; padding: 6px 0; }
.price-guide > div strong, .investment-guide > div strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.price-guide > small, .investment-guide > small { display: block; color: #8e8798; margin-top: 9px; line-height: 1.4; }
.markup-highlight { display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; align-items: center; padding: 11px 12px; margin-bottom: 7px; border-radius: 9px; background: #292431; }
.markup-highlight strong { grid-row: 1 / 3; grid-column: 2; color: #d1b8ff; font-size: 22px !important; letter-spacing: -.03em; }
.markup-highlight small { color: #81798a; font-size: 10px; }
.source-note { margin-top: 18px; padding-top: 17px; border-top: 1px solid #37323f; color: #8f8898; font-size: 11px; line-height: 1.5; }
.source-note strong { color: #c8c1d0; }
.source-note p { margin: 6px 0 10px; }
.source-note a { display: block; width: fit-content; color: #c4a7ff; margin-top: 4px; text-underline-offset: 2px; }
.source-note > span { display: block; margin-top: 10px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; background: #201b27; color: white; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 1100px) {
  .calculator-layout { grid-template-columns: minmax(0, 1fr) 360px; }
  .dimension-row { grid-template-columns: repeat(3, 1fr); }
  .dimension-sign { display: none; }
  .volume-box { grid-column: 1 / -1; min-height: 64px; }
  .saved-calculations-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .intro { grid-template-columns: 1fr; gap: 16px; }
  .calculator-layout { grid-template-columns: 1fr; }
  .results { position: static; }
  .three-cols { grid-template-columns: repeat(2, 1fr); }
  .saved-calculations-list { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .save-state { display: none; }
  .page { padding: 28px 14px 48px; }
  h1 { font-size: 38px; }
  .form-section { padding: 19px 16px; }
  .two-cols, .three-cols, .dimension-row { grid-template-columns: 1fr; }
  .exchange-row { grid-template-columns: 1fr; gap: 12px; }
  .target-field { max-width: none; }
  .segment { grid-template-columns: 1fr; }
  .segment span { min-height: 44px; flex-direction: row; gap: 7px; }
  .segment small { margin: 0; }
  .volume-box { grid-column: auto; }
  .results { padding: 19px 16px; }
  .discount-result { align-items: flex-start; }
  .discount-result strong { font-size: 19px; }
  .spp-panel { grid-template-columns: 1fr; align-items: stretch; }
  .spp-value { text-align: left; }
  .spp-value strong { font-size: 19px; }
  .expense-totals > div { grid-template-columns: minmax(0, 1fr) auto; }
  .expense-totals b { grid-column: 2; }
  .saved-calculations { padding: 17px 15px; }
  .saved-heading { align-items: flex-start; }
  .save-calculation-form { grid-template-columns: 1fr; }
  .button-save { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
