/* =========================================================
   THEME VARIABLES
   ========================================================= */
:root,
html[data-theme="dark"] {
  --bg: #0b0e11;
  --bg-2: #12161c;
  --bg-3: #1a1f28;
  --bg-hover: #232932;
  --border: #262b35;
  --text: #eaecef;
  --text-2: #848e9c;
  --text-3: #5e6673;
  --yellow: #f0b90b;
  --green: #0ecb81;
  --red: #f6465d;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
  --glass: rgba(11,14,17,.92);
}

html[data-theme="light"] {
  --bg: #fafafa;
  --bg-2: #ffffff;
  --bg-3: #f2f4f7;
  --bg-hover: #eef0f4;
  --border: #e3e6eb;
  --text: #1a1d23;
  --text-2: #5e6673;
  --text-3: #9aa1ad;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --glass: rgba(255,255,255,.92);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color .25s ease, color .25s ease;
}

a { color: inherit; text-decoration: none; }

/* =========================================================
   TOP BAR
   ========================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background-color .25s ease, border-color .25s ease;
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -.3px;
  color: var(--text);
  flex-shrink: 0;
}
.brand-mark {
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--yellow), #f8d33a);
  border-radius: 8px;
  font-size: 15px;
  color: #0b0e11;
  font-weight: 900;
}

/* NAV */
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: .15s;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.nav a:hover { color: var(--text); background: var(--bg-3); }
.nav a:active { transform: scale(.96); }
.nav a.active { color: var(--yellow); background: rgba(240,185,11,.1); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.global-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  margin-right: 8px;
}
.global-stats b { color: var(--text); font-weight: 600; }

/* Icon button */
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { color: var(--yellow); border-color: var(--yellow); }
.icon-btn:active { transform: scale(.95); }
.icon-btn svg { width: 16px; height: 16px; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.dropdown-btn:hover { border-color: var(--yellow); }
.dropdown-btn:active { transform: scale(.97); }
.dropdown-btn svg { width: 13px; height: 13px; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 140px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px;
  display: none;
  z-index: 200;
}
.dropdown-menu.open { display: block; animation: dropIn .14s ease; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-4px); } }

.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: .12s;
}
.dropdown-menu button:hover { background: var(--bg-3); color: var(--yellow); }
.dropdown-menu button.active { color: var(--yellow); font-weight: 600; }

/* WS status */
.ws-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  padding: 6px 11px;
  border-radius: 20px;
  background: var(--bg-3);
  white-space: nowrap;
}
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); animation: pulse 1.6s infinite; }
.ws-dot.live { background: var(--green); }
.ws-dot.dead { background: var(--red); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* =========================================================
   PAGE
   ========================================================= */
.page { max-width: 1400px; margin: 0 auto; padding: 22px 20px 80px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.4px; }
.page-head .desc { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-2);
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
}
.tabs button {
  background: none;
  border: 0;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--yellow); color: #0b0e11; }

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 380px; }
.search-wrap svg {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  stroke: var(--text-3);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 36px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s;
}
#search::placeholder { color: var(--text-3); }
#search:focus { border-color: var(--yellow); }

.count-badge {
  font-size: 12px;
  color: var(--text-2);
  padding: 6px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: nowrap;
}
.count-badge b { color: var(--yellow); }

/* =========================================================
   TABLE
   ========================================================= */
.table-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  text-align: right;
  padding: 12px 14px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-2);
  background: var(--bg-3);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color .15s;
  position: sticky;
  top: 0;
  z-index: 5;
}
thead th:hover { color: var(--yellow); }
thead th.sorted { color: var(--yellow); }
thead th:first-child { text-align: center; width: 46px; cursor: default; }
thead th:nth-child(2) { text-align: left; }

tbody tr {
  border-top: 1px solid var(--border);
  transition: background .12s;
  cursor: pointer;
}
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 12px 14px;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
tbody td:first-child { text-align: center; color: var(--text-3); font-size: 12px; }
tbody td:nth-child(2) { text-align: left; }

/* Star */
.star-cell {
  text-align: center !important;
  width: 40px;
  padding-left: 6px !important;
  padding-right: 2px !important;
  /* star must always win clicks over the row */
  position: relative;
  z-index: 2;
}
.star {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-3);
  transition: transform .12s ease, color .15s ease, background .15s ease;
  border: 0;
  background: none;
  padding: 0;
  pointer-events: auto;      /* ensure clickable even inside a row with cursor:pointer */
  -webkit-user-select: none;
  user-select: none;
}
.star:hover { color: var(--yellow); background: rgba(240,185,11,.12); }
.star:active { transform: scale(.85); }
.star.active { color: var(--yellow); }
.star.active svg { filter: drop-shadow(0 0 4px rgba(240,185,11,.55)); }
.star svg { width: 15px; height: 15px; display: block; }

/* Coin cell */
.coin { display: flex; align-items: center; gap: 10px; }
.coin-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg-3);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--yellow);
  flex-shrink: 0;
  overflow: hidden;
}
.coin-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

.coin-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.coin-meta .name { font-weight: 600; color: var(--text); font-size: 13.5px; }
.coin-meta .sym  { font-size: 11.5px; color: var(--text-3); }

.price { color: var(--text); font-weight: 600; }

/* Change badges */
.chg {
  display: inline-block;
  min-width: 66px;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12.5px;
}
.chg.up   { color: var(--green); background: rgba(14,203,129,.1); }
.chg.down { color: var(--red);   background: rgba(246,70,93,.1); }

.up   { color: var(--green); }
.down { color: var(--red); }

/* Flash */
tr.flash-up   td.price { animation: flashUp .7s ease-out; }
tr.flash-down td.price { animation: flashDown .7s ease-out; }
@keyframes flashUp {
  0%   { background: rgba(14,203,129,.35); color: var(--green); border-radius: 4px; }
  100% { background: transparent; }
}
@keyframes flashDown {
  0%   { background: rgba(246,70,93,.35); color: var(--red); border-radius: 4px; }
  100% { background: transparent; }
}

/* Sparkline */
.spark-cell { width: 120px; padding: 6px 10px !important; }
.sparkline { display: block; width: 100%; height: 36px; }

/* Empty */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-2);
  font-size: 14px;
}
.empty svg { width: 42px; height: 42px; stroke: var(--text-3); margin-bottom: 12px; }

/* Loader */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px;
  font-size: 13px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.end-of-list {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
}

/* Footer */
.foot {
  max-width: 1400px;
  margin: 30px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* =========================================================
   MODAL
   ========================================================= */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-back.show { display: flex; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(.96); } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  background: none;
  border: 0;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; stroke: currentColor; }

.modal-price {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.modal-chg { font-size: 14px; font-weight: 600; margin-bottom: 18px; }

.modal-chart { width: 100%; height: 160px; margin-bottom: 18px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--bg-3); padding: 11px 13px; border-radius: 9px; }
.stat .k { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 3px; }
.stat .v { font-size: 14.5px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1024px) {
  .col-high, .col-high-h { display: none; }
  .nav { display: none; }
}

@media (max-width: 768px) {
  .topbar-inner { padding: 10px 14px; gap: 8px; }
  .page { padding: 16px 12px 60px; }
  .page-head h1 { font-size: 18px; }
  .global-stats { display: none; }
  .brand-name { display: none; }

  table { font-size: 13px; }
  thead th { padding: 10px 8px; font-size: 10.5px; }
  tbody td { padding: 11px 8px; }
  tbody td:first-child, thead th:first-child { display: none; }

  .coin-meta .name { font-size: 13px; }
  .col-vol, .col-vol-h { display: none; }
  .spark-cell, .spark-h { display: none !important; }
  .star-cell { width: 32px; }
  .star { width: 22px; height: 22px; }
  .star svg { width: 13px; height: 13px; }
}

@media (max-width: 480px) {
  .col-high, .col-high-h, .col-low, .col-low-h { display: none; }
  thead th:nth-child(3), tbody td:nth-child(3) { min-width: 84px; }
  .chg { min-width: 58px; font-size: 11.5px; padding: 2px 6px; }
  .toolbar { gap: 8px; }
  .count-badge { display: none; }
  .dropdown-menu { right: auto; left: 0; }
}