:root {
  --bg: #f3e9dc;
  --bg-2: #ebdfcf;
  --panel: #f7f0e6;
  --tile: #efe5d8;
  --ink: #2c221c;
  --ink-2: #6f5f52;
  --line: #cdbca9;
  --accent: #8f5c4b;
  --accent-ink: #fbf3ea;
  --good: #1f9e57;
  --pixel: "Silkscreen", monospace;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 14px/1.4 var(--mono);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- marquee ---------- */
.marquee {
  background: var(--ink);
  color: #f3e9dc;
  font: 400 12px/1 var(--pixel);
  letter-spacing: .08em;
  overflow: hidden;
  white-space: nowrap;
  padding: 7px 0;
}
.mq { display: inline-flex; gap: 18px; animation: mq 40s linear infinite; padding-left: 18px; }
.mq i { color: #d8a468; font-style: normal; }
.mq span:first-child { color: #5ce08f; }
@keyframes mq { to { transform: translateX(-50%); } }

/* ---------- header ---------- */
.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 18px 28px 6px;
}
.brand {
  color: var(--ink-2);
  text-decoration: none;
  letter-spacing: .12em;
  font-size: 15px;
}
.title {
  margin: 0;
  font: 700 clamp(30px, 5.4vw, 64px)/1 var(--pixel);
  text-transform: uppercase;
  letter-spacing: .02em;
  text-align: center;
  color: var(--ink);
  text-shadow: 3px 3px 0 #d8c6b0;
  white-space: nowrap;
}
.ca {
  justify-self: end;
  text-decoration: none;
  white-space: nowrap;
  background: transparent;
  border: 2px solid var(--line);
  padding: 6px 10px;
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--ink-2);
}
.ca:hover { border-color: var(--accent); color: var(--ink); }
.ca-val { color: var(--accent); font-weight: 600; }

/* ---------- stage ---------- */
main { flex: 1; display: flex; flex-direction: column; align-items: center; width: 100%; }
.stage-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 10px 16px 0;
}
.skyline {
  position: absolute;
  inset: auto 0 0 0;
  height: 60%;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(0,0,0,.02), transparent),
    var(--skyline) repeat-x bottom / auto 100%;
  opacity: .9;
}
.stage {
  position: relative;
  width: min(44vh, 440px, calc(100vw - 32px));
  aspect-ratio: 1;
  z-index: 1;
}
.stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 rgba(44, 34, 28, .18);
  background: var(--tile);
}
.stage.shake { animation: shake .35s steps(4); }
@keyframes shake {
  25% { transform: translate(-4px, 2px) rotate(-1deg); }
  50% { transform: translate(4px, -2px) rotate(1deg); }
  75% { transform: translate(-2px, 0); }
}
.stage-tag {
  position: absolute;
  left: -4px;
  bottom: -18px;
  background: var(--ink);
  color: #f3e9dc;
  font: 400 12px/1 var(--pixel);
  letter-spacing: .08em;
  padding: 7px 10px;
}

/* ---------- panel ---------- */
.panel {
  position: relative;
  z-index: 2;
  width: min(1180px, calc(100% - 24px));
  margin: 30px auto 0;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 14px 18px 18px;
}
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 12px;
  border-bottom: 2px solid #e6dacb;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #f0e6d9;
  border: 2px solid #e2d5c4;
  border-radius: 4px;
  padding: 5px 12px 5px 6px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.tab:hover { border-color: var(--line); }
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab-ico canvas { width: 24px; height: 24px; display: block; border-radius: 3px; background: var(--tile); }
.tab.on .tab-ico canvas { outline: 2px solid rgba(255,255,255,.35); }

.group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 12px 4px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
}
.group-value { color: var(--accent); font-weight: 600; }
.hint { margin-left: auto; font-size: 11px; opacity: .75; text-transform: none; letter-spacing: 0; }

.row-wrap { display: flex; align-items: center; gap: 10px; }
.arrow {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--tile);
  border: 2px solid var(--line);
  border-radius: 4px;
}
.arrow svg { width: 20px; height: 20px; fill: var(--ink); }
.arrow:hover { border-color: var(--accent); }
.row {
  flex: 1;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.tile {
  flex: none;
  position: relative;
  width: 104px;
  scroll-snap-align: start;
  background: var(--tile);
  border: 2px solid #ddcfbe;
  border-radius: 4px;
  padding: 4px 4px 0;
  transition: transform .08s steps(2);
}
.tile canvas { width: 92px; height: 92px; display: block; margin: 0 auto; }
.tile-name {
  display: block;
  font-size: 10px;
  line-height: 1.2;
  padding: 4px 0 5px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile:hover { border-color: var(--line); transform: translateY(-2px); }
.tile.on { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.tile.on .tile-name { color: var(--accent); font-weight: 600; }

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 150px;
  justify-content: center;
  padding: 12px 22px;
  background: #efe5d8;
  border: 2px solid var(--line);
  border-radius: 4px;
  font: 400 17px/1 var(--pixel);
  text-transform: uppercase;
  letter-spacing: .06em;
  box-shadow: 0 4px 0 #d9cab7;
  transition: transform .06s, box-shadow .06s;
}
.btn svg { width: 22px; height: 22px; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9cab7; }
.btn.primary { background: var(--accent); border-color: #7a4b3c; color: var(--accent-ink); box-shadow: 0 4px 0 #6d4234; min-width: 240px; }
.btn.primary:active { box-shadow: 0 1px 0 #6d4234; }
.btn.ghost { min-width: 0; background: transparent; box-shadow: none; color: var(--ink-2); }

/* ---------- footer ---------- */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px 28px 22px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.nfa { text-transform: none; letter-spacing: 0; opacity: .7; }
.tip {
  display: inline-flex; align-items: center; gap: 10px;
  background: none; border: 0; text-align: left;
  font-size: 11px; color: var(--ink-2);
}
.tip svg { width: 26px; height: 24px; color: var(--ink); }
.tip b { font-weight: 500; letter-spacing: .08em; }
.tip-addr { word-break: break-all; text-transform: none; }
.tip:hover .tip-addr { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #f3e9dc;
  padding: 10px 16px;
  font: 400 13px/1 var(--pixel);
  letter-spacing: .06em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body:not(.ready) .panel, body:not(.ready) .stage { opacity: 0; }
.panel, .stage { transition: opacity .3s; }

/* header gets crowded once Buy/Chart/CA sit next to the title */
@media (max-width: 1180px) {
  .top { grid-template-columns: 1fr auto; }
  .title { grid-column: 1 / -1; grid-row: 2; margin-top: 4px; }
}

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .top { grid-template-columns: 1fr auto; padding: 14px 16px 4px; }
  .title { grid-column: 1 / -1; grid-row: 2; font-size: clamp(20px, 7.4vw, 40px); margin-top: 6px; white-space: normal; letter-spacing: 0; }
  .panel { padding: 10px 10px 14px; width: calc(100% - 16px); }
  .arrow { display: none; }
  .tab { flex: none; }
  .tile { width: 88px; }
  .tile canvas { width: 76px; height: 76px; }
  .hint { display: none; }
  .btn { min-width: 0; flex: 1 1 40%; padding: 12px 10px; font-size: 14px; }
  .btn.primary { min-width: 0; flex-basis: 100%; }
  .foot { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .mq { animation: none; }
  .stage.shake { animation: none; }
}

[hidden] { display: none !important; }

.tab.muted:not(.on) { opacity: .45; }
