:root {
  color-scheme: dark;
  --bg: #080908;
  --panel: #181a18;
  --panel-2: #22251f;
  --line: #30352e;
  --line-soft: #262b25;
  --text: #f4f5ef;
  --muted: #92998e;
  --green: #00d395;
  --red: #ff6767;
  --blue: #4f79ff;
  --yellow: #f4cc37;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 10% 0%, rgba(0, 211, 149, 0.12), transparent 32%),
    radial-gradient(circle at 90% 8%, rgba(244, 204, 55, 0.1), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "PingFang SC", "Helvetica Neue", sans-serif;
}

body { padding: 14px; }
button, select, input { font: inherit; }
.page {
  width: 100%;
  max-width: 1540px;
  margin: 0 auto;
}

.sticky-shell {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: 1px;
  margin: -1px 0 18px;
  background:
    radial-gradient(circle at 10% 0%, rgba(0, 211, 149, 0.12), transparent 32%),
    radial-gradient(circle at 90% 8%, rgba(244, 204, 55, 0.1), transparent 28%),
    rgba(8, 9, 8, 0.94);
  backdrop-filter: blur(14px);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 15px;
  background: linear-gradient(135deg, #00d395, #f4cc37);
  color: #10140f;
  font-size: 24px;
  font-weight: 900;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.control-card,
.status-card,
.stat-card {
  border: 1px solid #2b3029;
  background: rgba(14, 16, 14, 0.92);
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

.control-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.control-card strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid #2b3029;
  background: rgba(14, 16, 14, 0.92);
}

.segmented button {
  min-width: 56px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.active {
  background: rgba(79, 121, 255, 0.16);
  color: #8eacff;
}

.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 14px;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid #8c9388;
  border-bottom: 1.5px solid #8c9388;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select-wrap select {
  min-width: 128px;
  height: 44px;
  padding: 0 38px 0 14px;
  border: 1px solid #2b3029;
  border-radius: 14px;
  background: rgba(14, 16, 14, 0.92);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  appearance: none;
  outline: none;
}

.token-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #2b3029;
  border-radius: 14px;
  background: rgba(14, 16, 14, 0.92);
  color: var(--muted);
  font-size: 13px;
}

.token-search input {
  width: 120px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-transform: uppercase;
}

.token-search input::placeholder {
  color: #687063;
}

.filter-chip {
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(79, 121, 255, 0.28);
  border-radius: 13px;
  background: rgba(79, 121, 255, 0.14);
  color: #91aaff;
  font-weight: 700;
}

.filter-chip.visible { display: inline-flex; }

.filter-chip button {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: rgba(255,255,255,0.06);
  color: #b6c6ff;
  cursor: pointer;
  font-size: 18px;
}

.status-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-left: auto;
  padding: 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #6d746a;
}
.status-dot.ok { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-main { color: var(--text); font-weight: 800; }
.status-meta {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  min-height: 86px;
  padding: 14px 16px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
}

.stat-value {
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
}

.stat-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.board {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(24, 26, 24, 0.96);
  box-shadow: var(--shadow);
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(34, 37, 31, 0.9);
}

.board-title {
  font-size: 15px;
  font-weight: 800;
}

.board-meta {
  font-size: 12px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 1540px;
  border-collapse: collapse;
}

thead th {
  height: 54px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  color: #f1f3ec;
  font-size: 15px;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

thead th:first-child,
tbody td:first-child {
  width: 64px;
  text-align: center;
}

thead th:nth-child(2),
tbody td:nth-child(2) {
  text-align: left;
}

thead th.sort-active { color: var(--blue); }
.sort-arrow { margin-left: 5px; }

tbody tr {
  height: 66px;
  border-bottom: 1px solid var(--line-soft);
  transition: background-color 180ms ease;
}

tbody tr:hover { background: rgba(255,255,255,0.02); }

tbody tr:last-child { border-bottom: 0; }

tbody tr.flash-updated {
  animation: row-flash 1.9s ease-out;
}

@keyframes row-flash {
  0% {
    background: rgba(79, 121, 255, 0.26);
    box-shadow: inset 0 0 0 1px rgba(79, 121, 255, 0.42);
  }
  100% {
    background: transparent;
    box-shadow: none;
  }
}

tbody td {
  padding: 0 16px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 15px;
}

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

.rank {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: #323730;
  color: #d8ded4;
  font-weight: 800;
}
.rank.top1 { background: #6b4c12; color: #ffca47; }
.rank.top2 { background: #3e4540; }
.rank.top3 { background: #613414; color: #ff9b42; }
.mobile-rank { display: none; }

.pair-cell,
.pair-inline,
.pair-main,
.actions {
  display: inline-flex;
  align-items: center;
}
.pair-cell { gap: 12px; }
.pair-inline { gap: 10px; }
.pair-main {
  gap: 0;
  font-size: 15px;
  font-weight: 500;
}

.dex-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

.version-pill {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}
.version-pill.v3 { background: rgba(79, 121, 255, 0.16); color: #7294ff; }
.version-pill.v4 { background: rgba(244, 204, 55, 0.16); color: var(--yellow); }

.pair-token-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.pair-token-button:hover { color: var(--blue); }
.pair-quote { color: #d4d9cf; }

.alpha-badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 5px;
  border-radius: 6px;
  color: #12130e;
  font-size: 13px;
  font-weight: 900;
}
.alpha-badge { background: var(--yellow); }

.num-green { color: var(--green); font-weight: 800; }
.num-red { color: var(--red); font-weight: 800; }

.actions {
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn,
.action-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
}

.icon-btn {
  min-width: 44px;
  height: 30px;
  gap: 4px;
  background: transparent;
  color: #e6e9e1;
}

.action-link-btn {
  width: 42px;
  height: 36px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.action-link-btn:disabled { opacity: 0.32; cursor: not-allowed; }

.icon-btn svg,
.action-link-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
}

.depth-btn {
  background: rgba(240, 204, 55, 0.14);
  color: var(--yellow);
  font-size: 13px;
  font-weight: 900;
}

.copy-kind {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 18px;
  border-radius: 5px;
  background: rgba(79, 121, 255, 0.18);
  color: #91aaff;
  font-size: 12px;
  font-weight: 900;
}

.toast-root {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 99;
  display: grid;
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px;
  border: 1px solid rgba(0, 211, 149, 0.32);
  border-radius: 12px;
  background: #022b17;
  color: #9affcf;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 800;
  animation: toast-in 180ms ease-out;
}
.toast.error {
  border-color: rgba(255, 103, 103, 0.34);
  background: #351010;
  color: #ffb1b1;
}
.toast.leaving { animation: toast-out 200ms ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@media (max-width: 960px) {
  body { padding: 0; }
  .page { max-width: none; }
  .sticky-shell {
    margin: 0 0 10px;
    padding: 8px;
    border-bottom: 1px solid rgba(48, 53, 46, 0.9);
  }
  .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(92px, 0.68fr);
    gap: 8px;
    margin-bottom: 0;
  }
  .brand,
  .control-card,
  .status-card,
  .stats {
    display: none;
  }
  .segmented,
  .select-wrap,
  .token-search,
  .filter-chip {
    width: 100%;
    min-width: 0;
  }
  .segmented {
    grid-column: 1 / 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    height: 42px;
  }
  .segmented button {
    min-width: 0;
    height: 32px;
    padding: 0;
    font-size: 12px;
  }
  .select-wrap {
    grid-column: 2 / 3;
  }
  .select-wrap select {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding-left: 12px;
    font-size: 13px;
  }
  .token-search {
    grid-column: 1 / 2;
    height: 42px;
  }
  .token-search span {
    flex: 0 0 auto;
  }
  .token-search input {
    width: 100%;
    min-width: 0;
  }
  .filter-chip.visible {
    grid-column: 2 / 3;
    align-self: center;
    justify-self: start;
    display: inline-flex;
    width: auto;
    max-width: 100%;
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }
  .board {
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  .board-head {
    display: none;
  }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  table {
    border-collapse: separate;
    border-spacing: 0 10px;
  }
  thead { display: none; }
  tbody tr {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-areas:
      "pair pair pair pair pair pair swaps swaps swaps rank rank rank"
      "price price price price fee fee fee fee rate rate rate rate"
      "feeTvl feeTvl feeTvl feeTvl tvl tvl tvl tvl volume volume volume volume"
      "actions actions actions actions actions actions actions actions actions actions actions actions";
    column-gap: 14px;
    row-gap: 10px;
    height: auto;
    margin: 0 8px 8px;
    padding: 10px 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
  }
  tbody td {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    min-width: 0;
    padding: 0;
    text-align: left;
    white-space: normal;
    font-size: 15px;
    line-height: 1.18;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    text-align: left;
    font-size: 11px;
    line-height: 1.1;
  }
  tbody td:first-child { grid-area: rank; }
  tbody td:first-child {
    align-self: start;
    justify-self: end;
    width: auto;
  }
  tbody td:nth-child(2) {
    display: block;
    grid-area: pair;
  }
  tbody td:nth-child(2)::before { content: ""; }
  tbody td:nth-child(3) { grid-area: price; }
  tbody td:nth-child(4) { grid-area: rate; }
  tbody td:nth-child(5) { grid-area: fee; }
  tbody td:nth-child(6) { grid-area: tvl; }
  tbody td:nth-child(7) { grid-area: feeTvl; }
  tbody td:nth-child(8) { grid-area: volume; }
  tbody td:nth-child(9) {
    grid-area: swaps;
    align-self: center;
  }
  tbody td:nth-child(10) {
    grid-area: actions;
    border-top: 1px solid rgba(48, 53, 46, 0.9);
    padding-top: 6px;
  }
  tbody td:nth-child(10)::before {
    content: attr(data-label);
  }
  tbody td:nth-child(10) {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 14px;
  }
  .pair-cell {
    display: flex;
    width: 100%;
    gap: 9px;
    align-items: center;
  }
  .pair-inline {
    min-width: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .pair-main {
    font-size: 15px;
  }
  .dex-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }
  .version-pill {
    height: 21px;
    min-width: 34px;
    padding: 0 8px;
    font-size: 10px;
  }
  .mobile-rank {
    display: none;
  }
  tbody td:first-child::before {
    content: "";
    display: none;
  }
  tbody td:first-child .rank {
    display: block;
    width: auto;
    height: auto;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
    text-align: right;
  }
  tbody td:first-child .rank.top1,
  tbody td:first-child .rank.top2,
  tbody td:first-child .rank.top3 {
    background: transparent;
  }
  tbody td:first-child .rank.top1 { color: #ffca47; }
  tbody td:first-child .rank.top2 { color: #d8ded4; }
  tbody td:first-child .rank.top3 { color: #ff9b42; }
  .actions {
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 2px;
  }
  .icon-btn {
    min-width: 38px;
    height: 28px;
  }
  .action-link-btn {
    width: 38px;
    height: 32px;
    border-radius: 10px;
  }
  .empty {
    margin: 0 8px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
  }
}
