:root {
  --bg: #0A0A08;
  --amber: #FFB000;
  --amber-hi: #FFD066;
  --dim: #A8812A;
  --muted: #5E4A1A;
  --line: #2E2A1C;
  --box: #3A3424;
  --up: #3DDC84;
  --down: #FF5C5C;
  --pad: clamp(12px, 1.5vw, 20px);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--amber);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font: inherit; color: inherit; }

.dim { color: var(--dim); }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

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

.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.show-sm { display: none; }

/* ---------- frame ---------- */

.term {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  height: 44px;
  padding: 0 var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--amber);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.topbar > div { display: flex; align-items: center; gap: 14px; min-width: 0; }
#clock { font-variant-numeric: tabular-nums; }

.sound-btn {
  min-width: 44px;
  min-height: 34px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid var(--bg);
  background: transparent;
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}
.sound-btn:hover { background: var(--bg); color: var(--amber); }
.sound-btn:focus-visible { outline: 2px solid var(--bg); outline-offset: 2px; }
.sound-btn .snd-off, .sound-btn[aria-pressed="false"] .snd-on { display: none; }
.sound-btn[aria-pressed="false"] .snd-off { display: inline; }

.ticker {
  flex: none;
  height: 36px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.ticker-track { display: flex; width: max-content; animation: marquee 45s linear infinite; }
.ticker-list { display: flex; gap: 56px; margin: 0; padding: 0 28px; list-style: none; }
@keyframes marquee { to { transform: translateX(-50%); } }

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr) minmax(280px, 340px);
  gap: 1px;
  background: var(--line);
}

.panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
}

.panel-title {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--dim);
}

/* ---------- asset panel ---------- */

.logo-box {
  position: relative;
  flex: none;
  height: clamp(110px, 18vh, 170px);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--box);
}
.logo-box img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px);
}
.corner { position: absolute; width: 16px; height: 16px; border: 0 solid var(--amber); }
.corner.tl { left: -1px; top: -1px; border-left-width: 3px; border-top-width: 3px; }
.corner.tr { right: -1px; top: -1px; border-right-width: 3px; border-top-width: 3px; }
.corner.bl { left: -1px; bottom: -1px; border-left-width: 3px; border-bottom-width: 3px; }
.corner.br { right: -1px; bottom: -1px; border-right-width: 3px; border-bottom-width: 3px; }

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  row-gap: 6px;
}
.kv dt { color: var(--dim); }
.kv dd { margin: 0; }
#status.down, #status.down * { color: var(--down); }
#status.wait, #status.wait * { color: var(--amber); }
.odor { display: flex; align-items: center; gap: 3px; }
.odor i { width: 12px; height: 14px; background: var(--amber); }
.odor i.hot { background: var(--down); }

.badge {
  flex: none;
  padding: 1px 6px;
  background: var(--down);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* bundle check: the dev's linked wallets, selling into the dump */
.bundle {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.bundle-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bundle-sub { margin: 0; font-size: 11px; line-height: 1.5; letter-spacing: 0.5px; color: var(--down); }

.bt-cols, .bt li, .bt-total {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 60px 64px;
  gap: 6px;
  align-items: center;
  font-size: 12px;
}
.bt-cols { padding: 0 6px; font-size: 10px; letter-spacing: 1px; color: var(--dim); }
.bt-cols span:not(:first-child), .bt .s, .bt .p, .bt-total span:not(:first-child) { text-align: right; }
.bt {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.bt li { position: relative; flex: none; height: 26px; padding: 0 6px; white-space: nowrap; }
.bt li > span { position: relative; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.bt li i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--pct) * 4.6%);
  background: rgba(255, 176, 0, 0.13);
  border-left: 2px solid var(--amber);
}
.bt .p { color: var(--dim); }
.bt li.selling { background: rgba(255, 92, 92, 0.2); }
.bt li.selling i { background: rgba(255, 92, 92, 0.28); border-left-color: var(--down); }
.bt li.selling .s { color: var(--down); font-weight: 700; }
.bt li.selling .p { color: var(--up); }
.bt li.sold i { display: none; }
.bt li.sold .w { color: var(--dim); text-decoration: line-through; }
.bt li.sold .s { color: var(--down); font-weight: 700; }
.bt li.sold .p { color: var(--up); font-weight: 700; }
.bt li.hit { animation: hit 0.5s ease-out; }
@keyframes hit { from { background: var(--down); } to { background: transparent; } }
.bt-total { flex: none; padding: 8px 6px 0; border-top: 1px solid var(--line); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- chart panel ---------- */

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 20px;
}
.chart-logo { display: none; width: 52px; height: 52px; object-fit: contain; }
.chart-title { margin-right: auto; }
.chart-title .sub { font-size: 13px; letter-spacing: 2px; color: var(--dim); }
.chart-title h1 {
  margin: 2px 0 0;
  font-size: clamp(44px, 5.4vw, 80px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}
.px {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* one-line bundle summary, shown when the asset panel is hidden */
.bundle-strip {
  display: none;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--box);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.bs-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bs-pnl { margin-left: auto; font-weight: 700; }
.bundle-strip.dumping { border-color: var(--down); background: rgba(255, 92, 92, 0.12); }
.bundle-strip.dumping .bs-text { color: var(--down); }
.bundle-strip.hit { animation: hit 0.5s ease-out; }

/* phone view switcher: CHART | BUNDLE | $POOVAL (hidden on wider screens) */
.m-tabs { display: none; border: 1px solid var(--box); }
.m-tabs button {
  flex: 1;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}
.m-tabs button + button { border-left: 1px solid var(--box); }
.m-tabs button[aria-selected="true"] { background: var(--amber); color: var(--bg); }
.m-tabs button:focus-visible { outline: 2px solid var(--amber-hi); outline-offset: -4px; }
.m-dot { display: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.m-tabs .alert .m-dot { display: inline-block; animation: blink 1s steps(1) infinite; }
.m-tabs .alert:not([aria-selected="true"]) { color: var(--down); }
.m-tabs .alert[aria-selected="true"] { background: var(--down); }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 120px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.flash { position: absolute; inset: 0; background: var(--down); opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.6s ease-out; }
@keyframes flash { from { opacity: 0.45; } to { opacity: 0; } }

.chart-wrap.shake { animation: shake 0.45s linear; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, 4px); }
  20% { transform: translate(7px, -5px); }
  30% { transform: translate(-6px, -3px); }
  40% { transform: translate(6px, 5px); }
  50% { transform: translate(-4px, 2px); }
  60% { transform: translate(4px, -3px); }
  70% { transform: translate(-3px, 2px); }
  80% { transform: translate(2px, -1px); }
  90% { transform: translate(-1px, 1px); }
}

.stamp {
  position: absolute;
  left: 50%;
  top: 42%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 26px 12px;
  border: 6px solid var(--down);
  background: rgba(10, 10, 8, 0.75);
  color: var(--down);
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-8deg);
}
.stamp span { font-size: clamp(36px, 6vw, 84px); line-height: 1; letter-spacing: 0.06em; }
.stamp small { margin-top: 6px; font-size: clamp(14px, 1.6vw, 20px); }
.stamp.show { animation: stamp 0.35s cubic-bezier(0.2, 1.6, 0.4, 1) forwards; }
@keyframes stamp {
  from { opacity: 0; transform: translate(-50%, -50%) rotate(-8deg) scale(2); }
  to { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(1); }
}

.footnote { margin: 0; font-size: 12px; color: var(--dim); }

/* ---------- order panel ---------- */

.ticket { border: 1px solid var(--box); }
.ticket .row {
  min-height: 42px;
  padding: 5px 6px 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.ticket .row:last-child { border-bottom: 0; }

.ca-btn {
  min-height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--amber);
  background: transparent;
  font-size: 13px;
  cursor: pointer;
}
.ca-btn:hover { background: var(--amber); color: var(--bg); }
.ca-pending { padding-right: 6px; font-size: 13px; color: var(--dim); }

.exec {
  min-height: 80px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--amber);
  color: var(--bg);
  font-size: clamp(18px, 1.7vw, 24px);
  font-weight: 700;
  letter-spacing: 2px;
  white-space: nowrap;
  text-decoration: none;
}
.exec:hover { background: var(--amber-hi); }
.exec.is-pending { background: transparent; color: var(--amber); border: 2px dashed var(--amber); cursor: default; }
.cursor { display: inline-block; width: 0.55em; height: 1em; margin-left: 6px; background: currentColor; }
.route { margin: -6px 0 0; font-size: 12px; color: var(--dim); }

.ratings-title { margin-top: 8px; }
.ratings { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.ratings li { display: flex; justify-content: space-between; gap: 12px; }

/* live token data (real, from /api/token) */
.live {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.live-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.live-status {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--dim);
  color: var(--dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}
.live-status.is-live { border-color: var(--up); color: var(--up); }
.live-status.is-live::before { content: "● "; animation: blink 1.2s steps(1) infinite; }
.live-status.is-down { border-color: var(--down); color: var(--down); }

.stats {
  margin: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 5px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.stats dt { color: var(--dim); }
.stats dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.th-cols { display: flex; justify-content: space-between; padding: 0 6px; font-size: 10px; letter-spacing: 1px; color: var(--dim); }
.th {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--box) transparent;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.th li {
  position: relative;
  flex: none;
  height: 19px;
  padding: 0 6px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.th li > * { position: relative; overflow: hidden; text-overflow: ellipsis; }
.th li i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--w, 0%);
  background: rgba(255, 176, 0, 0.12);
  border-left: 2px solid var(--amber);
}
.th .rank { color: var(--dim); }
.th a { text-decoration: none; }
.th a:hover { color: var(--amber-hi); text-decoration: underline; }
.th .tag { color: var(--dim); }
.th li.th-empty { display: block; height: auto; padding: 6px; color: var(--dim); }

.live-mini { display: none; gap: 14px; font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; }
.live-mini b { color: var(--amber); font-weight: 600; }

.exec:focus-visible, .ca-btn:focus-visible, .key:focus-visible, .th a:focus-visible {
  outline: 2px solid var(--amber-hi);
  outline-offset: 3px;
}

/* ---------- footer ---------- */

.keys {
  flex: none;
  height: 46px;
  padding: 0 var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}
.keys nav { display: flex; align-items: center; gap: 20px; }
.key {
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  text-decoration: none;
  cursor: pointer;
}
.key:hover { color: var(--amber-hi); }
kbd { padding: 1px 6px; background: var(--amber); color: var(--bg); font: inherit; font-weight: 700; }
.nfa { color: var(--dim); overflow: hidden; text-overflow: ellipsis; }

/* ---------- responsive ---------- */

@media (max-height: 760px) {
  .ratings, .ratings-title, .kv .opt, .bundle-sub { display: none; }
  .logo-box { height: clamp(90px, 16vh, 130px); }
  .bt li { height: 24px; }
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(270px, 320px); }
  .asset { display: none; }
  .chart-logo { display: block; }
  .bundle-strip { display: flex; }
  .ratings, .ratings-title { display: none; }
  .hide-md { display: none; }
}

@media (max-width: 760px) {
  body { font-size: 13px; }
  .topbar { height: 40px; font-size: 13px; }
  .ticker { height: 32px; font-size: 12px; }
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .panel { gap: 10px; }
  .order .panel-title, .ticket .hide-sm, .route, .ratings, .ratings-title, .live { display: none; }
  .live-mini { display: flex; }
  .chart-head { align-items: center; gap: 8px 12px; }
  .chart-logo { width: 44px; height: 44px; }
  .chart-title h1 { font-size: 40px; }
  .px { width: 100%; flex-direction: row; gap: 16px; text-align: left; }
  .chart-wrap { min-height: 90px; }
  .footnote { font-size: 10px; }
  .exec { min-height: 60px; font-size: 20px; }
  .bundle-strip { padding-left: 10px; }
  .bundle-strip .badge { display: none; }
  .keys { font-size: 12px; }
  .hide-sm { display: none; }
  .show-sm { display: inline; }
}

/* phones: the bundle table and live data are moved into the stage (app.js)
   and the tabs pick which of the three fills it */
@media (max-width: 760px) {
  .m-tabs { display: flex; }
  .stage > .bundle, .stage > .live {
    display: none;
    flex: 1;
    min-height: 0;
    padding: 10px;
    border: 1px solid var(--line);
  }
  .term[data-view="bundle"] .stage > .chart-wrap,
  .term[data-view="token"] .stage > .chart-wrap { display: none; }
  .term[data-view="bundle"] .stage > .bundle,
  .term[data-view="token"] .stage > .live { display: flex; }
  .term:not([data-view="chart"]) .bundle-strip,
  .term[data-view="token"] .live-mini { display: none; }
  /* rows that don't fit scroll inside their box; the page itself never scrolls */
  .stage .bt { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
}

/* short phones: give the bundle and holder lists the room they need */
@media (max-width: 760px) and (max-height: 700px) {
  .term:not([data-view="chart"]) .ticker,
  .term:not([data-view="chart"]) .footnote,
  .term:not([data-view="chart"]) .chart-head .sub,
  .term:not([data-view="chart"]) .bundle-sub,
  .term:not([data-view="chart"]) .live-mini { display: none; }
  .exec { min-height: 52px; }
  .term:not([data-view="chart"]) .chart-title h1 { font-size: 32px; }
  .term:not([data-view="chart"]) .chart-logo { width: 36px; height: 36px; }
}

@media (max-height: 520px) {
  .ticker, .footnote, .chart-head .sub { display: none; }
  .exec { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track, .blink, .bt li.hit, .bundle-strip.hit, .m-tabs .alert .m-dot { animation: none; }
  .stamp.show { animation: none; opacity: 1; }
}
