:root {
  --bg: #f4f6f8;
  --bg-elev: #ffffff;
  --bg-sunken: #eceff3;
  --bg-hover: #f0f3f6;
  --border: #d7dde3;
  --border-strong: #b9c2cc;
  --fg: #141b22;
  --fg-muted: #56626f;
  --fg-faint: #8a95a1;
  --accent: #0b8a55;
  --accent-soft: rgba(11, 138, 85, 0.1);
  --accent-fg: #ffffff;
  --up: #0b8a55;
  --down: #cc2f4a;
  --warn: #a86400;
  --warn-soft: rgba(168, 100, 0, 0.1);
  --info: #0b69c7;
  --grid-dot: rgba(20, 27, 34, 0.06);
  --shadow: 0 1px 2px rgba(20, 27, 34, 0.06);
  --glow: none;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07090c;
    --bg-elev: #0d1117;
    --bg-sunken: #0a0d12;
    --bg-hover: #121821;
    --border: #1b232d;
    --border-strong: #2a3643;
    --fg: #d4dde6;
    --fg-muted: #7c8997;
    --fg-faint: #4d5966;
    --accent: #3ee08f;
    --accent-soft: rgba(62, 224, 143, 0.1);
    --accent-fg: #03130a;
    --up: #3ee08f;
    --down: #ff5f7e;
    --warn: #ffb454;
    --warn-soft: rgba(255, 180, 84, 0.1);
    --info: #59c2ff;
    --grid-dot: rgba(212, 221, 230, 0.045);
    --shadow: none;
    --glow: 0 0 14px rgba(62, 224, 143, 0.28);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #07090c;
  --bg-elev: #0d1117;
  --bg-sunken: #0a0d12;
  --bg-hover: #121821;
  --border: #1b232d;
  --border-strong: #2a3643;
  --fg: #d4dde6;
  --fg-muted: #7c8997;
  --fg-faint: #4d5966;
  --accent: #3ee08f;
  --accent-soft: rgba(62, 224, 143, 0.1);
  --accent-fg: #03130a;
  --up: #3ee08f;
  --down: #ff5f7e;
  --warn: #ffb454;
  --warn-soft: rgba(255, 180, 84, 0.1);
  --info: #59c2ff;
  --grid-dot: rgba(212, 221, 230, 0.045);
  --shadow: none;
  --glow: 0 0 14px rgba(62, 224, 143, 0.28);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* The page scrollbar is always shown, so short and long pages line up. Styling it also swaps macOS's overlay
   scrollbar, which hides when idle, for a classic one in Chrome and Safari (Firefox follows the OS setting). */
html {
  -webkit-text-size-adjust: 100%;
  overflow-y: scroll;
}

html::-webkit-scrollbar {
  width: 12px;
}

html::-webkit-scrollbar-track {
  background: var(--bg);
}

html::-webkit-scrollbar-thumb {
  border: 3px solid var(--bg);
  border-radius: 999px;
  background: var(--border-strong);
}

html::-webkit-scrollbar-thumb:hover {
  background: var(--fg-faint);
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent);
  color: var(--accent-fg);
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
}

main.container {
  padding-top: 20px;
  padding-bottom: 48px;
}

/* ---------- header ---------- */

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 52px;
}

.logo {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.logo .prompt {
  color: var(--accent);
  text-shadow: var(--glow);
}

.cursor {
  display: inline-block;
  color: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--fg-muted);
}

.nav a:hover {
  color: var(--fg);
  background: var(--bg-hover);
}

.nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.header-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-line {
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-muted);
}

.status-line .container {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 26px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.status-line .container::-webkit-scrollbar {
  display: none;
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-faint);
  flex: none;
}

.dot.up {
  background: var(--up);
  box-shadow: 0 0 6px var(--up);
}

.dot.degraded {
  background: var(--warn);
}

.dot.down {
  background: var(--down);
  box-shadow: 0 0 6px var(--down);
}

@media (max-width: 720px) {
  .header .nav {
    display: none;
  }

  .header-row {
    gap: 10px;
  }
}

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elev);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  color: var(--accent-fg);
  box-shadow: var(--glow);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--fg-muted);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--border);
  color: var(--fg);
}

.btn.danger:hover:not(:disabled) {
  border-color: var(--down);
  color: var(--down);
}

.btn.sm {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.icon-btn {
  width: 30px;
  padding: 0;
}

.input,
.select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-sunken);
  outline: none;
  min-width: 0;
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder {
  color: var(--fg-faint);
}

.select {
  padding-right: 6px;
  cursor: pointer;
}

.select.sm {
  height: 30px;
  font-size: 12px;
}

@media (max-width: 359px) {
  .addr-short {
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ---------- panels ---------- */

.page-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-title .prompt {
  color: var(--accent);
}

.page-title .sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--fg-muted);
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  text-transform: lowercase;
}

.panel-head h2::before {
  content: "# ";
  color: var(--fg-faint);
}

.panel-body {
  padding: 14px;
}

.stack {
  display: grid;
  gap: 16px;
}

.muted {
  color: var(--fg-muted);
}

.faint {
  color: var(--fg-faint);
}

.up {
  color: var(--up);
}

.down {
  color: var(--down);
}

.warn {
  color: var(--warn);
}

.small {
  font-size: 11px;
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.stat {
  background: var(--bg-elev);
  padding: 12px 14px;
  min-width: 0;
}

.stat-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  margin-top: 2px;
  font-size: 11px;
}

.dominance {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 8px;
  border-radius: 3px;
  overflow: hidden;
}

.dominance .d-btc {
  fill: var(--warn);
}

.dominance .d-eth {
  fill: var(--info);
}

.dominance .d-other {
  fill: var(--bg-sunken);
}

@media (max-width: 960px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats .stat:first-child {
    grid-column: span 2;
  }
}

.movers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 720px) {
  .movers {
    grid-template-columns: 1fr;
  }
}

.mover-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.mover-list li {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
}

.mover-list li .price {
  color: var(--fg-muted);
}

.mover-list li .pct {
  min-width: 72px;
  text-align: right;
  font-weight: 600;
}

/* ---------- coin table ---------- */

.table-wrap {
  overflow-x: auto;
}

.coins {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.coins th,
.coins td {
  padding: 9px 12px;
  text-align: right;
  white-space: nowrap;
}

.coins th {
  position: sticky;
  top: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.coins th.sortable a {
  display: block;
  color: inherit;
}

.coins th.sortable:hover,
.coins th[aria-sort="ascending"],
.coins th[aria-sort="descending"] {
  color: var(--fg);
}

.coins td {
  border-bottom: 1px solid var(--border);
}

/* Not the action cell: the star's pop animation grows past it. */
.coins td:not(.act) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.coins tbody tr:last-child td {
  border-bottom: none;
}

.coins tbody tr:hover td {
  background: var(--bg-hover);
}

.coins .left {
  text-align: left;
}

/* The rank sits right after the star or ✕, right-aligned like the other numbers so the digits line up. */
.coins .rank {
  padding-left: 4px;
  padding-right: 4px;
  text-align: right;
  color: var(--fg-faint);
}

.coins .act {
  padding-left: 4px;
  padding-right: 4px;
}

/* A fixed layout: every column but the coin has a set width and the coin takes the rest, truncating its name.
   The market and the watchlist then line up column for column, whatever coins they list.
   A value wider than its column (a rare +1234.56%) ends in an ellipsis instead of running into the next one. */
.coins .act {
  width: 38px;
}

.coins .rank {
  width: 40px; /* fits a 4-digit rank */
}

.coins .rank-short {
  display: none;
}

.coins .col-price {
  width: 128px;
}

.coins .col-1h,
.coins .col-24h,
.coins .col-7d {
  width: 92px;
}

.coins .col-mcap,
.coins .col-vol {
  width: 104px;
}

.coins .col-spark {
  width: 134px;
}

.coins .act .icon-btn {
  height: 30px;
}

/* ☆ on the market and ✕ on the watchlist sit in the same spot, so they share one size and stroke. */
.row-icon {
  display: block;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.star.on .row-icon {
  fill: currentColor;
}

.coin-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.coin-cell img,
.coin-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  background: var(--bg-sunken);
}

.coin-icon {
  display: inline-grid;
  place-items: center;
  font-size: 9px;
  color: var(--fg-muted);
}

.coin-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.coin-name .sym,
.coin-name .full {
  overflow: hidden;
  text-overflow: ellipsis;
}

.coin-name .sym {
  font-weight: 600;
}

.coin-name .full {
  font-size: 11px;
  color: var(--fg-muted);
}

.star {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--fg-faint);
  border-radius: 4px;
}

.star:hover {
  color: var(--warn);
  background: var(--bg-hover);
}

.star.on {
  color: var(--warn);
}

.spark {
  display: block;
}

@media (max-width: 960px) {
  .coins .col-vol {
    display: none;
  }
}

@media (max-width: 720px) {
  .coins .col-mcap,
  .coins .col-7d {
    display: none;
  }

  .coins th,
  .coins td {
    padding: 9px 8px;
  }

  .coins .col-price {
    width: 112px;
  }

  .coins .col-1h,
  .coins .col-24h {
    width: 80px;
  }

  .coins .col-spark {
    width: 126px;
  }
}

/* Below this the chart makes way for price, 1h and 24h, so the table fits without scrolling.
   The rank stays in a 3-character column; 1000 and above shorten to "1k". */
@media (max-width: 560px) {
  .coins .col-spark {
    display: none;
  }

  .coins .rank {
    width: 30px;
    padding-left: 2px;
  }

  .coins .rank-full {
    display: none;
  }

  .coins .rank-short {
    display: inline;
  }
}

.table-foot {
  display: flex;
  justify-content: center;
  padding: 10px;
  border-top: 1px solid var(--border);
}

/* ---------- misc ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
}

.badge.warn {
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.ok {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.bad {
  border-color: color-mix(in srgb, var(--down) 45%, transparent);
  color: var(--down);
}

.alert {
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--down) 45%, transparent);
  border-radius: 6px;
  color: var(--down);
  background: color-mix(in srgb, var(--down) 8%, transparent);
  word-break: break-word;
}

.alert.warn {
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--warn);
  background: var(--warn-soft);
}

.alert::before {
  content: "ERR ";
  font-weight: 700;
}

.alert.warn::before {
  content: "WARN ";
}

.loading {
  padding: 28px 14px;
  color: var(--fg-muted);
  text-align: center;
}

.loading::after {
  content: "_";
  color: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--fg-muted);
}

.empty .big {
  font-size: 22px;
  color: var(--fg-faint);
  margin-bottom: 8px;
}

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

.toolbar .input {
  flex: 1 1 200px;
}

.grep {
  position: relative;
  flex: 1 1 200px;
  max-width: 280px;
}

.grep .input {
  width: 100%;
  padding-left: 58px;
}

.grep::before {
  content: "grep ›";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 12px;
  pointer-events: none;
}

@media (max-width: 720px) {
  .grep {
    max-width: none;
  }

  /* market and watchlist: the heading and a narrow filter share one row. */
  .filter-head {
    flex-wrap: nowrap;
    padding: 8px 12px;
  }

  .filter-head h2 {
    white-space: nowrap;
  }

  .filter-head .toolbar {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    min-width: 0;
  }

  .filter-head .grep {
    flex: 0 1 190px;
    min-width: 0;
  }

  .filter-head .grep .input {
    height: 30px;
  }
}

/* ---------- wallet sheet ---------- */

.wallet-list {
  display: grid;
  gap: 8px;
}

.wallet-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sunken);
  cursor: pointer;
  text-align: left;
  color: inherit;
  text-decoration: none;
}

.wallet-opt:hover:not(:disabled) {
  border-color: var(--accent);
}

.wallet-opt img,
.wallet-opt .wallet-glyph {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex: none;
}

.wallet-opt .wallet-glyph {
  display: grid;
  place-items: center;
  background: var(--bg-hover);
  color: var(--accent);
}

.wallet-opt .arrow {
  margin-left: auto;
  color: var(--fg-faint);
}

.log {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.log .ok {
  color: var(--up);
}

.log .err {
  color: var(--down);
}

/* Pairing code of the MetaMask handoff: shown on the signing page, typed on the original screen. */
.pair-code {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--fg);
  user-select: all;
  -webkit-user-select: all;
}

.pair-code-input {
  font-size: 20px;
  letter-spacing: 0.3em;
  text-align: center;
  height: 44px;
}

/* ---------- converter ---------- */

.coin-open {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
}

.coin-open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.coins tbody tr:has([data-convert]),
.mover-list li:has([data-convert]) {
  cursor: pointer;
}

.mover-list li:has([data-convert]):hover {
  background: var(--bg-hover);
}

/* ---------- coin sheet: quote, 7d chart, stats ---------- */

.coin-info {
  display: grid;
  gap: 10px;
  padding: 14px 14px 0;
}

/* Holds the space while loading, so the converter below does not jump. */
.coin-info:empty {
  min-height: 290px;
}

.coin-quote {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.coin-price {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.coin-rank {
  margin-left: auto;
}

.chart {
  display: grid;
  gap: 4px;
  margin: 0;
}

.chart-plot {
  position: relative;
  height: 120px;
  cursor: crosshair;
  /* Vertical drags still scroll the sheet; horizontal ones scrub. */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.chart-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-line,
.chart-base {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.chart-line {
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-base {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-up .chart-line {
  stroke: var(--up);
}

.chart-down .chart-line {
  stroke: var(--down);
}

.chart-up .chart-area {
  fill: color-mix(in srgb, var(--up) 12%, transparent);
}

.chart-down .chart-area {
  fill: color-mix(in srgb, var(--down) 12%, transparent);
}

.chart-cursor,
.chart-dot {
  position: absolute;
  display: none;
  pointer-events: none;
}

.chart-cursor {
  top: 0;
  bottom: 0;
  left: var(--x);
  width: 1px;
  background: var(--border-strong);
}

.chart-dot {
  left: var(--x);
  top: var(--y);
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 0 0 2px var(--bg-elev);
}

.chart.scrubbing .chart-cursor,
.chart.scrubbing .chart-dot {
  display: block;
}

.chart-readout {
  min-height: 1.5em;
  font-variant-numeric: tabular-nums;
}

.chart [data-chart-scrub],
.chart.scrubbing [data-chart-default] {
  display: none;
}

.chart.scrubbing [data-chart-scrub] {
  display: inline;
}

.chart-empty {
  display: grid;
  place-items: center;
  height: 120px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

@media (max-width: 720px) {
  .chart-plot,
  .chart-empty {
    height: 96px;
  }

  .coin-info:empty {
    min-height: 266px;
  }
}

.coin-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--border);
  overflow: hidden;
}

.coin-stats div {
  min-width: 0;
  padding: 8px 10px;
  background: var(--bg-sunken);
}

.coin-stats dt {
  font-size: 11px;
  color: var(--fg-muted);
}

.coin-stats dd {
  margin: 2px 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.convert-amount {
  display: grid;
  gap: 6px;
}

/* 16px or more, or iOS zooms in on focus. */
.convert-amount .input {
  width: 100%;
  height: 42px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.convert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sunken);
}

.convert-list li {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: baseline;
  column-gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.convert-list li:first-child {
  border-top: none;
}

.convert-list .ccy {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
}

.convert-list .base .ccy {
  color: var(--accent);
}

.convert-list .total {
  text-align: right;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.convert-list .unit {
  grid-column: 2;
  text-align: right;
}

#convert-out:empty {
  display: none;
}

/* ---------- search dropdown ---------- */

.search {
  position: relative;
  flex: 1 1 200px;
  max-width: 280px;
}

.search .grep {
  max-width: none;
}

/* Results float under the search box instead of pushing the table down. */
.search .search-results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: max(100%, 380px);
  max-width: calc(100vw - 32px);
  margin-top: 0;
}

.search.closed .search-results {
  display: none;
}

/* On phones the box shares the header row (narrowed, like the market filter) and the results span the panel. */
@media (max-width: 720px) {
  .panel-head {
    position: relative;
  }

  .search {
    position: static;
    flex: 0 1 190px;
    min-width: 0;
    max-width: none;
  }

  .filter-head .toolbar .small {
    white-space: nowrap;
  }

  .search .search-results {
    top: calc(100% - 4px);
    left: 14px;
    right: 14px;
    width: auto;
    max-width: none;
  }
}

.search-results {
  margin-top: 8px;
  max-height: 420px;
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.search-results .row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.search-results .row:last-child {
  border-bottom: none;
}

.search-results .row:hover {
  background: var(--bg-hover);
}

/* ---------- settings ---------- */

.field {
  display: grid;
  gap: 6px;
}

.field > label,
.field > .label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.radio-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.radio {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-sunken);
  cursor: pointer;
}

.radio:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.radio input,
.check input {
  accent-color: var(--accent);
  margin: 3px 0 0;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
}

.key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.key-row .input {
  width: 100%;
}

.key-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 0;
  font-size: 12px;
}

.kv dt {
  color: var(--fg-muted);
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .settings-grid,
  .radio-group {
    grid-template-columns: 1fr;
  }
}

.radio-group.langs {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.health {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.health th,
.health td {
  padding: 8px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.health tr:last-child td {
  border-bottom: none;
}

.health th {
  font-weight: 500;
  color: var(--fg-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.menu {
  position: relative;
}

.menu summary {
  list-style: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 200px;
  padding: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.menu-pop .addr {
  padding: 6px 8px 8px;
  font-size: 11px;
  color: var(--fg-muted);
  word-break: break-all;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.menu-pop form {
  margin: 0;
}

.menu-pop a,
.menu-pop button {
  display: block;
  width: 100%;
  padding: 7px 8px;
  border: none;
  border-radius: 4px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-pop a:hover,
.menu-pop button:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.footer {
  padding: 20px 0 28px;
  color: var(--fg-faint);
  font-size: 11px;
}

.footer a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 720px) {
  .footer {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }
}

/* ---------- utilities ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stack.tight {
  gap: 10px;
}

.panel-body p,
.modal-body p {
  margin: 0;
}

.empty p {
  margin: 0 0 16px;
}

.toolbar.spread {
  justify-content: space-between;
}

.badges {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.health td.wrap {
  white-space: normal;
  min-width: 160px;
}


.via {
  padding: 6px 12px;
}

.left {
  text-align: left !important;
}

.coins td.nodata {
  white-space: normal;
}

.coin-img.broken {
  visibility: hidden;
}

.mover-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.modal-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

/* ---------- app feel: press feedback ---------- */

.btn,
.star,
.wallet-opt,
.radio,
.tabbar a,
.nav a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active:not(:disabled),
.wallet-opt:active,
.radio:active {
  transform: scale(0.97);
}

.star:active {
  transform: scale(0.85);
}

.star.on {
  animation: pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}

form.htmx-request .btn,
form.htmx-request .star,
.btn.htmx-request {
  opacity: 0.55;
  pointer-events: none;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

#search-results .row {
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* ---------- progress bar ---------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 2px;
  pointer-events: none;
  background: var(--accent);
  box-shadow: var(--glow);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
}

html.is-loading .progress {
  opacity: 1;
  animation: progress 8s cubic-bezier(0.1, 0.7, 0.2, 1) forwards;
}

html.is-done .progress {
  transform: scaleX(1);
  opacity: 0;
  transition: transform 0.15s ease, opacity 0.3s ease 0.1s;
}

@keyframes progress {
  from {
    transform: scaleX(0);
  }
  10% {
    transform: scaleX(0.35);
  }
  to {
    transform: scaleX(0.92);
  }
}

/* ---------- tab bar (mobile) ---------- */

.tabbar {
  display: none;
}

@media (max-width: 720px) {
  .header {
    padding-top: env(safe-area-inset-top);
  }

  /* One compact row: the list starts as high as possible on a phone. */
  .page-title {
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 15px;
  }

  .page-title > span:first-child {
    flex: none;
    white-space: nowrap;
  }

  .page-title .badges {
    justify-content: flex-end;
    min-width: 0;
  }

  /* The status line under the header already names the source. */
  .page-title .badge.src {
    display: none;
  }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg-elev) 86%, transparent);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-top: 1px solid var(--border);
    view-transition-name: tabbar;
    --tab: 0;
  }

  .tabbar:has(> a:nth-child(2)[aria-current="page"]) {
    --tab: 1;
  }

  .tabbar:has(> a:nth-child(3)[aria-current="page"]) {
    --tab: 2;
  }

  /* One indicator slides to the current tab. It moves on the tap, before the next page arrives. */
  .tabbar::before {
    content: "";
    position: absolute;
    top: -1px;
    left: calc((var(--tab) + 0.32) * 100% / 3);
    width: calc(0.36 * 100% / 3);
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--accent);
    box-shadow: var(--glow);
    transition: left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .tabbar:not(:has([aria-current="page"]))::before {
    opacity: 0;
  }

  .tabbar a {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 0 8px;
    font-size: 10.5px;
    color: var(--fg-muted);
    transition: color 0.2s ease;
    -webkit-touch-callout: none;
    user-select: none;
  }

  .tabbar svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.3);
  }

  .tabbar a:active svg {
    transform: scale(0.86);
  }

  .tabbar a[aria-current="page"] {
    color: var(--accent);
  }

  .tabbar a[aria-current="page"] svg {
    transform: translateY(-1px) scale(1.08);
    filter: drop-shadow(0 0 6px var(--accent-soft));
  }

}

@media (max-width: 440px) {
  .header-row {
    gap: 8px;
  }

  .logo {
    font-size: 13px;
  }

  .logo .cursor {
    display: none;
  }

  .header-tools {
    gap: 4px;
  }

  .theme-btn {
    padding: 0 4px;
  }

  /* Numbers a size down and a slimmer ☆/✕ column pay for the rank column. */
  .coins {
    font-size: 11px;
  }

  .coins th,
  .coins td {
    padding: 9px 5px;
  }

  .coin-name .sym {
    font-size: 12px;
  }

  .coins .act {
    width: 28px;
    padding-left: 2px;
    padding-right: 2px;
  }

  .coins .act .star,
  .coins .act .icon-btn {
    width: 24px;
  }

  .coins .rank {
    width: 26px;
    padding-left: 1px;
  }

  .coins .col-price {
    width: 88px;
  }

  .coins .col-1h,
  .coins .col-24h {
    width: 58px;
  }

  .coin-cell {
    gap: 8px;
  }

  .menu summary {
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
  }
}

/* ---------- page transitions ---------- */

@media (max-width: 720px) {
  @view-transition {
    navigation: auto;
  }
}

.header {
  view-transition-name: header;
}

::view-transition-old(root) {
  animation: vt-out 0.14s ease both;
}

::view-transition-new(root) {
  animation: vt-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

/* The page being left dims while the next one loads (see navigation in app.js); quick loads never show it. */
html.navigating main {
  opacity: 0.5;
  transition: opacity 0.2s ease 0.08s;
}

/* Too narrow for the title and its badges on one row. After the 720px rules so it wins. */
@media (max-width: 359px) {
  .page-title {
    flex-wrap: wrap;
  }
}

/* ---------- auto refresh ---------- */

.badge.refresh {
  font: inherit;
  font-size: 11px;
  background: transparent;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.badge.refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.badge.refresh span {
  min-width: 3ch;
  text-align: right;
}

.badge.refresh svg {
  width: 12px;
  height: 12px;
  transform: rotate(-90deg);
}

.badge.refresh circle {
  fill: none;
  stroke-width: 2.4;
}

.badge.refresh .track {
  stroke: var(--border-strong);
}

.badge.refresh .ring {
  stroke: var(--accent);
  stroke-dasharray: 100;
  stroke-dashoffset: calc(var(--elapsed, 0) * 1px);
  transition: stroke-dashoffset 0.25s linear;
}

.badge.refresh.busy svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(-90deg);
  }
  to {
    transform: rotate(270deg);
  }
}

.tick-up,
.tick-down,
.tick-new {
  border-radius: 3px;
  animation: tick 1.6s ease-out;
}

.tick-up {
  --tick: var(--up);
}

.tick-down {
  --tick: var(--down);
}

.tick-new {
  --tick: var(--accent);
}

@keyframes tick {
  0% {
    opacity: 0.2;
    color: var(--tick);
    background-color: color-mix(in srgb, var(--tick) 22%, transparent);
  }
  20% {
    opacity: 1;
    color: var(--tick);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes vt-out {
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  z-index: 90;
  top: calc(env(safe-area-inset-top) + 70px);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-elev);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  font-size: 12px;
  animation: toast-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.toast.ok {
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  color: var(--accent);
}

.toast.err {
  border-color: color-mix(in srgb, var(--down) 50%, transparent);
  color: var(--down);
}

.toast.leaving {
  animation: toast-out 0.2s ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}

@media (max-width: 720px) {
  .toasts {
    top: auto;
    bottom: calc(78px + env(safe-area-inset-bottom));
  }

  @keyframes toast-in {
    from {
      opacity: 0;
      transform: translateY(12px) scale(0.96);
    }
  }
}

/* ---------- sheet (dialog) ---------- */

dialog.sheet {
  width: calc(100% - 32px);
  max-width: 420px;
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--fg);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

dialog.sheet::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
}

dialog.sheet[open] {
  animation: pop-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

dialog.sheet[open]::backdrop {
  animation: fade-in 0.2s ease;
}

dialog.sheet.closing {
  animation: pop-out 0.16s ease both;
}

.sheet-grip {
  display: none;
}

.details-pop,
details[open] > .menu-pop {
  animation: pop-in 0.16s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@media (max-width: 720px) {
  dialog.sheet {
    width: 100%;
    max-width: none;
    max-height: 88dvh;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }

  dialog.sheet[open] {
    animation: sheet-up 0.34s cubic-bezier(0.2, 0.9, 0.25, 1);
  }

  dialog.sheet.closing {
    animation: sheet-down 0.22s ease both;
  }

  .sheet-grip {
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: var(--border-strong);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
}

@keyframes pop-out {
  to {
    opacity: 0;
    transform: scale(0.97);
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
}

@keyframes sheet-down {
  to {
    transform: translateY(100%);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
    transition: none !important;
  }
}
