:root {
  --accent: #6E56F7;
  --accent-dark: #5940D9;
  --bg-page: #EEF0F4;
  --bg: #FFFFFF;
  --bg-soft: #F4F4F6;
  --bg-soft-hover: #E9E9ED;
  --text: #1B1B1F;
  --text-muted: #6A6A75;
  --border: #E4E4E9;
  --danger: #D0344C;
  --danger-solid: #D0344C; /* for solid buttons: white text sits on top, so this must stay dark
                              enough regardless of theme — kept separate from --danger, which
                              brightens in dark mode for its OWN use as text against the page bg */
  --success: #1E8E5A;
  --warn-bg: #FFF6E9;
  --warn-border: #F3D9A6;
  --warn-text: #8A6116;
  --danger-bg: #FDEEF0;
  --danger-border: #F3C0C9;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shell-width: 400px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  display: flex;
  justify-content: center;
}
.shell {
  width: var(--shell-width);
  max-width: 100vw;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.06);
  overflow-x: hidden;
}

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px 0;
}
.topbar .icon-btn { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand svg { width: 26px; height: 26px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg-soft); }

/* ── Onboarding ──────────────────────────────────────────────────────── */
.center-col {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 28px; text-align: center; gap: 8px;
}
.logo-mark { width: 96px; height: 96px; margin-bottom: 8px; }
.wordmark { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.05; }
.tagline { color: var(--text-muted); font-size: 15px; margin-top: 6px; margin-bottom: 24px; }
.stack { width: 100%; display: flex; flex-direction: column; gap: 12px; }

.btn {
  appearance: none; border: none; border-radius: 999px; padding: 15px 20px; font-size: 15px;
  font-weight: 600; cursor: pointer; text-align: center; transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { background: #B9B9C2; cursor: not-allowed; }
.btn-secondary { background: var(--bg-soft); color: var(--text); }
.btn-secondary:hover { background: var(--bg-soft-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger-solid); color: #fff; }
.btn-link { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 15px; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 999px; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.field {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 15px 16px; font-size: 15px; outline: none; background: var(--bg); color: var(--text);
}
.field:focus { border-color: var(--accent); }
.field-error { border-color: var(--danger); }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.field-hint.error { color: var(--danger); }
textarea.field { resize: none; min-height: 140px; font-family: inherit; line-height: 1.5; }
.label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; display: block; }

/* ── Screen scaffolding ──────────────────────────────────────────────── */
.screen { flex: 1; display: flex; flex-direction: column; padding: 0 20px 20px; overflow-y: auto; }
.screen-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 0 18px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.screen-title { font-size: 18px; font-weight: 700; flex: 1; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h1 { font-size: 26px; font-weight: 800; margin: 4px 0 10px; }
.p-muted { color: var(--text-muted); font-size: 14.5px; line-height: 1.5; }

/* ── Recovery phrase grid ────────────────────────────────────────────── */
.phrase-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.phrase-chip {
  display: flex; align-items: center; gap: 8px; background: var(--bg-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; font-weight: 600;
}
.phrase-chip .n { color: var(--text-muted); font-weight: 500; width: 18px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 9px 14px; font-size: 14px; font-weight: 600;
  background: var(--bg); cursor: pointer; user-select: none;
}
.chip.used { opacity: .35; pointer-events: none; }
.chip.picked { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.removable { cursor: pointer; }
.chip.removable:hover { opacity: .8; }
.picked-slots { display: flex; flex-wrap: wrap; gap: 8px; min-height: 46px; border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 8px; margin-bottom: 16px; }

/* ── Account chip / header on main screen ───────────────────────────── */
.acct-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 4px; }
.acct-name-btn { display: flex; align-items: center; gap: 4px; background: none; border: none; font-size: 17px; font-weight: 700; cursor: pointer; color: var(--text); }
.address-chip {
  display: inline-flex; align-items: center; gap: 8px; background: var(--bg-soft); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--text-muted); cursor: pointer;
}
.dot-stack { display: flex; }
.dot-stack span {
  width: 16px; height: 16px; border-radius: 50%; margin-left: -6px; border: 2px solid var(--bg-soft);
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.dot-stack span:first-child { margin-left: 0; }
.dot-stack span img { width: 8px; height: 8px; object-fit: contain; } /* see .chain-badge img comment — same inscribed-circle limit */

.balance-block { padding: 18px 16px 6px; }
.balance-usd { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.balance-change { font-size: 14px; margin-top: 4px; }
.balance-change.up { color: var(--success); }
.balance-change.down { color: var(--danger); }

.actions-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 16px; }
.action-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--bg-soft);
  border: none; border-radius: var(--radius-md); padding: 14px 4px; cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text);
}
.action-btn:hover { background: var(--bg-soft-hover); }
.action-btn svg { width: 20px; height: 20px; }

.tabs { display: flex; gap: 22px; padding: 4px 16px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 10px 0; font-size: 15px; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-color: var(--text); }

.token-list { display: flex; flex-direction: column; }
.token-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.token-row:hover { background: var(--bg-soft); }
.token-icon { width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 15px; background-size: cover; position: relative; overflow: visible; }
.token-icon-img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #fff; }
.chain-badge {
  position: absolute; bottom: -2px; right: -2px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--bg); background-color: #fff; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* A square image inscribed in this badge's circular clip has corners that poke past the circle —
   at 12px on this box's inscribed content circle, a 12x12 image's corners exceed the boundary by
   ~1.8px, cropping straight into off-center logo artwork (seen on e.g. Arbitrum's icon). Sizing the
   image well below the inscribed-square limit (~8.5px here) keeps the whole logo inside the circle
   instead of relying on the clip to save it. */
.chain-badge img { width: 8px; height: 8px; object-fit: contain; }
.token-main { flex: 1; min-width: 0; }
.token-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.token-name .sym { white-space: nowrap; }
.token-sub { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.token-values { text-align: right; flex-shrink: 0; }
.token-usd { font-weight: 600; font-size: 15px; }
.token-amt { color: var(--text-muted); font-size: 13px; }
/* Network pill — sits next to the token symbol so "USDT on Tron" vs "USDT on Ethereum" is
   unmistakable at a glance, independent of the tiny chain badge on the icon. */
.net-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 6px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-muted); font-size: 11.5px; font-weight: 600; white-space: nowrap;
  flex-shrink: 0; line-height: 1.4;
}
.net-pill i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.token-row:hover .net-pill, .list-row:hover .net-pill { background: var(--bg); }

/* Native <select> styled to match .field inputs (custom chevron, no OS default look). */
select.field {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236A6A75' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}

/* Inline token picker (Swap "You receive") — search field + scrollable result list. */
.picker { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--bg); }
.picker .search-field { margin: 0; border-radius: 0; background: var(--bg-soft); }
.picker-list { max-height: 260px; overflow-y: auto; }
.picker-list .token-row { padding: 10px 14px; }
.picker-list .token-icon { width: 32px; height: 32px; font-size: 13px; }
.picker-list .chain-badge { width: 14px; height: 14px; }
.picked-token { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); }
.picked-token .token-icon { width: 32px; height: 32px; font-size: 13px; }
.picked-token .chain-badge { width: 14px; height: 14px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 60px 20px; font-size: 14px; }
.list-section-label { padding: 14px 16px 6px; font-size: 12.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-row:hover { background: var(--bg-soft); }
.list-row:last-child { border-bottom: none; }

.search-field { display: flex; align-items: center; gap: 8px; background: var(--bg-soft); border-radius: 999px; padding: 12px 16px; margin-bottom: 14px; }
.search-field input { border: none; background: none; outline: none; flex: 1; font-size: 15px; color: var(--text); }

.bottom-bar { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

.overlay { position: absolute; inset: 0; background: rgba(20,20,25,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--bg); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 340px; text-align: center; }
.modal h3 { font-size: 19px; margin: 8px 0 12px; }
.modal p { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.toast {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 100; white-space: nowrap;
}

.row-between { display: flex; align-items: center; justify-content: space-between; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.filter-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; background: var(--bg); }
.filter-row { display: flex; justify-content: space-between; padding: 0 16px 10px; }

.account-menu { position: absolute; top: 60px; left: 16px; right: 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: 0 12px 30px rgba(0,0,0,0.15); z-index: 40; overflow: hidden; }
.account-menu .list-row { border-bottom: 1px solid var(--border); }
.account-menu .list-row:last-child { border-bottom: none; }

/* ── Accounts screen: wallets as collapsible groups, accounts as cards ─────── */
.wallet-group { margin: 0 -20px 6px; }
.wallet-head { display: flex; align-items: center; gap: 4px; padding: 10px 12px 6px 20px; }
.wallet-title { flex: 1; font-size: 15px; font-weight: 700; color: var(--text-muted); cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet-head .icon-btn { transition: transform .15s; }
.acct-item { border-top: 1px solid var(--border); }
.acct-item:last-of-type { border-bottom: 1px solid var(--border); }
.acct-item.active { background: var(--bg-soft); }
.acct-main { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 20px; cursor: pointer; }
.acct-main:hover { background: var(--bg-soft); }
.acct-avatar { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 17px; }
.acct-body { flex: 1; min-width: 0; }
.acct-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.acct-name > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-current { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); background: rgba(110,86,247,0.12); border-radius: 999px; padding: 2px 7px; flex-shrink: 0; }
.acct-addr-line { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.addr-toggle { width: 26px; height: 26px; border-radius: 8px; border: none; background: var(--bg-soft); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.acct-item.active .addr-toggle, .acct-main:hover .addr-toggle { background: var(--bg-soft-hover); }
.addr-toggle svg { transition: transform .15s; }
.addr-toggle.open svg { transform: rotate(180deg); }
.addr-chip-sm { display: inline-flex; align-items: center; gap: 5px; background: var(--bg-soft); border-radius: 8px; padding: 4px 9px; font-size: 12.5px; color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; cursor: pointer; }
.acct-item.active .addr-chip-sm, .acct-main:hover .addr-chip-sm { background: var(--bg-soft-hover); }
.acct-usd { font-weight: 600; font-size: 15px; white-space: nowrap; }
.kebab { width: 34px; height: 34px; border-radius: 10px; border: none; background: var(--bg-soft); color: var(--text); font-size: 18px; font-weight: 700; line-height: 1; cursor: pointer; flex-shrink: 0; }
.kebab:hover { background: var(--bg-soft-hover); }
.acct-addrs { padding: 0 12px 12px 72px; display: flex; flex-direction: column; gap: 4px; }
.acct-addr-row { display: flex; align-items: center; gap: 8px; }
.acct-addr-row .icon-btn { width: 28px; height: 28px; }
.acct-add { display: flex; align-items: center; gap: 10px; padding: 12px 20px; width: 100%; text-align: left; }
.acct-add svg { width: 26px; height: 26px; padding: 5px; border-radius: 8px; background: rgba(110,86,247,0.12); }
.kebab-menu { top: auto; }

/* ── Send form: "send to one of my accounts" picker ─────────────────────── */
.own-pick { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.own-pick-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 14px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; background: var(--bg-soft); user-select: none; }
.own-pick-head.has-pick { color: var(--accent); }
.own-pick-head svg { transition: transform .15s; flex-shrink: 0; }
.own-pick-head.collapsed svg { transform: rotate(-90deg); }
.own-pick-list { max-height: 220px; overflow-y: auto; }
.own-pick-wallet { padding: 8px 14px 2px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.own-pick-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; }
.own-pick-row:hover { background: var(--bg-soft); }
.own-pick-row.selected { background: rgba(110,86,247,0.08); }
.own-pick-row .token-name { font-size: 14px; }
.own-pick-check { visibility: hidden; display: inline-flex; }
.own-pick-row.selected .own-pick-check { visibility: visible; }

.address-popover {
  position: absolute; top: calc(100% + 8px); left: 0; width: 300px; max-width: 80vw;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0,0,0,0.18); z-index: 45; padding: 6px; cursor: default; text-align: left;
}
.address-popover .list-row { padding: 10px 8px; }
.address-popover .list-row .token-icon { width: 30px; height: 30px; font-size: 13px; }
.address-popover .token-main { flex: 1; }
.address-popover .token-name { font-size: 14px; }

.switch { position: relative; display: inline-block; width: 40px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-track { position: absolute; inset: 0; background: var(--bg-soft-hover); border-radius: 999px; transition: background .15s; cursor: pointer; }
.switch-track::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }

.qr-wrap { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; display: inline-block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; color: var(--text-muted); }

.warn-box { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: var(--radius-md); padding: 12px 14px; font-size: 13px; color: var(--warn-text); margin-bottom: 16px; }
.danger-box { background: var(--danger-bg); border: 1px solid var(--danger-border); border-radius: var(--radius-md); padding: 12px 14px; font-size: 13px; color: var(--danger); margin-bottom: 16px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #0F0F13; --bg: #1B1B22; --bg-soft: #26262F; --bg-soft-hover: #303039;
    --text: #F2F2F5; --text-muted: #9797A3; --border: #34343E;
    --danger: #FF6B81; --success: #3DDC84;
    --warn-bg: #3A2E14; --warn-border: #5C481F; --warn-text: #E8C468;
    --danger-bg: #3A1620; --danger-border: #5C2430;
  }
  .btn-primary { background: #fff; color: #000; }
  .btn-primary:hover { background: #e6e6e6; }
  .btn-primary:disabled { background: #4A4A55; color: #9797A3; }
  .token-icon-img { background: #2A2A33; }
  select.field { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239797A3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); }
}
