:root {
  --bg: #0b0e14;
  --bg2: #11151f;
  --card: #151a26;
  --line: #232a3a;
  --text: #e6e9f0;
  --muted: #8a93a6;
  --long: #f6465d;
  --short: #2ebd85;
  --accent: #3b82f6;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  /* full window height so the history card can stretch to the bottom edge */
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ---------- top bar / digital clock ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 20px 4px;
}

.brand { display: flex; flex-direction: column; gap: 2px; }
.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .2px;
}
.brand-sub {
  margin: 0;
  font-size: 10.5px;
  color: var(--muted);
}

.clock-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 14px 8px;
  border-radius: 11px;
  background: linear-gradient(150deg, #182031 0%, #0d121c 100%);
  border: 1px solid #2b364c;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .38), inset 0 1px 0 rgba(255, 255, 255, .06);
  overflow: hidden;
}
.clock-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, .9), transparent);
}

.clock-left { display: flex; flex-direction: column; gap: 2px; }
.clock-date { font-size: 11.5px; font-weight: 550; letter-spacing: .2px; }
.clock-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--muted);
}
.clock-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--short);
  animation: clockPulse 2s infinite;
}
@keyframes clockPulse {
  0%   { box-shadow: 0 0 0 0 rgba(46, 189, 133, .5); }
  70%  { box-shadow: 0 0 0 7px rgba(46, 189, 133, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 189, 133, 0); }
}

.clock-divider { width: 1px; height: 30px; background: var(--line); }
.clock-time {
  display: flex;
  align-items: baseline;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 25px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #eaf2ff;
  text-shadow: 0 0 18px rgba(120, 170, 255, .22);
}
.clock-time .sec { font-size: 15px; color: #9cc7ff; text-shadow: 0 0 12px rgba(120, 170, 255, .45); }
.clock-time .ampm {
  align-self: center;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar { padding: 6px 14px 4px; }
  .clock-card { gap: 10px; padding: 6px 11px; }
  .clock-time { font-size: 21px; }
  .clock-time .sec { font-size: 13px; }
}

/* snapshot countdown — sits just left of the interval dropdown */
.countdown {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 26px;
  font-weight: 800;
  letter-spacing: .6px;
  line-height: 1;
  padding: 6px 14px 7px;
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(59, 130, 246, .24), rgba(59, 130, 246, .05));
  border: 1px solid rgba(96, 165, 250, .45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 0 16px rgba(59, 130, 246, .22);
  min-width: 100px;
  text-align: center;
  white-space: nowrap;
}
.countdown .cd-time {
  background: linear-gradient(180deg, #ffffff 10%, #8ec5ff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 0 10px rgba(96, 165, 250, .5));
}
.countdown.off {
  opacity: .5;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  box-shadow: none;
  background: var(--bg2);
  border-color: var(--line);
}
.history-controls .countdown:not(.off) {
  flex-shrink: 0;
  font-size: 22px;
  padding: 5px 12px 6px;
  min-width: 92px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: #1a2130; border-color: #33405a; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-ico { width: 15px; height: 15px; flex-shrink: 0; }

.btn-save {
  background: rgba(46, 189, 133, .12);
  border-color: rgba(46, 189, 133, .38);
  color: #86e2ba;
}
.btn-save:hover { background: rgba(46, 189, 133, .2); border-color: rgba(46, 189, 133, .65); }

.btn-clear {
  background: rgba(246, 70, 93, .10);
  border-color: rgba(246, 70, 93, .32);
  color: #fca5a5;
}
.btn-clear:hover { background: rgba(246, 70, 93, .18); border-color: rgba(246, 70, 93, .6); }

/* ---------- confirm modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 7, 12, .72);
  backdrop-filter: blur(4px);
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 340px;
  padding: 20px;
  border-radius: 13px;
  background: linear-gradient(150deg, #1a2231 0%, #111622 100%);
  border: 1px solid #2b364c;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .05);
  text-align: center;
}
.modal-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(246, 70, 93, .12);
  border: 1px solid rgba(246, 70, 93, .3);
  color: #fca5a5;
}
.modal-icon svg { width: 20px; height: 20px; }
.modal h3 { margin: 0 0 6px; font-size: 16px; font-weight: 650; }
.modal p { margin: 0 0 18px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .btn { min-width: 82px; }
@media (max-width: 600px) {
  .modal { padding: 16px; max-width: 300px; }
  .modal-actions .btn { min-width: 0; flex: 1; }
}

/* ---------- scrollbars ---------- */
html, body, .table-wrap {
  scrollbar-width: thin;
  scrollbar-color: #34415b transparent;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: #2f3b54;
  border: 2px solid var(--bg);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: #43536f; }
::-webkit-scrollbar-corner { background: var(--bg); }

.table-wrap::-webkit-scrollbar-track { background: var(--card); }
.table-wrap::-webkit-scrollbar-thumb { border-color: var(--card); }
.table-wrap::-webkit-scrollbar-corner { background: var(--card); }

/* ---------- layout ---------- */
main {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 14px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* ---------- interval dropdown (no label text, icon + custom chevron) ---------- */
.selectwrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.selectwrap .sel-clock,
.selectwrap .sel-chev {
  position: absolute;
  width: 14px;
  height: 14px;
  pointer-events: none;
  color: #7f8ca6;
  transition: color .15s;
}
.selectwrap .sel-clock { left: 10px; }
.selectwrap .sel-chev { right: 9px; }
.selectwrap select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  margin: 0;
  padding: 7px 30px;
  border-radius: 9px;
  border: 1px solid #2c3850;
  background: linear-gradient(180deg, #1b2333 0%, #121826 100%);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: .2px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 8px rgba(0, 0, 0, .28);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.selectwrap select:hover {
  border-color: #3d4c6b;
  background: linear-gradient(180deg, #202a3d 0%, #151c2b 100%);
}
.selectwrap select:focus-visible {
  outline: none;
  border-color: rgba(96, 165, 250, .8);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .18), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.selectwrap:hover .sel-clock,
.selectwrap:hover .sel-chev,
.selectwrap:focus-within .sel-clock,
.selectwrap:focus-within .sel-chev { color: #9cc7ff; }
.selectwrap select option { background: #151a26; color: var(--text); }

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

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

thead th {
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  cursor: default;
}
thead th.c-rank { text-align: center; width: 44px; }
thead th.c-asset { text-align: left; }
#liqTable thead th { text-align: right; }
#liqTable thead th.c-asset { text-align: left; }
#liqTable thead th[data-sort="price"] { text-align: center; }
#liqTable thead th[data-sort="trend"] { text-align: center; }

tbody td {
  padding: 11px 10px;
  border-bottom: 1px solid rgba(35, 42, 58, .6);
  text-align: right;
  white-space: nowrap;
  font-size: 13.5px;
}
tbody tr:hover { background: rgba(255, 255, 255, .022); }
td.c-rank { text-align: center; color: var(--muted); }
td.c-asset { text-align: left; }
td.empty { text-align: center; color: var(--muted); padding: 34px; }

.asset { display: inline-flex; align-items: center; gap: 9px; }
.asset img { width: 20px; height: 20px; border-radius: 50%; background: #222; }
.asset .sym { font-weight: 650; }
.asset .nm { color: var(--muted); font-size: 11.5px; }

.pos { color: var(--short); }
.neg { color: var(--long); }

/* Bull & Bear change arrow (vs previous snapshot) */
.bb-arrow { font-size: 10px; line-height: 1; }
/* keep the number right-aligned; arrow sits in a reserved slot */
#historyTable td.bb-cell { position: relative; padding-right: 26px; }
#historyTable td.bb-cell .bb-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}
.bb-arrow.up { color: #2ebd85; }
.bb-arrow.down { color: #f6465d; }

.trend { text-align: center; font-weight: 700; letter-spacing: .3px; padding: 4px 12px; }
thead th[data-sort="trend"] { text-align: center; }
tbody td.trend { text-align: center; }
.trend-up { color: #2ebd85; background: rgba(46, 189, 133, .08); border-radius: 4px; padding: 4px 12px; display: inline-block; }
.trend-down { color: #f6465d; background: rgba(246, 70, 93, .08); border-radius: 4px; padding: 4px 12px; display: inline-block; }

.flash { animation: flash .7s ease-out; }
@keyframes flash {
  from { background: rgba(59, 130, 246, .16); }
  to   { background: transparent; }
}

/* ---------- history / snapshot ---------- */
/* the history card grows to fill the remaining window height */
main > .card { flex: 0 0 auto; }
#historySec {
  margin-top: 18px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#historySec .card-head { flex: 0 0 auto; justify-content: flex-end; }

#historyMeta { white-space: nowrap; }
#historyMeta .snap-count { font-size: 11px; }

.hist-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: auto;
  min-width: 0;
}
.hist-heading h2 { margin: 0; font-size: 15.5px; font-weight: 650; color: var(--text); }
.hist-heading .muted { margin: 0; font-size: 12px; }
.ht-short { display: none; }

#historyTable tbody tr.live-row td {
  background: rgba(59, 130, 246, .10);
  font-weight: 600;
  border-top: 1px solid rgba(59, 130, 246, .35);
  border-bottom: 1px solid rgba(59, 130, 246, .30);
}

/* keep header rows + LIVE row in place while scrolling snapshots */
#historyTable { border-collapse: separate; border-spacing: 0; }
#historySec .table-wrap {
  flex: 1 1 auto;
  min-height: 200px;
  max-height: none;
  overflow-y: auto;
}
#historyTable thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--card);
}
#historyTable thead tr:last-child th {
  position: sticky;
  top: var(--hist-head1, 40px);
  z-index: 8;
  background: var(--card);
}
#historyTable tbody tr.live-row td {
  position: sticky;
  top: var(--hist-head2, 74px);
  z-index: 7;
  background: #16233a;
}
.live-badge {
  background: var(--accent);
  color: #06121f;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 2px 6px;
  border-radius: 4px;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.snap-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

#historyTable thead th { cursor: default; }
#historyTable thead th:hover { color: var(--muted); }
#historyTable thead th.grp {
  text-align: center;
  color: var(--text);
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.grp-inner { display: inline-flex; align-items: center; gap: 6px; }
.grp-text { display: inline-flex; flex-direction: column; align-items: flex-start; }
.grp-logo {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #222;
}
.grp-sym { font-weight: 650; }
.grp-name {
  display: block;
  margin-top: 2px;
  font-size: 8px;
  font-weight: 400;
  letter-spacing: .2px;
  text-align: left;
  color: var(--muted);
}
#historyTable .grp-start {
  border-left: 1px solid var(--line);
}
#historyTable .grp-line {
  border-right: 1px solid rgba(255, 255, 255, .18);
}
#historyTable thead tr:last-child th { border-bottom: 1px solid var(--line); padding-top: 4px; }
#historyTable tbody td { padding: 8px 10px; font-size: 13px; vertical-align: middle; }
#historyTable .c-time { white-space: nowrap; }
#historyTable tbody td.trend { text-align: center !important; }
#historyTable tbody td.trend > span { display: inline-block; }
#historyTable thead th.trend { text-align: center; }
#historyTable .c-rank { text-align: center; color: var(--muted); }

/* white outline: header rows + live row */
#historyTable thead tr:first-child th,
#historyTable thead tr:last-child th,
#historyTable tbody tr.live-row td {
  border-top: 1px solid rgba(255, 255, 255, .28);
  border-bottom: 1px solid rgba(255, 255, 255, .28);
}
#historyTable thead tr:first-child th:first-child,
#historyTable thead tr:last-child th:first-child,
#historyTable tbody tr.live-row td:first-child {
  border-left: 1px solid rgba(255, 255, 255, .28);
}
#historyTable thead tr:first-child th:last-child,
#historyTable thead tr:last-child th:last-child,
#historyTable tbody tr.live-row td:last-child {
  border-right: 1px solid rgba(255, 255, 255, .28);
}

@media (max-width: 860px) {
  #historySec .card-head { flex-wrap: wrap; justify-content: flex-start; }
  .history-controls {
    gap: 8px;
    width: 100%;
  }
  .history-controls .countdown:not(.off) { font-size: 18px; padding: 4px 10px 5px; min-width: 78px; }
  .snap-btns { gap: 6px; margin-left: auto; }
  .snap-btns .btn { padding: 6px 10px; font-size: 11.5px; white-space: nowrap; }
  .selectwrap select { padding: 6px 26px; font-size: 11.5px; }
  .selectwrap .sel-clock,
  .selectwrap .sel-chev { width: 12px; height: 12px; }
  .selectwrap .sel-clock { left: 8px; }
  .selectwrap .sel-chev { right: 7px; }
}

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  body { font-size: 13px; }
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px 6px;
  }
  .brand { min-width: 0; }
  .brand h1 { font-size: 15px; }
  .brand-sub { font-size: 10px; line-height: 1.35; }
  .clock-card { flex: 0 0 auto; gap: 0; padding: 4px 8px; border-radius: 9px; }
  .clock-left, .clock-divider { display: none; }
  .clock-time { font-size: 18px; }
  .clock-time .sec { font-size: 12px; }
  .clock-time .ampm { font-size: 8px; margin-left: 4px; }

  main { padding: 10px 12px 24px; }
  .card { padding: 10px 10px 8px; border-radius: 8px; }
  #historySec { margin-top: 12px; }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  #liqTable { min-width: 880px; }
  #historyTable { min-width: 1080px; }
  #historySec .table-wrap { min-height: 160px; }

  /* freeze assets column while scrolling the table horizontally */
  #liqTable th.c-asset, #liqTable td.c-asset {
    position: sticky;
    left: 0;
    z-index: 3;
    min-width: 76px;
    background: var(--card);
    box-shadow: 2px 0 6px rgba(0, 0, 0, .35);
  }
  #liqTable thead th.c-asset { z-index: 5; }

  /* freeze rank + time in snapshot history while scrolling horizontally */
  #historyTable th.c-rank, #historyTable td.c-rank {
    position: sticky;
    left: 0;
    z-index: 4;
    width: 44px;
    min-width: 44px;
    background: var(--card);
  }
  #historyTable th.c-time-col, #historyTable td.c-time {
    position: sticky;
    left: var(--hist-rank-w, 44px);
    z-index: 3;
    min-width: 100px;
    background: var(--card);
    box-shadow: 2px 0 6px rgba(0, 0, 0, .35);
  }
  #historyTable thead tr:last-child th.c-rank,
  #historyTable thead tr:last-child th.c-time-col { z-index: 10; }
  #historyTable thead tr:first-child th.c-frozen-head {
    position: sticky;
    left: 0;
    z-index: 11;
    background: var(--card);
  }
  #historyTable tbody tr.live-row td.c-rank, #historyTable tbody tr.live-row td.c-time {
    z-index: 10;
    background: #16233a;
  }
  thead th { font-size: 10px; padding: 7px 6px; }
  tbody td { font-size: 12px; padding: 8px 7px; }
  #historyTable tbody td { font-size: 11.5px; padding: 7px 7px; }
  #historyMeta { white-space: normal; }
  .asset { gap: 6px; }
  .asset img { width: 18px; height: 18px; }
  .grp-inner { gap: 4px; }
  .grp-logo { width: 16px; height: 16px; }
  .grp-name { font-size: 7.5px; }
  .asset .nm { display: none; }

  .history-controls { flex-wrap: nowrap; gap: 5px; }
  .hist-heading h2 { font-size: 12.5px; white-space: nowrap; }
  .ht-full { display: none; }
  .ht-short { display: inline; }
  .hist-heading .muted { display: none; }
  .history-controls .countdown:not(.off) { font-size: 15px; padding: 3px 8px 4px; min-width: 0; letter-spacing: .4px; }
  .history-controls .countdown.off { font-size: 9px; }
  .snap-btns { margin-left: auto; gap: 4px; }
  .snap-btns .btn { min-height: 0; padding: 4px 7px; font-size: 10.5px; gap: 4px; }
  .btn-ico { width: 12px; height: 12px; }
  .selectwrap select { min-height: 0; padding: 4px 22px; font-size: 11px; border-radius: 7px; }
  .selectwrap .sel-clock,
  .selectwrap .sel-chev { width: 10px; height: 10px; }
  .selectwrap .sel-clock { left: 6px; }
  .selectwrap .sel-chev { right: 5px; }
}

@media (max-width: 360px) {
  .brand h1 { font-size: 14px; }
  .clock-time { font-size: 16px; }
  .history-controls .countdown:not(.off) { font-size: 14px; padding: 2px 6px 3px; }
  .snap-btns .btn { padding: 4px 5px; }
}
