:root {
  --bg: #f5f6f8; --card: #fff; --text: #0f1419; --muted: #5b6573; --line: #e4e7ec; --field: #f0f2f5;
  --accent: #15803d; --accent-text: #fff; --warn: #b45309; --danger: #dc2626; --info: #2563eb;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light dark;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0d12; --card: #151922; --text: #e8ebf0; --muted: #9aa4b2; --line: #262c38; --field: #1d222d;
    --shadow: 0 1px 2px rgb(0 0 0 / .4); --accent: #22c55e; --accent-text: #04210f; --warn: #f59e0b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 .25rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.05rem; }
p { margin: .25rem 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .strong { font-weight: 600; } .warn-text { color: var(--warn); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: 0 1rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--field); cursor: pointer; font-weight: 550; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .6; cursor: progress; }
.linklike { background: none; border: 0; padding: 0; color: var(--warn); text-decoration: underline; cursor: pointer; text-align: left; font-weight: 550; }
label { display: grid; gap: .3rem; font-weight: 550; font-size: .9rem; }
label small { font-weight: 400; }
input:not([type=checkbox]):not([type=file]) { width: 100%; min-height: 44px; padding: 0 .8rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--field); font-weight: 400; font-size: 16px; }
input:invalid { border-color: var(--danger); }
.stack { display: grid; gap: .9rem; margin-top: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; } .wrap-row { flex-wrap: wrap; margin-top: .6rem; }
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .65rem; border-radius: 999px;
  background: var(--field); border: 1px solid var(--line); font-size: .8rem; white-space: nowrap; }
.pill.warn { background: #b45309; color: #fff; border: 0; cursor: pointer; min-height: 36px; font-weight: 600; }
.pill.on { background: color-mix(in srgb, var(--accent) 18%, var(--card)); border-color: var(--accent); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.ok .dot, .on .dot { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.bad .dot { background: var(--danger); }

/* switch: 44px hit area around the visible track */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: -8px -4px; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: color-mix(in srgb, var(--muted) 40%, var(--line)); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: .2s; }
.switch input:not(:checked) + span::after { background: color-mix(in srgb, var(--muted) 60%, var(--card)); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--info); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; } .switch input:disabled + span { opacity: .4; }
.switch.big { width: 64px; height: 36px; } .switch.big span::after { width: 30px; height: 30px; }
.switch.big input:checked + span::after { transform: translateX(28px); }

/* login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); display: grid; gap: 1rem; padding: 1.6rem; }
.error { color: var(--danger); font-size: .9rem; margin: 0; } .error:empty { display: none; }

/* header + alerts stick together, so a banner is never hidden under the header */
.sticky { position: sticky; top: 0; z-index: 5; }
.top { display: flex; align-items: center; gap: 1rem;
  padding: max(.7rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .7rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }
.tabs { display: flex; gap: .25rem; background: var(--field); border-radius: 10px; padding: 3px; margin-inline: auto; }
.tabs button { border: 0; background: none; min-height: 40px; padding: 0 .9rem; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--muted); }
.tabs button[aria-current=page] { background: color-mix(in srgb, var(--text) 12%, var(--card)); color: var(--text); box-shadow: var(--shadow); }
.health { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); display: grid; gap: 1rem; }
.tab { display: grid; gap: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.logout { justify-self: start; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: .5rem; }
  .top .brand span { display: none; }
  .health { margin-left: auto; }
  .tabs { order: 3; width: 100%; } .tabs button { flex: 1; }
  #activity-card { order: -1; } /* what just happened comes first on a phone */
}

/* trading card */
.trading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-width: 2px; }
.trading.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--card)); }
.trading h2 { font-size: 1.25rem; }

/* rules */
.exchange { margin-top: 1rem; }
.exchange h3 { margin: 0 0 .3rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.rule { display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.rule:first-of-type { border-top: 0; }
.rule .name { flex: 1; min-width: 0; font-size: .95rem; cursor: pointer; display: block; }
.rule .name small { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }
.rule.off .name { color: var(--muted); font-weight: 400; }
.rule:not(.off) .name { font-weight: 600; }
.rule input.usdt:not([type=checkbox]) { width: 84px; text-align: right; flex: none; }

/* activity */
.activity { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; }
.activity li { padding: .7rem 0; border-top: 1px solid var(--line); display: grid; gap: .35rem; }
.activity li:first-child { border-top: 0; }
.activity li.fresh { animation: fresh 2.5s ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--warn) 18%, transparent); } }
.meta { display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: baseline; font-size: .8rem; color: var(--muted); }
.meta strong { color: var(--text); font-size: .9rem; }
.headline { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { display: inline-flex; gap: .35rem; align-items: center; padding: .2rem .55rem; border-radius: 8px; font-size: .8rem;
  background: var(--field); border: 1px solid var(--line); }
.chip b { font-weight: 650; }
.chip.bought { background: color-mix(in srgb, var(--accent) 16%, var(--card)); border-color: var(--accent); }
.chip.sending { background: color-mix(in srgb, var(--warn) 16%, var(--card)); border-color: var(--warn); }
.chip.failed { background: color-mix(in srgb, var(--danger) 14%, var(--card)); border-color: var(--danger); }
.tag { font-size: .7rem; padding: .05rem .4rem; border-radius: 6px; background: var(--info); color: #fff; }
.empty { padding: 1.5rem 0; text-align: center; }

/* alerts */
.alerts { display: grid; gap: .5rem; max-width: 1100px; margin: 0 auto; padding: 0 1rem; max-height: 50dvh; overflow: auto; }
.alerts:not(:empty) { padding-block: .75rem; }
.alert { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem; border-radius: var(--radius); color: #fff;
  background: #b45309; box-shadow: 0 8px 30px rgb(0 0 0 / .25); animation: pulse 1s ease-in-out 4; }
.alert.bought { background: #15803d; animation: none; }
.alert.failed { background: var(--danger); animation: none; }
.alert.test { background: var(--info); }
.alert .msg { flex: 1; min-width: 0; } .alert strong { display: block; font-size: 1.25rem; }
.alert span { opacity: .95; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.alert button { background: rgb(255 255 255 / .22); border: 0; color: inherit; border-radius: 8px; min-height: 44px; padding: 0 .9rem; cursor: pointer; font-weight: 600; flex: none; }
@keyframes pulse { 50% { transform: scale(1.015); box-shadow: 0 8px 40px rgb(180 83 9 / .7); } }

.toast { position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  padding: .6rem 1rem; border-radius: 10px; background: var(--text); color: var(--bg); font-size: .9rem; box-shadow: var(--shadow); max-width: calc(100% - 2rem); }
.toast:empty { opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
