:root {
  --bg: #0b0d12;
  --panel: #13161e;
  --panel-2: #1a1e28;
  --line: #262b38;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --accent: #8b7bff;
  --accent-2: #37d3c0;
  --ok: #3ecf8e;
  --warn: #f5b84b;
  --error: #ff6b6b;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image: radial-gradient(900px 420px at 50% -120px, rgba(139, 123, 255, 0.16), transparent 70%);
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 650; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.error { color: var(--error); }
.break { word-break: break-all; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-left));
  background: rgba(11, 13, 18, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.wallet { display: flex; align-items: center; gap: 8px; min-width: 0; }

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.container { max-width: 580px; margin: 0 auto; padding: 16px 12px 40px; }

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

.btn {
  font: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  transition: filter 0.15s, background 0.15s;
}
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6c5ce7); font-weight: 600; }
.btn-primary:not(:disabled):hover { filter: brightness(1.1); }
.btn-ghost { background: var(--panel-2); border-color: var(--line); }
.btn-ghost:not(:disabled):hover { background: #222736; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-action { width: 100%; margin-top: 16px; padding: 14px; font-size: 16px; }

input, select {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: #5d6477; }
select:disabled { opacity: 0.7; }

.search { display: flex; gap: 8px; }
.search input { font-family: var(--mono); font-size: 14px; }

.search-results { margin-top: 12px; display: grid; gap: 10px; }
.search-result { padding: 10px; background: var(--panel-2); border-radius: 10px; border: 1px solid var(--line); }
.search-result .chips { margin-top: 8px; }

.label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }

.token-head { display: flex; align-items: center; gap: 12px; }
.token-icon {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 700; font-size: 13px;
}
.token-title { min-width: 0; flex: 1; }
.token-symbol { font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.token-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }

.badge { padding: 3px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.badge-ok { background: rgba(62, 207, 142, 0.14); color: var(--ok); }
.badge-warn { background: rgba(245, 184, 75, 0.14); color: var(--warn); }

.notices, .warnings { margin: 12px 0 0; padding: 10px 12px 10px 28px; border-radius: 10px; background: rgba(245, 184, 75, 0.08); color: var(--warn); font-size: 13.5px; }
.notices li + li, .warnings li + li { margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13.5px;
}
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip:disabled { opacity: 0.45; cursor: not-allowed; }
.chip-selected { border-color: var(--accent); background: rgba(139, 123, 255, 0.18); }
.chip-registry::before { content: "●"; color: var(--ok); font-size: 9px; align-self: center; }
.chip-kind { color: var(--muted); font-size: 11.5px; }
.more-chips { margin-top: 6px; }
.more-chips summary { font-size: 13px; margin-bottom: 6px; }

.diagnostics { margin-top: 12px; font-size: 13.5px; }
.diagnostics summary, details summary { cursor: pointer; color: var(--muted); }
.diagnostics ul { margin: 8px 0 0; padding-left: 18px; }
.diagnostics li + li { margin-top: 6px; }

.route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.route .label { margin-top: 0; }
.route-box { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.route-chain { font-weight: 600; }
.route-swap {
  width: 40px; height: 40px; margin-bottom: 2px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
  transition: border-color .15s, transform .2s;
}
.route-swap:hover:not(:disabled) { border-color: var(--accent); transform: rotate(180deg); }
.route-swap:disabled { color: var(--muted); cursor: not-allowed; opacity: .5; }
.status-line { margin-top: 8px; }

.amount { display: flex; align-items: center; gap: 8px; }
.amount input { font-size: 18px; font-family: var(--mono); }

.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.inline-field .label { margin: 0; }
.slippage { width: 90px; text-align: right; }

.quote { margin-top: 16px; padding: 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); display: grid; gap: 6px; }
.quote-row { display: flex; justify-content: space-between; gap: 12px; }
.quote-row > span:last-child { text-align: right; font-family: var(--mono); font-size: 13.5px; }
.quote .warnings { margin-top: 4px; }

.approvals { margin-top: 12px; display: grid; gap: 8px; }
.approval { padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(139, 123, 255, 0.35); background: rgba(139, 123, 255, 0.08); }
.approval-blocked { border-color: rgba(255, 107, 107, 0.4); background: rgba(255, 107, 107, 0.08); }

.hint { margin-top: 8px; color: var(--muted); }
.hint.error { color: var(--error); }

.result { margin-top: 12px; padding: 12px; border-radius: 10px; background: rgba(62, 207, 142, 0.08); border: 1px solid rgba(62, 207, 142, 0.3); display: grid; gap: 6px; }
.result-links { display: flex; gap: 14px; flex-wrap: wrap; }

.log { margin: 10px 0 0; padding: 0; list-style: none; max-height: 260px; overflow-y: auto; font-size: 13px; display: grid; gap: 4px; }
.log li { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: baseline; }
.log li > span:last-child { overflow-wrap: anywhere; }
.log-time { color: #5d6477; font-family: var(--mono); font-size: 12px; }
.log-ok { color: var(--ok); }
.log-error { color: var(--error); }

.footnote { text-align: center; padding: 0 8px; }

.wallet-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  width: min(360px, calc(100vw - 32px));
  padding: 14px;
}
.wallet-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.wallet-list { display: grid; gap: 8px; }
.wallet-item { font: inherit; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; }
.wallet-item:hover { border-color: var(--accent); }
.wallet-item img, .wallet-icon-fallback { width: 28px; height: 28px; border-radius: 8px; }
.wallet-icon-fallback { display: grid; place-items: center; background: var(--line); font-size: 12px; }

@media (max-width: 480px) {
  h1 { font-size: 19px; }
  .card { padding: 14px 12px; }
  .route { grid-template-columns: 1fr; }
  .route-swap { justify-self: center; margin: 0; transform: rotate(90deg); }
  .route-swap:hover:not(:disabled) { transform: rotate(270deg); }
  .brand .muted { display: none; }
  .token-head { flex-wrap: wrap; }
  .token-meta { width: 100%; flex-direction: row; align-items: center; justify-content: flex-start; text-align: left; }
}
