/* Palette and type match the landing page (site/index.html) so the site and app read as one product. */
:root {
  --bg: #070A0F;
  --surface: #0E131C;
  --surface-2: #141B27;
  --border: #1F2838;
  --text: #EAF1FA;
  --muted: #9AA6BA;
  --faint: #8591A6; /* 5.4:1 on the darkest surface; #667085 measured 3.5 to 4.0:1, under WCAG AA for the 11-13px text it colours (8 Oct) */
  --border-input: #5B6B88; /* 3.2:1 on surface-2: the input boundary WCAG 1.4.11 asks for; --border is 1.2:1 */
  --accent: #35C6F4;
  --accent-2: #4C82FF;
  --accent-ink: #041018;
  --good: #3FE0A5;
  --warn: #F4C15A;
  --bad: #FF5D6C;
  --radius: 12px;
  --display: "Sora", system-ui, sans-serif;
  --body: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(60vw 40vw at 85% -10%, rgba(76, 130, 255, 0.12), transparent 60%),
    radial-gradient(50vw 40vw at 0% 0%, rgba(53, 198, 244, 0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

body.busy { cursor: progress; }
a { color: var(--accent); }

/* The hidden attribute must beat every display rule (.btn is inline-flex; without this a "hidden" button still renders). */
[hidden] { display: none !important; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* ---------- header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: rgba(7, 10, 15, 0.8);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.logo {
  position: relative; flex: none;
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(from 220deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: 0 0 14px rgba(53, 198, 244, 0.5);
}
.logo::after { content: ""; position: absolute; inset: 5px; border-radius: 3px; background: var(--bg); }
.tag {
  font-family: var(--body); font-size: 11px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px;
}

.wallet { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pill {
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
  font-size: 12px; color: var(--muted); background: var(--surface);
}
.pill.ok { color: var(--good); border-color: rgba(63, 224, 165, 0.4); }
/* The account pill: the connected wallet's own icon and name, then the address. One control, opens a menu. */
.pill.account { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-family: var(--body); color: var(--text); padding: 5px 10px 5px 7px; }
.pill.account:hover { border-color: var(--accent); }
.pill.account .addr { font-family: var(--mono); color: var(--muted); }
.wicon { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.wallet-opt { display: inline-flex; align-items: center; gap: 8px; }
.menu { position: fixed; z-index: 60; min-width: 190px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 12px 32px rgba(0, 0, 0, .35); display: grid; }
.menu > button, .menu > a { all: unset; display: block; box-sizing: border-box; width: 100%; padding: 9px 10px; border-radius: 8px; font: 500 13.5px/1.3 var(--body); color: var(--text); cursor: pointer; }
.menu > button:hover, .menu > a:hover, .menu > button:focus-visible, .menu > a:focus-visible { background: var(--surface-2); outline: none; }
.menu > .danger { color: var(--bad); }
@media (max-width: 640px) { .pill.account .wname { display: none; } }


/* ---------- layout */
.container { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; }

.notice {
  border: 1px solid rgba(244, 193, 90, 0.4);
  background: rgba(244, 193, 90, 0.08);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}
.notice code {
  display: block; margin: 4px 0; padding: 6px 10px; border-radius: 6px;
  background: var(--surface-2); font-family: var(--mono); font-size: 12px; overflow-x: auto;
}

/* Status strip: one line, reads as "live", never a wall of text. */
.strip {
  display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
  padding: 7px 14px 7px 12px; margin-bottom: 12px; border-radius: 999px;
  border: 1px solid rgba(53, 198, 244, 0.25); background: rgba(53, 198, 244, 0.06);
  font-size: 12.5px; color: var(--muted);
}
.strip strong { color: var(--text); }
.strip-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(63, 224, 165, 0.18); }

/* Fee chip: the brand promise in one line; details on tap. */
.fee-chip {
  margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: linear-gradient(90deg, rgba(53, 198, 244, 0.10), transparent 60%), var(--surface);
}
.fee-chip summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 9px 16px; font-size: 13px; color: var(--muted); }
.fee-chip summary::-webkit-details-marker { display: none; }
.fee-chip summary strong { font-family: var(--display); font-size: 22px; color: var(--accent); line-height: 1; }
.fee-more { margin-left: auto; color: var(--accent); font-weight: 700; font-size: 12px; }
.fee-chip[open] .fee-more { opacity: 0.6; }
.fee-chip p { margin: 0; padding: 0 16px 12px; font-size: 13px; color: var(--muted); max-width: 80ch; }

/* Transaction panel */
.txpanel {
  border: 1px solid rgba(53, 198, 244, 0.4); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  background: linear-gradient(180deg, rgba(53, 198, 244, 0.08), var(--surface));
  box-shadow: 0 12px 40px -18px rgba(53, 198, 244, 0.6);
}
.tx-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-family: var(--display); font-size: 15px; }
.tx-steps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.tx-steps li { display: flex; gap: 10px; align-items: flex-start; }
.tx-n { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.tx-steps li.active .tx-n { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); animation: pulse 1.2s infinite; }
.tx-steps li.done .tx-n { background: rgba(63, 224, 165, 0.18); color: var(--good); }
.tx-steps li.failed .tx-n { background: rgba(255, 93, 108, 0.18); color: var(--bad); }
.tx-l { font-weight: 700; }
.tx-steps li.pending .tx-l { color: var(--muted); }
.tx-steps .sub a { color: var(--accent); }
#txFoot { margin-top: 8px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(53, 198, 244, 0.5); } 50% { box-shadow: 0 0 0 6px rgba(53, 198, 244, 0); } }
@media (prefers-reduced-motion: reduce) { .tx-steps li.active .tx-n { animation: none; } }

.linkish { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; }
.linkish:hover { text-decoration: underline; }
textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; box-sizing: border-box; resize: vertical; }
textarea:focus { outline: 2px solid rgba(53, 198, 244, 0.5); outline-offset: 0; }

/* Guided journey */
.journey { margin: -4px 0 18px; }
.journey ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.journey li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.journey li:hover { border-color: var(--muted); transform: translateY(-1px); }
.j-n { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; font-weight: 700; background: var(--surface-2); }
.journey li.active { border-color: rgba(53, 198, 244, 0.6); color: var(--text); box-shadow: 0 0 0 3px rgba(53, 198, 244, 0.12); }
.journey li.active .j-n { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.journey li.done { border-color: rgba(63, 224, 165, 0.35); }
.journey li.done .j-n { background: rgba(63, 224, 165, 0.18); color: var(--good); }
.journey li.done .j-n::before { content: "✓"; }
.journey li.done .j-n span { display: none; }
.j-hint { margin-top: 8px; font-size: 13px; color: var(--muted); }
.j-hint b { color: var(--text); }

/* Loading shimmer + quiet hover life */
.sk { height: 14px; border-radius: 7px; margin: 10px 0; background: linear-gradient(90deg, var(--surface-2) 25%, rgba(255, 255, 255, 0.08) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.sk:nth-child(2) { width: 70%; }
.sk:nth-child(3) { width: 40%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.stat, .card { transition: border-color 0.15s; }
.stat:hover, .card:hover { border-color: rgba(53, 198, 244, 0.35); }
@media (prefers-reduced-motion: reduce) {
  .sk { animation: none; }
  #gaugeNeedle, .bar-fill, .journey li, .stat, .card { transition: none; }
}
@media (max-width: 760px) {
  .journey ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fee-more { margin-left: 0; }
}

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-family: var(--mono); font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 14px; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; transition: width 0.3s; }
.bar-fill.good { background: var(--good); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; background: none; border: 0; color: var(--muted); padding: 10px 14px; cursor: pointer;
  font: inherit; font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-new {
  font-size: 10px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent-ink); background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 999px; padding: 1px 6px;
}

.panel h2 { font-family: var(--display); font-size: 15px; margin: 18px 0 8px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 12px; }
.tier-tag { color: var(--accent); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.actions { text-align: right; }
.actions .btn + .btn { margin-left: 6px; }

.asset { display: flex; align-items: center; gap: 10px; }
.sym { font-weight: 700; }
.icon {
  --h: 30;
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 800; letter-spacing: -0.02em;
  background: hsl(var(--h) 60% 20%); color: hsl(var(--h) 90% 78%);
  border: 1px solid hsl(var(--h) 60% 34%);
}

/* ---------- controls */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: 8px 14px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--accent-ink);
  box-shadow: 0 6px 22px -8px rgba(53, 198, 244, 0.7);
}
.btn.primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 93, 108, 0.15); border-color: rgba(255, 93, 108, 0.5); color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus { outline: 2px solid rgba(53, 198, 244, 0.5); outline-offset: 0; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; transition: 0.2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--muted); transition: 0.2s; }
.switch input:checked + span { background: rgba(63, 224, 165, 0.25); border-color: var(--good); }
.switch input:checked + span::before { transform: translateX(16px); background: var(--good); }
.switch input:disabled + span { opacity: 0.4; cursor: not-allowed; }

/* ---------- dev tools */
.dev-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 6px; font-family: var(--display); font-size: 15px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.liq-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.liq-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.liq-form label.check { flex-direction: row; align-items: center; gap: 8px; }
.price-controls { display: flex; gap: 6px; }
.price-controls input { width: 140px; }

/* ---------- position outlook */
.outlook { margin-bottom: 8px; }
.outlook-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.gauge-card { text-align: center; }
.gauge { width: 100%; max-width: 220px; margin: 4px auto 0; display: block; }
.gauge path { fill: none; stroke-width: 12; stroke-linecap: butt; }
.gauge .g-track { stroke: var(--surface-2); }
.gauge .g-red { stroke: var(--bad); }
.gauge .g-amber { stroke: var(--warn); }
.gauge .g-green { stroke: var(--good); }
.gauge line { stroke: var(--text); stroke-width: 3; stroke-linecap: round; }
.gauge circle { fill: var(--text); }
#gaugeNeedle { transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.gauge-value { font-family: var(--mono); font-size: 26px; font-weight: 700; margin-top: -6px; }
.liq-list { display: grid; gap: 8px; margin-top: 8px; }
.liq-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 10px; align-items: baseline; font-size: 13px; }
.liq-row .sym { font-weight: 700; }
.liq-row .lp { font-family: var(--mono); font-weight: 700; text-align: right; }
.liq-row .sub { grid-column: 1 / -1; }
.whatif-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.whatif-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.whatif-pct { font-weight: 700; min-width: 44px; text-align: right; }
.whatif-out { display: grid; gap: 4px; margin-top: 10px; font-size: 13px; }
.whatif-out .row { display: flex; justify-content: space-between; gap: 10px; }
.whatif-out .row span:first-child { color: var(--muted); }
.whatif-out .row span:last-child { font-family: var(--mono); font-weight: 700; }
.costs { display: grid; gap: 6px; margin-top: 8px; font-size: 13px; }
.costs .row { display: flex; justify-content: space-between; gap: 10px; }
.costs .row span:first-child { color: var(--muted); }
.costs .row span:last-child { font-family: var(--mono); font-weight: 700; }
@media (max-width: 1000px) { .outlook-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .outlook-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- spend */
.spend-head { max-width: 62ch; margin: 6px 0 18px; }
.eyebrow { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); }
.spend-title { font-family: var(--display); font-weight: 800; font-size: clamp(20px, 3.4vw, 26px); line-height: 1.2; letter-spacing: -0.02em; margin: 8px 0 8px; }
.flow { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; counter-reset: none; }
.flow li {
  position: relative; display: grid; gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.flow li:nth-child(2) { border-color: rgba(53, 198, 244, 0.45); background: linear-gradient(180deg, rgba(53, 198, 244, 0.08), var(--surface)); }
.flow b { font-family: var(--display); font-size: 15px; }
.flow span:last-child { color: var(--muted); font-size: 13px; }
.flow-n {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); margin-bottom: 6px;
}
.spend-hint {
  border: 1px solid rgba(53, 198, 244, 0.3); background: rgba(53, 198, 244, 0.06);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px; margin-bottom: 20px; color: var(--text);
}
.spend-hint b { color: var(--accent); }
.spend-hint .muted { display: block; margin-top: 6px; }
.spend-note {
  border: 1px solid rgba(244, 193, 90, 0.35); background: rgba(244, 193, 90, 0.07);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px; margin-bottom: 20px;
}
.spend-note b { color: var(--warn); }
.wallet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.wallet-card {
  display: grid; gap: 4px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  transition: border-color 0.15s, transform 0.15s;
}
.wallet-card:hover { border-color: rgba(53, 198, 244, 0.5); transform: translateY(-2px); }
.wallet-card .w-name { font-family: var(--display); font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.wallet-card .w-name::after { content: "↗"; color: var(--muted); font-weight: 400; }
.wallet-card .w-desc { color: var(--muted); font-size: 13px; }
.wallet-card .w-meta { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.fine { color: var(--faint); font-size: 12px; margin: 16px 0 0; max-width: 80ch; }

/* ---------- wallet tab */
.wallet-empty { max-width: 64ch; padding: 8px 0 12px; }
.wallet-empty-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; }
.wallet-empty-actions .btn { padding: 12px 18px; }
.wallet-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.wallet-points li { padding-left: 22px; position: relative; color: var(--muted); font-size: 13.5px; }
.wallet-points li::before { content: "✓"; position: absolute; left: 0; color: var(--good); font-weight: 800; }
.wallet-points b { color: var(--text); }
.wallet-hero {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: center;
  padding: 22px; margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(53, 198, 244, 0.10), var(--surface) 55%);
}
.wallet-total { font-family: var(--mono); font-size: clamp(28px, 5vw, 40px); font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.wallet-addr { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.wallet-addr code { font-size: 12.5px; color: var(--muted); word-break: break-all; }
.wallet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.wallet-actions .btn { padding: 10px 18px; }
.wallet-qr { width: 132px; }
.qr { background: #fff; padding: 8px; border-radius: 12px; display: block; }
.qr svg { display: block; width: 100%; height: auto; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; margin: 14px 0 8px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.wallet-primary { width: 100%; text-align: left; justify-content: flex-start; padding: 14px 16px; }
.wallet-primary span { display: grid; gap: 2px; }
.wallet-primary small { font-weight: 500; font-size: 12px; opacity: 0.85; white-space: normal; }
#cbFine { margin-top: 8px; }
label.stack { display: grid; gap: 4px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
label.stack select, label.stack input { width: 100%; box-sizing: border-box; }
.receive-qr { width: min(240px, 100%); margin: 10px auto 14px; box-sizing: border-box; }
.pay-camera { position: relative; width: 100%; aspect-ratio: 1; max-height: 360px; border-radius: 12px; overflow: hidden; background: #000; margin: 6px 0 10px; }
.pay-camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.pay-frame { position: absolute; inset: 14%; border: 2px solid rgba(53, 198, 244, 0.9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35); pointer-events: none; }
.pay-paste { flex-wrap: nowrap; }
.pay-paste input { flex: 1; min-width: 0; }
#wPay .sub { font-weight: 500; }
.receive-addr { text-align: center; font-size: 13px; word-break: break-all; color: var(--muted); margin-bottom: 14px; }
@media (max-width: 760px) {
  .wallet-hero { grid-template-columns: minmax(0, 1fr); }
  .wallet-qr { width: 120px; }
  .wallet-actions .btn { flex: 1; }
}

/* ---------- modal */
dialog {
  width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; padding: 22px;
}
dialog::backdrop { background: rgba(3, 6, 12, 0.72); backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 14px; font-family: var(--display); }
.field { background: var(--surface-2); border: 1px solid var(--border-input); border-radius: 10px; padding: 10px 12px; }
.field-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.amount { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.amount input { flex: 1; min-width: 0; border: 0; background: transparent; font-family: var(--mono); font-size: 24px; padding: 2px 0; }
.amount input:focus { outline: none; }
.error { color: var(--bad); font-size: 12px; min-height: 18px; }
.fee-note { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.preview { margin: 14px 0; display: grid; gap: 6px; }
.preview .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.preview .row span:first-child { color: var(--muted); }
.preview .row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* The zero-gas panel prints the full address. A flex child defaults to min-width:auto, so a 42-character
   monospace string cannot shrink and forces the whole page to scroll sideways on the one screen a stuck
   tester is staring at. */
.tx-steps li > div { min-width: 0; }
.tx-steps code, .tx-steps .mono { overflow-wrap: anywhere; word-break: break-word; }

/* Terms gate. Wider than the other dialogs because it is read, not operated. */
#termsGate { width: min(540px, calc(100vw - 32px)); }
/* An ID selector outranks the phone media query below (media queries add no specificity), so the gate has to
   opt back into the full-width bottom sheet or it sits flush left with a 32px gap down the right edge. */
@media (max-width: 760px) { #termsGate { width: 100%; max-width: 100%; } }
/* Terms gate v3: product first, then a separated "Good to know" block so the risks are never read as pitch. */
#termsGate .tg-eyebrow { margin: 0 0 8px; font: 600 11px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
#termsGate .tg-title { margin: 0 0 8px; font: 700 23px/1.2 var(--display); letter-spacing: -.01em; text-wrap: balance; }
#termsGate .tg-lede { margin: 0 0 18px; color: var(--muted); font-size: 14.5px; line-height: 1.55; }
#termsGate .tg-points { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0 0 18px; }
#termsGate .tg-points > div { padding-left: 12px; border-left: 2px solid var(--accent); }
#termsGate .tg-points dt { font-weight: 600; font-size: 13.5px; margin: 0 0 2px; }
#termsGate .tg-points dd { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
#termsGate .tg-risk { border-top: 1px solid var(--border); padding: 14px 14px 2px; margin: 0 -4px; border-radius: 0 0 var(--radius) var(--radius); background: color-mix(in srgb, var(--warn) 6%, transparent); }
#termsGate .tg-risk h4 { margin: 0; font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--warn); }
#termsGate .tg-risk .gate-list { margin: 10px 0; }
@media (max-width: 560px) { #termsGate .tg-points { grid-template-columns: 1fr; } #termsGate .tg-title { font-size: 20px; } }
.gate-list { margin: 14px 0; padding-left: 18px; display: grid; gap: 9px; font-size: 13.5px; line-height: 1.55; color: var(--muted); }
.gate-list b { color: var(--text); }
.gate-check { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0 18px; font-size: 13px; line-height: 1.5; }
.gate-check input { margin-top: 3px; flex: 0 0 auto; width: 16px; height: 16px; accent-color: var(--accent); }

.wallet-links { display: grid; gap: 8px; margin: 14px 0 6px; }
.wallet-links .btn { width: 100%; padding: 12px 14px; justify-content: space-between; }
.wallet-links .btn::after { content: "→"; color: var(--muted); }

/* ---------- rate chooser & loan chips */
.rate-chooser { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border: 0; padding: 0; margin: 12px 0 0; }
.rate-chooser legend { float: left; margin-right: 6px; color: var(--muted); font-size: 12px; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span {
  display: inline-block; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.seg input:checked + span { border-color: var(--accent); color: var(--accent); background: rgba(53, 198, 244, 0.12); }
.seg input:focus-visible + span { outline: 2px solid rgba(53, 198, 244, 0.5); }
.seg input:disabled + span { opacity: 0.4; cursor: not-allowed; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); margin-right: 4px;
}
.chip.fixed { border-color: rgba(63, 224, 165, 0.5); color: var(--good); }

/* ---------- toasts */
#toasts {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); word-break: break-word;
}
.toast.success { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }

/* ---------- tablet */
@media (max-width: 900px) {
  .wallet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- phone */
@media (max-width: 760px) {
  .container { padding: 16px 16px 48px; }
  .topbar { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .wallet { width: 100%; }
  .wallet #connectBtn { flex: 1; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 18px; }
  .dev-grid, .liq-form, .flow { grid-template-columns: minmax(0, 1fr); }
  /* iOS zooms into any focused field under 16px — keep every input at 16px on phones. */
  input, select { font-size: 16px; }

  /* Bottom-sheet modals feel native on phones. */
  dialog {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0;
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }
  .modal-actions .btn { flex: 1; padding: 12px; }
}

@media (max-width: 640px) {
  /* Tables become stacked cards: each cell shows its column label from data-label. */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table-wrap table { min-width: 0; }
  .table-wrap thead { display: none; }
  .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; }
  .table-wrap tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; margin-bottom: 10px;
  }
  .table-wrap tbody tr:hover { background: var(--surface); }
  .table-wrap td { border: 0; padding: 5px 0; white-space: normal; text-align: right; }
  .table-wrap td[data-label]::before { content: attr(data-label); float: left; color: var(--muted); font-size: 12.5px; padding-top: 1px; }
  .table-wrap td::after { content: ""; display: block; clear: both; }
  .table-wrap td.cell-asset { text-align: left; padding-bottom: 8px; }
  .table-wrap td.actions {
    display: flex; gap: 8px; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--border);
  }
  .table-wrap td.actions::after { display: none; }
  .table-wrap td.actions .btn { flex: 1; padding: 10px; font-size: 13px; }
  .actions .btn + .btn { margin-left: 0; }
  .table-wrap td.empty { text-align: center; padding: 20px 0; }
  .price-controls { justify-content: flex-end; flex-wrap: wrap; }
  .price-controls input { width: 100%; }

  .wallet-grid { grid-template-columns: minmax(0, 1fr); }
  #toasts { left: 16px; right: 16px; max-width: none; }
}

/* ---------- internationalisation (frontend/i18n.js) */

/* Hides the page only for a visitor whose language is NOT the English already in the HTML, and only until the
   dictionary lands (i18n.js clears it, with a 900ms failsafe). An English visitor never sees this class, so the
   common case has zero added latency and nobody gets a flash of the wrong language. */
.i18n-pending body { visibility: hidden; }
/* This does NOT hide a dialog opened with showModal(): browsers give a modal dialog a `visibility: visible` of its
   own, so it shows inside a hidden page. A page that opens a dialog as it loads must wait for the hold to end first
   (the borrow page's risk gate does: pageShown() in router.js). Hiding dialogs here instead would open them with
   nothing focused, because a hidden control cannot take focus. */

/* The language swap. Opacity does not participate in layout, so a translation that is 40% longer than the
   English cannot shift anything while it fades — which is the usual reason a language switch feels broken. */
html { transition: opacity 140ms ease; }
html.i18n-swapping { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  html { transition: none; }
  html.i18n-swapping { opacity: 1; }
}

.lang-wrap { display: inline-flex; align-items: center; }
.lang {
  appearance: none;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: 12px; padding: 4px 26px 4px 10px; cursor: pointer;
  /* The chevron is inline SVG so it needs no extra request and no CSP exception. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239AA6BA' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.lang:hover { color: var(--text); border-color: var(--muted); }
.lang:focus-visible { outline: 2px solid rgba(53, 198, 244, 0.5); outline-offset: 1px; }
/* In RTL the chevron and the text padding both have to move to the other side. */
[dir="rtl"] .lang { padding: 4px 10px 4px 26px; background-position: left 9px center; }

/* Visible to screen readers, not on screen. The select has a title too, but a label is the accessible name
   assistive technology actually announces. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- right-to-left (Arabic today; Hebrew, Farsi and Urdu when translated)

   Setting dir="rtl" on <html> flips flex rows, text alignment and scrollbars for free. What it does NOT flip is
   a physical property written as left/right. These are the ones this stylesheet actually uses; everything else
   already uses gap, flex or logical properties. */
[dir="rtl"] .num,
[dir="rtl"] .preview .row span:last-child,
[dir="rtl"] .stat-value { text-align: left; }
[dir="rtl"] .modal-actions { justify-content: flex-start; }
[dir="rtl"] .fee-more { margin-left: 0; margin-right: auto; }
[dir="rtl"] .gate-list { padding-left: 0; padding-right: 18px; }
[dir="rtl"] .bar-fill { transform-origin: right center; }
/* Addresses, hashes and amounts stay left-to-right inside an RTL page: a hex string reversed is a different
   hex string, which would be a genuine safety problem rather than a cosmetic one. */
[dir="rtl"] .mono,
[dir="rtl"] code,
[dir="rtl"] .receive-addr,
[dir="rtl"] input[type="number"],
[dir="rtl"] #amountInput { direction: ltr; text-align: left; unicode-bidi: embed; }

/* Latin runs inside an RTL paragraph. A ticker, an address, an amount or a URL is a left-to-right island, and
   without isolation the bidi algorithm reorders the surrounding punctuation around it — the classic "the ticker
   ended up on the wrong side" bug. `isolate` scopes the run so neighbouring text is unaffected. */
[dir="rtl"] input,
[dir="rtl"] input::placeholder,
[dir="rtl"] textarea,
[dir="rtl"] select { unicode-bidi: isolate; }
/* For Latin text the app injects into translated prose, e.g. the network name in the testnet banner. */
[dir="ltr"] { unicode-bidi: isolate; }

/* The mainnet badge beside the build tag. Rendered only when the router is actually deployed (ROUTER_LIVE in
   app.js), so it can never assert something that is not true. */
.tag-live {
  background: rgba(63, 224, 165, .12);
  border-color: rgba(63, 224, 165, .35);
  color: var(--good);
  text-decoration: none;
  font-weight: 600;
}
.tag-live:hover { background: rgba(63, 224, 165, .2); }
/* "Testnet live": outlined, with a status dot, as on the landing page. Distinct from .tag-live on purpose. */
.tag-dot { display: inline-flex; align-items: center; gap: 6px; }
.tag-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(63, 224, 165, .18); }
