:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e3e5ee;
  --text: #171a23;
  --muted: #646b7d;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eceafd;
  --ok: #15803d;
  --ok-soft: #e6f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --err: #c0262d;
  --err-soft: #fdecec;
  --check-a: #ffffff;
  --check-b: #e7e8ee;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 20, 40, .06), 0 4px 16px rgba(16, 20, 40, .05);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #20242f;
    --border: #2b303d;
    --text: #eceef4;
    --muted: #9aa1b2;
    --accent: #8b85ff;
    --accent-text: #0f1117;
    --accent-soft: #252347;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #33290f;
    --err: #f87171;
    --err-soft: #3a1a1c;
    --check-a: #2a2e39;
    --check-b: #222631;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* boot */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
  border: 0; cursor: pointer;
}
main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .78rem; font-weight: 600;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-current="page"] { color: var(--accent); }
@media (min-width: 900px) {
  .tabbar { max-width: 760px; margin: 0 auto; left: 0; right: 0; bottom: 16px;
            border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
            height: var(--tabbar-h); padding: 0; }
}

/* cards & sections */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card > h2 { margin-bottom: 4px; }
.card > .muted:first-of-type { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.field { margin-top: 14px; }
.field > label, .field > .label {
  display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px;
}
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }

/* banners */
.banner {
  border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: .92rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.err { background: var(--err-soft); color: var(--err); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

/* segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  flex: 1 1 auto; min-height: 40px; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: .9rem;
}
.seg button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}

/* switch */
/* label.switch beats `.field > label { display:block }` */
label.switch, .field > label.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer; margin: 0; font-weight: 600; font-size: .95rem;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  flex: none; width: 46px; height: 28px; border-radius: 999px; background: var(--border);
  position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* inputs */
input[type=text], input[type=email], input[type=number], select {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] {
  width: 52px; height: 44px; padding: 2px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* position grid */
.posgrid { display: grid; grid-template-columns: repeat(3, 48px); gap: 6px; }
.posgrid button {
  height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; display: grid; place-items: center;
}
.posgrid button::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); opacity: .5; }
.posgrid button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.posgrid button[aria-pressed="true"]::after { background: var(--accent); opacity: 1; }

/* presets */
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.preset {
  text-align: left; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2);
}
.preset strong { display: block; }
.preset span { font-size: .78rem; color: var(--muted); }
.preset[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* upload */
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px 16px;
  text-align: center; background: var(--surface); transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop > svg { width: 40px; height: 40px; color: var(--accent); margin: 0 auto 8px; }
.drop .row { justify-content: center; margin-top: 14px; }
.cost { margin-top: 12px; font-size: .88rem; color: var(--muted); }

/* results */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.result .img {
  aspect-ratio: 1; display: grid; place-items: center; position: relative;
  background-color: var(--check-a);
  background-image:
    linear-gradient(45deg, var(--check-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check-b) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.result .img img { max-height: 100%; object-fit: contain; }
.result .img .spinner { position: absolute; }
.result .img img.pending { opacity: .35; filter: grayscale(1); }
.result .meta { padding: 10px 12px; }
.result .name { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .status { font-size: .8rem; color: var(--muted); }
.result .status.err { color: var(--err); }
.result .actions { display: flex; gap: 6px; margin-top: 8px; }
.result .actions .btn { flex: 1; min-height: 38px; padding: 6px 10px; font-size: .85rem; }

/* logo preview */
.logo-preview {
  width: 120px; height: 72px; border-radius: 10px; border: 1px solid var(--border);
  display: grid; place-items: center; padding: 6px;
  background-color: var(--check-a);
  background-image: linear-gradient(45deg, var(--check-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check-b) 75%);
  background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}
.logo-preview img { max-height: 100%; object-fit: contain; }

/* account */
.credits-big { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.packages { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.package {
  border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: var(--surface-2);
  display: flex; flex-direction: column; gap: 6px;
}
.package .name { font-weight: 700; text-transform: capitalize; }
.package .credits { font-size: 1.4rem; font-weight: 800; }
.package .price { color: var(--muted); font-size: .88rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px;
           padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.login .box { width: 100%; max-width: 420px; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 18px; box-shadow: var(--shadow); }
.login h1 { font-size: 1.6rem; }
.login p { color: var(--muted); }
.login ul { text-align: left; color: var(--muted); padding-left: 20px; margin: 18px 0 24px; }
.tg-btn { background: #2aabee; border-color: #2aabee; color: #fff; padding: 12px 22px; font-size: 1rem; }
.tg-btn:hover { background: #229ed9; }
.tg-btn svg { width: 22px; height: 22px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: .9rem; transition: opacity .2s, transform .2s; z-index: 50;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); color: #fff; }

/* install banner + guide */
.install { border-color: var(--accent); background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.install-icon { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 20, .55);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.sheet {
  width: 100%; max-width: 440px; background: var(--surface); color: var(--text);
  border-radius: 20px; padding: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
@media (min-width: 700px) { .modal { align-items: center; } }
.icon-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1rem; }
.steps { list-style: none; padding: 0; margin: 16px 0; }
.steps li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.steps li:last-of-type { border-bottom: 0; }
.step-n {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.step-t { flex: 1; }
.step-i { flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); color: var(--accent); display: grid; place-items: center; }
.step-i svg { width: 20px; height: 20px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 1.5s !important; } }
