:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #14202b;
  --muted: #5d6b78;
  --line: #e2e7ec;
  --brand: #0b5cad;
  --brand-ink: #ffffff;
  --brand-soft: #e6f0fa;
  --ok: #17803d;
  --ok-soft: #e5f5ea;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #182029;
    --text: #e8edf2;
    --muted: #9aa8b5;
    --line: #2a3542;
    --brand: #4a9be8;
    --brand-ink: #0b1724;
    --brand-soft: #16304a;
    --ok: #52c27a;
    --ok-soft: #173225;
    --warn: #f0b24a;
    --warn-soft: #3a2c12;
    --bad: #f27b70;
    --bad-soft: #3d1c19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 76px;
}

a { color: var(--brand); text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -0.01em; }
.brand span { color: var(--brand); }

.lang { display: flex; gap: 4px; }
.lang button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }

h1 { font-size: 24px; line-height: 1.25; margin: 8px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 24px 0 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.balance { background: var(--brand); color: var(--brand-ink); border: 0; }
.balance .label { opacity: 0.85; font-size: 14px; }
.balance .amount { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.balance .sub { opacity: 0.85; font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--brand);
  color: var(--brand-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--brand); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--line); min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.link { background: none; color: var(--brand); min-height: auto; padding: 0; font-weight: 500; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }

form p, .field { margin: 0 0 14px; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
input[type="text"], input[type="tel"], input[type="number"], input[type="file"], select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible { outline: 3px solid var(--brand-soft); outline-offset: 1px; border-color: var(--brand); }
input.code { letter-spacing: 0.4em; text-align: center; font-size: 26px; font-variant-numeric: tabular-nums; }

.errorlist { list-style: none; margin: 6px 0 0; padding: 0; color: var(--bad); font-size: 14px; }

.messages { list-style: none; margin: 0 0 12px; padding: 0; }
.messages li { padding: 12px 14px; border-radius: 12px; margin-bottom: 8px; font-size: 15px; background: var(--brand-soft); }
.messages .success { background: var(--ok-soft); color: var(--ok); }
.messages .error { background: var(--bad-soft); color: var(--bad); }
.messages .info { background: var(--warn-soft); color: var(--warn); font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.plus { color: var(--ok); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.presets button { min-height: 44px; padding: 0 2px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }

.ref { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: baseline; }
.ref dt { color: var(--muted); font-size: 14px; }
.ref dd { margin: 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

.hero { text-align: center; padding: 32px 8px 8px; }
.hero h1 { font-size: 28px; }
.hero p { color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 24px 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 44px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; color: var(--muted); font-size: 12px; }
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 600; }
.tabbar svg { width: 22px; height: 22px; }

.empty { text-align: center; padding: 24px 8px; color: var(--muted); }
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.file-pick { display: flex; align-items: center; gap: 12px; font-weight: 400; margin: 0; cursor: pointer; }
.file-pick .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
input[type="file"]:focus-visible + .file-pick .btn { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
.file-pick .btn { flex-shrink: 0; white-space: nowrap; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 30, 0.55); backdrop-filter: blur(2px); }
dialog.modal {
  position: fixed; z-index: 21; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 560px;
  border: 0; border-radius: 18px 18px 0 0; padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--text); box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
}
dialog.modal h2 { margin-top: 0; font-size: 20px; }
@media (min-width: 600px) {
  dialog.modal { inset: 50% 0 auto 0; transform: translateY(-50%); border-radius: 18px; }
}
