:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: rgba(255,255,255,.9);
  --surface-solid: #fff;
  --surface-soft: #edf7f5;
  --text: #13201e;
  --muted: #687875;
  --line: #dce7e4;
  --primary: #0f766e;
  --primary-strong: #0b5e58;
  --primary-soft: #d9f0ec;
  --danger: #b42318;
  --shadow: 0 14px 42px rgba(21,52,48,.08);
  --radius-lg: 22px;
  --radius-md: 15px;
  --radius-sm: 11px;
  font-size: 16px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1514;
  --surface: rgba(22,33,31,.92);
  --surface-solid: #16211f;
  --surface-soft: #1b2e2a;
  --text: #edf6f4;
  --muted: #9eb0ac;
  --line: #2b3c39;
  --primary: #45b8aa;
  --primary-strong: #2f968a;
  --primary-soft: #203d38;
  --danger: #ff8a80;
  --shadow: 0 14px 42px rgba(0,0,0,.27);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: .93rem;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(15,118,110,.1), transparent 25rem),
    radial-gradient(circle at 100% 15%, rgba(243,167,18,.07), transparent 20rem),
    var(--bg);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 32%, transparent);
  outline-offset: 2px;
}

.page-shell { width: min(1080px, calc(100% - 28px)); margin: 0 auto; }
.topbar { min-height: 66px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.brand span:last-child { display: grid; gap: 0; }
.brand strong { font-size: 1rem; }
.brand small { color: var(--muted); font-size: .78rem; }
.icon-button, .dialog-close { border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; }
.icon-button { width: 36px; height: 36px; border-radius: 11px; }
.icon-button svg, .dialog-close svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.moon-icon { display: none; }
:root[data-theme="dark"] .sun-icon { display: none; }
:root[data-theme="dark"] .moon-icon { display: block; }

.hero { max-width: 670px; padding: 34px 0 26px; }
.eyebrow { display: inline-block; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.hero h1 { margin: 8px 0 12px; max-width: 650px; font-size: 1.8rem; line-height: 1.15; letter-spacing: -.03em; }
.hero p { margin: 0; max-width: 650px; color: var(--muted); font-size: 1rem; line-height: 1.6; }

.simulator-grid { display: grid; grid-template-columns: minmax(0,1.12fr) minmax(330px,.88fr); gap: 18px; align-items: start; }
.card { border: 1px solid color-mix(in srgb,var(--line) 86%,transparent); background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(14px); border-radius: var(--radius-lg); }
.purchase-card { padding: clamp(17px,3vw,26px); }
.summary-card { padding: clamp(17px,3vw,24px); position: sticky; top: 14px; }

.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-soft); margin-bottom: 20px; }
.segment { min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: .9rem; font-weight: 760; cursor: pointer; }
.segment.is-active { color: var(--text); background: var(--surface-solid); box-shadow: 0 4px 14px rgba(17,53,49,.07); }
.two-columns, .context-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field-group { margin-bottom: 17px; min-width: 0; }
.compact-field { margin-bottom: 0; }
.full-row { grid-column: 1 / -1; }
.field-group label { display: block; margin-bottom: 7px; font-weight: 720; font-size: .9rem; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.label-row span { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap svg { position: absolute; left: 13px; width: 17px; fill: none; stroke: var(--muted); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.input-wrap input, .plain-input, .suffix-input, .amount-input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-solid); transition: border-color 160ms ease, box-shadow 160ms ease; }
.input-wrap input, .plain-input { height: 44px; color: var(--text); }
.input-wrap input { padding: 0 12px 0 39px; }
.plain-input { padding: 0 11px; }
.input-wrap input::placeholder { color: color-mix(in srgb,var(--muted) 65%,transparent); }
.input-wrap input:focus, .plain-input:focus, .suffix-input:focus-within, .amount-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb,var(--primary) 11%,transparent); outline: none; }
.amount-input { min-height: 61px; padding: 0 15px; display: flex; align-items: center; }
.amount-input input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--text); background: transparent; font-size: clamp(1.45rem,5vw,2rem); font-weight: 800; letter-spacing: -.035em; }
.amount-input span, .suffix-input span { color: var(--muted); font-weight: 750; font-size: .88rem; }
.suffix-input { min-height: 42px; padding: 0 11px; display: flex; align-items: center; gap: 8px; }
.suffix-input input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
.field-help, .field-error { min-height: 16px; margin: 6px 0 0; font-size: .78rem; line-height: 1.45; }
.field-help { color: var(--muted); }
.field-error { color: var(--danger); }

.quick-values { display: flex; gap: 6px; flex-wrap: wrap; margin: -2px 0 17px; }
.quick-values button, .inline-button { border: 1px solid var(--line); border-radius: 999px; background: var(--surface-solid); color: var(--muted); font-size: .8rem; font-weight: 720; cursor: pointer; }
.quick-values button { padding: 7px 10px; }
.quick-values button:hover, .quick-values button.is-selected, .inline-button:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.account-context { margin: 0 0 16px; border: 1px solid var(--line); border-radius: 13px; background: color-mix(in srgb,var(--surface-soft) 60%,transparent); }
.account-context summary { padding: 12px 13px; color: var(--text); font-size: .88rem; font-weight: 780; cursor: pointer; }
.context-grid { padding: 3px 13px 13px; }
.inline-button { margin-top: 6px; padding: 5px 8px; }
.check-row { display: flex !important; align-items: flex-start; gap: 8px; cursor: pointer; }
.check-row input { margin: 2px 0 0; accent-color: var(--primary); }
.check-row span { line-height: 1.35; }

.primary-button { width: 100%; min-height: 49px; border: 0; border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; background: linear-gradient(135deg,var(--primary),var(--primary-strong)); color: #fff; font-size: .93rem; font-weight: 800; cursor: pointer; box-shadow: 0 11px 24px rgba(15,118,110,.2); }
.primary-button:hover { transform: translateY(-1px); }
.primary-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.notice { margin-top: 16px; padding: 11px 12px; display: flex; align-items: flex-start; gap: 8px; border-radius: 12px; background: var(--surface-soft); color: var(--muted); }
.notice svg { width: 17px; flex: 0 0 auto; fill: none; stroke: var(--primary); stroke-width: 1.7; stroke-linecap: round; }
.notice p { margin: 0; font-size: .78rem; line-height: 1.5; }
.notice strong { color: var(--text); }

.summary-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.summary-heading h2, .section-heading h2 { margin: 3px 0 0; letter-spacing: -.03em; }
.summary-heading h2 { font-size: 1.22rem; }
.summary-heading small { display: block; margin-top: 4px; color: var(--muted); font-size: .76rem; }
.status-pill { padding: 6px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .72rem; font-weight: 800; }
.total-panel { margin: 17px 0 14px; padding: 16px; border-radius: 16px; background: linear-gradient(145deg,var(--primary),var(--primary-strong)); color: #fff; }
.total-panel span { display: block; opacity: .78; font-size: .78rem; }
.total-panel strong { display: block; margin-top: 5px; font-size: clamp(1.55rem,5vw,2.15rem); letter-spacing: -.045em; line-height: 1.1; overflow-wrap: anywhere; }
.total-panel small { display: block; margin-top: 6px; opacity: .82; font-size: .78rem; }
.breakdown, .tax-details dl, .receipt-summary { margin: 0; }
.breakdown > div, .tax-details dl > div, .receipt-summary > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.breakdown > div { padding: 9px 0; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); font-size: .82rem; }
dd { margin: 0; font-size: .84rem; font-weight: 780; text-align: right; }
.tax-details { margin-top: 4px; border-bottom: 1px solid var(--line); }
.tax-details summary { padding: 12px 0; color: var(--primary); font-size: .84rem; font-weight: 780; cursor: pointer; }
.tax-details dl { padding: 0 0 9px 10px; }
.tax-details dl > div { padding: 5px 0; align-items: flex-start; }
.tax-details dt, .tax-details dd { font-size: .76rem; }
.tax-details dt { max-width: 62%; }
.formula-note { margin-top: 14px; padding: 11px; border-radius: 11px; background: var(--surface-soft); }
.formula-note strong, .formula-note span { display: block; }
.formula-note strong { font-size: .84rem; }
.formula-note span { margin-top: 4px; color: var(--muted); font-size: .76rem; line-height: 1.5; }

.history-section { padding: 45px 0 22px; }
.section-heading { align-items: end; margin-bottom: 12px; }
.section-heading h2 { font-size: clamp(1.35rem,4vw,1.8rem); }
.text-button { border: 0; background: transparent; color: var(--primary); font-size: .85rem; font-weight: 780; cursor: pointer; }
.history-list { display: grid; gap: 8px; }
.empty-state { min-height: 105px; display: grid; place-items: center; align-content: center; gap: 6px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius-md); }
.empty-state svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.empty-state p { margin: 0; font-size: .84rem; }
.history-item { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.history-item strong, .history-item span { display: block; }
.history-item strong { font-size: .88rem; }
.history-item span, .history-item time { color: var(--muted); font-size: .75rem; }
.history-item .history-total { color: var(--text); font-weight: 800; font-size: .84rem; text-align: right; }
footer { padding: 25px 0 32px; color: var(--muted); text-align: center; font-size: .76rem; }

.receipt-dialog { width: min(470px,calc(100% - 20px)); border: 0; padding: 0; border-radius: 20px; background: transparent; color: var(--text); }
.receipt-dialog::backdrop { background: rgba(6,15,14,.62); backdrop-filter: blur(5px); }
.receipt-card { position: relative; padding: 27px; border-radius: 20px; background: var(--surface-solid); box-shadow: var(--shadow); text-align: center; }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 32px; height: 32px; border-radius: 10px; }
.success-icon { width: 48px; height: 48px; margin: 0 auto 13px; display: grid; place-items: center; border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.success-icon svg { width: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.receipt-card h2 { margin: 7px 0; font-size: 1.25rem; letter-spacing: -.03em; }
.receipt-card > p { margin: 0 auto; max-width: 320px; color: var(--muted); font-size: .82rem; line-height: 1.5; }
.token-box { margin: 17px 0; padding: 13px; border-radius: 12px; background: var(--surface-soft); }
.token-box span, .token-box strong { display: block; }
.token-box span { color: var(--muted); font-size: .75rem; }
.token-box strong { margin: 6px 0 9px; font-size: clamp(.88rem,4.3vw,1.1rem); letter-spacing: .08em; word-break: break-word; }
.token-box button { border: 0; background: transparent; color: var(--primary); font-size: .82rem; font-weight: 800; cursor: pointer; }
.receipt-summary { margin-bottom: 17px; text-align: left; }
.receipt-summary > div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.toast { position: fixed; left: 50%; bottom: 18px; z-index: 20; transform: translate(-50%,16px); padding: 10px 13px; border-radius: 10px; color: #fff; background: #17211f; font-size: .8rem; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: 180ms ease; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
.toast.is-visible { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 820px) {
  .simulator-grid { grid-template-columns: 1fr; }
  .summary-card { position: static; }
  .hero { padding-top: 24px; }
}

@media (max-width: 520px) {
  :root { font-size: 15px; }
  .page-shell { width: min(100% - 16px,1080px); }
  .topbar { min-height: 58px; }
  .icon-button { width: 32px; height: 32px; }
  .hero { padding: 23px 1px 20px; }
  .hero h1 { font-size: 1.8rem; }
  .hero p { font-size: .82rem; line-height: 1.45; }
  .purchase-card, .summary-card { border-radius: 17px; padding: 14px; }
  .two-columns, .context-grid { grid-template-columns: 1fr; gap: 10px; }
  .full-row { grid-column: auto; }
  .field-group { margin-bottom: 13px; }
  .quick-values { display: grid; grid-template-columns: 1fr 1fr; }
  .quick-values button { width: 100%; padding: 7px 5px; }
  .amount-input { min-height: 55px; }
  .amount-input input { font-size: 1.45rem; }
  .total-panel { padding: 14px; }
  .total-panel strong { font-size: 1.55rem; }
  .history-item { grid-template-columns: 1fr auto; }
  .history-item time { display: none; }
  .receipt-card { padding: 24px 16px 18px; }
}

@media (max-width: 340px) {
  :root { font-size: 13px; }
  .page-shell { width: min(100% - 10px,1080px); }
  .purchase-card, .summary-card { padding: 11px; border-radius: 14px; }
  .hero h1 { font-size: 1.8rem; }
  .brand small { display: none; }
  .quick-values { grid-template-columns: 1fr; }
  .summary-heading { gap: 8px; }
  .status-pill { display: none; }
  .breakdown > div, .tax-details dl > div { gap: 8px; }
  dt { max-width: 58%; }
}

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