:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #18212b;
  --muted: #647180;
  --line: #d9e0e6;
  --accent: #087f5b;
  --accent-strong: #066a4b;
  --accent-soft: #daf5ea;
  --danger: #bd2c36;
  --warning: #976500;
  --primary-text: #ffffff;
  --shadow: 0 12px 32px rgba(24, 33, 43, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] { color-scheme: light; }

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1318;
  --surface: #151d24;
  --surface-2: #1c2730;
  --text: #edf4f2;
  --muted: #98a8b3;
  --line: #2b3944;
  --accent: #4dd7a7;
  --accent-strong: #7ce4bf;
  --accent-soft: #153c32;
  --danger: #ff7c85;
  --warning: #f4c45e;
  --primary-text: #071812;
  --shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1318; --surface: #151d24; --surface-2: #1c2730; --text: #edf4f2;
    --muted: #98a8b3; --line: #2b3944; --accent: #4dd7a7; --accent-strong: #7ce4bf;
    --accent-soft: #153c32; --danger: #ff7c85; --warning: #f4c45e; --primary-text: #071812; --shadow: 0 12px 32px rgba(0,0,0,.28);
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
.app-header { max-width: 1180px; margin: auto; min-height: 76px; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; gap: 11px; align-items: center; text-decoration: none; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: var(--primary-text); background: var(--accent); font-weight: 900; font-size: 1.35rem; box-shadow: var(--shadow); }
.brand span:last-child { display: grid; }
.brand small { color: var(--muted); margin-top: 1px; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .88rem; }
.connection i { width: 8px; height: 8px; border-radius: 99px; background: var(--accent); }
.connection.offline i { background: var(--warning); }
.tabs { max-width: 1132px; margin: 0 auto 24px; padding: 5px; display: flex; gap: 3px; overflow-x: auto; border-radius: 14px; background: var(--surface-2); }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 650; text-decoration: none; border-radius: 10px; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
main { max-width: 1180px; margin: auto; padding: 0 24px 64px; outline: none; }
.page-head { margin: 0 0 20px; display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.page-head h1 { margin: 0; font-size: clamp(1.65rem, 4vw, 2.35rem); letter-spacing: -.04em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .9fr); gap: 20px; align-items: start; }
.calculator-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, .75fr); gap: 20px; align-items: start; }
.calculator-layout form > .card + .card { margin-top: 16px; }
.result-panel { position: sticky; top: 16px; }
.calc-section { padding: 22px; }
.section-title, .section-title > div, .inline-rate-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title { margin-bottom: 18px; }
.section-title h2 { margin: 0; }
.section-number { width: 28px; height: 28px; flex: 0 0 28px; display: grid; place-items: center; border-radius: 9px; color: var(--accent); background: var(--accent-soft); font-weight: 850; }
.field-note { font-weight: 450; }
.rate-stack { display: grid; gap: 14px; }
.inline-rate { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.inline-rate-head { margin-bottom: 13px; }
.inline-rate-head span, .same-rate span { color: var(--muted); font-size: .88rem; }
.same-rate { display: flex; justify-content: space-between; gap: 12px; }
.home-currency-row { padding-top: 4px; }
.saved-rates { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.saved-rates summary { cursor: pointer; font-weight: 750; }
.saved-rates .list { margin-top: 12px; }
.sticky-calculate { position: sticky; z-index: 3; bottom: 10px; display: flex; align-items: center; gap: 12px; margin: 16px 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.sticky-calculate .primary { min-width: 200px; }
.sticky-calculate span { color: var(--muted); font-size: .82rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin: 0 0 14px; letter-spacing: -.02em; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.full { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: var(--muted); font-size: .86rem; font-weight: 650; }
input, select { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; color: var(--text); background: var(--surface); }
input[readonly] { color: var(--muted); background: var(--surface-2); cursor: default; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 2px; }
button { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 10px; font-weight: 750; color: var(--text); background: var(--surface-2); }
button.primary { color: var(--primary-text); background: var(--accent); }
button.primary:hover { background: var(--accent-strong); }
button.secondary { border: 1px solid var(--line); background: transparent; }
button.danger { color: var(--danger); }
button.icon-button { padding: 0; min-height: 36px; width: 36px; font-size: 1.5rem; background: transparent; }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.hint, .empty { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.notice { border-radius: 12px; padding: 11px 13px; color: var(--warning); background: color-mix(in srgb, var(--warning) 11%, transparent); font-size: .9rem; }
.notice.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.persistent-notice { margin-bottom: 16px; }
.persistent-notice a { font-weight: 750; }
.result-hero { padding: 22px; color: white; background: linear-gradient(145deg, #0b7d5a, #075c57); border-radius: 15px; }
.result-hero small { opacity: .8; }
.result-hero strong { display: block; margin-top: 5px; font-size: clamp(1.7rem, 5vw, 2.8rem); letter-spacing: -.04em; }
.result-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; }
.result-meta span { display: grid; font-size: .88rem; opacity: .85; }
.result-meta b { font-size: 1rem; opacity: 1; }
.steps { margin: 18px 0 0; padding: 0; list-style: none; }
.steps li { position: relative; padding: 0 0 18px 28px; }
.steps li:not(:last-child)::before { content: ""; position: absolute; left: 8px; top: 18px; bottom: 2px; width: 2px; background: var(--line); }
.steps li::after { content: ""; position: absolute; left: 3px; top: 5px; width: 10px; height: 10px; border: 2px solid var(--accent); background: var(--surface); border-radius: 99px; }
.step-head { display: flex; justify-content: space-between; gap: 10px; }
.step-head span { color: var(--muted); font-size: .87rem; }
.step-detail { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.list { display: grid; gap: 12px; }
.list-item { display: flex; gap: 14px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.list-item-main { min-width: 0; }
.list-item h3 { margin: 0 0 4px; font-size: 1rem; }
.list-item p { margin: 0; color: var(--muted); font-size: .87rem; overflow-wrap: anywhere; }
.badge { display: inline-flex; margin-left: 6px; padding: 2px 7px; border-radius: 99px; color: var(--accent); background: var(--accent-soft); font-size: .7rem; font-weight: 750; vertical-align: 1px; }
.badge.warn { color: var(--warning); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border: 0; }
.setting-row h3 { margin: 0 0 4px; font-size: 1rem; }
.setting-row p { margin: 0; color: var(--muted); font-size: .87rem; }
.setting-row > :last-child { max-width: 240px; }
.stage-editor { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.stage-editor + .stage-editor { margin-top: 10px; }
.stage-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stage-actions { display: flex; gap: 3px; }
.stage-actions button { min-height: 32px; padding: 4px 9px; }
dialog { width: min(720px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
dialog form > header, dialog form > footer { position: sticky; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; background: var(--surface); }
dialog form > header { top: 0; border-bottom: 1px solid var(--line); }
dialog form > footer { bottom: 0; justify-content: end; gap: 9px; border-top: 1px solid var(--line); }
dialog h2 { margin: 0; }
#editor-body, #import-body { padding: 20px; overflow-y: auto; }
.toast { position: fixed; z-index: 10; right: 20px; bottom: 20px; max-width: min(380px, calc(100% - 40px)); padding: 12px 16px; color: white; background: #18212b; border-radius: 11px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.noscript { margin: 2rem; color: var(--danger); }

@media (max-width: 760px) {
  .app-header { padding: 12px 16px; }
  .brand small { display: none; }
  .tabs { margin: 0 12px 18px; }
  main { padding: 0 12px 88px; }
  .grid, .calculator-layout { grid-template-columns: 1fr; }
  .result-panel { position: static; }
  .page-head { align-items: start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .list-item, .setting-row { align-items: stretch; flex-direction: column; }
  .setting-row > :last-child { max-width: none; }
  .result-meta { flex-direction: column; }
  .section-title { align-items: start; }
  .section-title > .hint { display: none; }
  .inline-rate-head, .same-rate { align-items: start; flex-direction: column; }
  .sticky-calculate { bottom: 8px; align-items: stretch; flex-direction: column; }
  .sticky-calculate .primary { width: 100%; }
}
