:root {
  --bg: #0c0e0d;
  --bg-2: #101312;
  --panel: #151817;
  --panel-2: #1e2220;
  --line: #262b29;
  --line-2: #323835;
  --text: #e9ede9;
  --text-dim: #99a099;
  --text-faint: #6c736c;
  --accent: #4caf50;
  --accent-cool: #6fb6ff;
  --tile-radius: 3px;
  --font-ui: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  background-image:
    radial-gradient(120% 80% at 50% -10%, rgba(76,175,80,.05), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  background-attachment: fixed, fixed;
  color: var(--text);
  font: 14px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
body::before {
  /* keep the noise faint so tile colors stay true */
  content: "";
  position: fixed;
  inset: 0;
  background: var(--bg);
  opacity: .945;
  z-index: -1;
  pointer-events: none;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 11px 16px 9px;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.brand-mark { width: 22px; height: 22px; border-radius: 5px; }

.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1.4px;
  white-space: nowrap;
  color: var(--text);
}
.brand h1 span { color: var(--text-faint); font-weight: 600; }

.total {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: -.2px;
  white-space: nowrap;
}
.total b { color: var(--text); font-weight: 600; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

/* search ---------------------------------------------------------------- */
.search-wrap {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  height: 30px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.search-wrap:focus-within {
  border-color: var(--line-2);
  box-shadow: 0 0 0 2px rgba(76,175,80,.18);
}
.search-ico { width: 14px; height: 14px; color: var(--text-faint); flex: none; }
.search {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  width: 150px;
  padding: 0;
  outline: none;
}
.search::placeholder { color: var(--text-faint); }
.search::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--bg-2);
}
.search-wrap:focus-within .search-kbd { display: none; }

/* segmented controls ---------------------------------------------------- */
.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 140ms ease, background-color 140ms ease, box-shadow 140ms ease, transform 140ms var(--ease-out);
}

.seg button:hover { color: var(--text); }
.seg button:active { transform: scale(0.96); }

.seg button.on {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 0 0 1px var(--line-2);
}

.seg-with-aux { display: inline-flex; align-items: center; gap: 5px; }

/* icon buttons ---------------------------------------------------------- */
.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease, transform 140ms var(--ease-out);
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 14px; height: 14px; }

.info-btn {
  width: 22px; height: 22px; padding: 0;
  border-radius: 50%;
  justify-content: center;
  font-family: var(--font-mono);
  font-style: italic;
  font-size: 12px;
  flex: none;
}
.info-btn[aria-expanded="true"] { color: var(--text); border-color: var(--line-2); background: var(--panel-2); }

.palette-btn { padding: 0 8px; gap: 3px; }
.pal-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.pal-a { background: #3e8e49; }
.pal-b { background: #ab3c40; }
.palette-btn[aria-pressed="true"] .pal-a { background: #4f86c6; }
.palette-btn[aria-pressed="true"] .pal-b { background: #cf8a3c; }
.palette-btn[aria-pressed="true"] { border-color: var(--line-2); color: var(--text); }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.check input { accent-color: var(--accent); margin: 0; }

/* legend ---------------------------------------------------------------- */
.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

.legend-bar {
  width: 104px;
  height: 9px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.08);
}

/* popover --------------------------------------------------------------- */
.popover {
  position: absolute;
  top: calc(100% - 2px);
  right: 16px;
  z-index: 60;
  width: min(360px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 14px 16px 13px;
  box-shadow: 0 18px 48px rgba(0,0,0,.6);
  animation: pop-in 160ms var(--ease-out);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-6px); } }
.popover h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .3px; text-transform: uppercase; color: var(--text-faint); }
.popover p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.5; color: var(--text-dim); }
.popover p b { color: var(--text); font-weight: 600; }
.popover .pop-foot { margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--line); font-size: 12px; }

/* crumbs ---------------------------------------------------------------- */
.crumbs {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.crumbs .back {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 3px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms var(--ease-out);
}

.crumbs .back:hover { background: var(--panel-2); }
.crumbs .back:active { transform: scale(0.97); }

.crumbs-path { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs-path b { color: var(--text); font-weight: 600; }
.crumbs-path .crumb { color: var(--text-dim); cursor: pointer; text-decoration: none; transition: color 140ms ease; }
.crumbs-path .crumb:hover { color: var(--text); text-decoration: underline; }
.crumbs-path .crumb-sep { color: var(--text-faint); margin: 0 3px; }
.crumbs-path .crumb-meta { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }

.pm-link {
  color: var(--accent-cool);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
}
.pm-link:hover { text-decoration: underline; }

/* heatmap --------------------------------------------------------------- */
#heatmap {
  position: relative;
  flex: 1;
  margin: 6px 8px;
  min-height: 320px;
  overflow: hidden;
}

.boot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
}
.boot-label { font-family: var(--font-mono); font-size: 12px; letter-spacing: .3px; }

.skeleton {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  grid-template-rows: repeat(3, 64px);
  gap: 6px;
  width: min(520px, 70vw);
}
.skeleton span {
  border-radius: var(--tile-radius);
  background: linear-gradient(100deg, var(--panel) 30%, var(--panel-2) 50%, var(--panel) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.25s var(--ease-in-out) infinite;
  animation-delay: calc(var(--c) * 90ms);
}
.skeleton span:nth-child(1) { grid-row: 1 / 3; }
.skeleton span:nth-child(6) { grid-row: 2 / 4; grid-column: 3; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.empty-note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.boot.error { color: #e08a8a; }

.boot .retry {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms var(--ease-out);
}
.boot .retry:hover { background: var(--panel-2); }
.boot .retry:active { transform: scale(0.97); }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* sections + tiles ------------------------------------------------------ */
.cat {
  position: absolute;
  border-radius: 7px;
  background: rgba(255,255,255,.012);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: left .35s var(--ease-in-out), top .35s var(--ease-in-out),
              width .35s var(--ease-in-out), height .35s var(--ease-in-out),
              opacity .3s ease;
  overflow: hidden;
}
.cat.no-h { box-shadow: none; background: transparent; }

.cat-h {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 22px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  cursor: default;
  user-select: none;
  transition: color 140ms ease;
}

.cat.drill .cat-h { cursor: pointer; }
.cat.drill .cat-h::after {
  content: '›';
  color: var(--text-faint);
  font-weight: 700;
  margin-left: -2px;
  transition: color 140ms ease, transform 140ms var(--ease-out);
}
.cat.drill .cat-h:hover { color: var(--text); }
.cat.drill .cat-h:hover::after { color: var(--text); transform: translateX(2px); }
.cat-h .cat-vol { font-weight: 400; color: var(--text-faint); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0; text-transform: none; }
.cat.no-h .cat-h { display: none; }

.cat-body { position: absolute; left: 0; right: 0; bottom: 0; top: 22px; }
.cat.no-h .cat-body { top: 0; }

.tile {
  position: absolute;
  border-radius: var(--tile-radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.22);
  transition: left .35s var(--ease-in-out), top .35s var(--ease-in-out),
              width .35s var(--ease-in-out), height .35s var(--ease-in-out),
              background-color .35s var(--ease-in-out), opacity .3s ease,
              box-shadow 140ms ease, filter 140ms ease;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(176deg, rgba(255,255,255,.07), rgba(255,255,255,0) 42%, rgba(0,0,0,.12));
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .tile:hover {
    box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.6);
    filter: brightness(1.06);
    z-index: 5;
  }
}
.tile.kb-focus {
  box-shadow: inset 0 0 0 2px var(--accent-cool), 0 0 0 1px var(--accent-cool);
  z-index: 6;
}

.tile-in {
  position: absolute;
  inset: 0;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tile-in.center {
  align-items: center;
  justify-content: center;
  padding: 2px;
}

.tile-title {
  font-weight: 600;
  font-size: 11.5px;
  line-height: 1.25;
  color: rgba(255,255,255,.97);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}

.tile.big .tile-title { font-size: 13px; }
.tile.huge .tile-title { font-size: 17px; letter-spacing: -.2px; }

.tile-price {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,255,255,.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}

.tile.big .tile-price { font-size: 12px; }
.tile.huge .tile-price { font-size: 13.5px; }

.tile-in.center .tile-price { font-size: 10.5px; color: rgba(255,255,255,.88); }

.tile-ico {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: cover;
  margin-bottom: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
  opacity: 0;
  transition: opacity .25s ease;
}
.tile-ico.ld { opacity: 1; }
.tile.huge .tile-ico { width: 30px; height: 30px; }

.tile-bar {
  margin-top: auto;
  height: 4px;
  border-radius: 3px;
  background: rgba(0,0,0,.34);
  overflow: hidden;
}
.tile-bar > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: rgba(255,255,255,.82);
  box-shadow: 0 0 6px rgba(255,255,255,.35);
}
.tile.huge .tile-bar { height: 5px; }

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 16px 9px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--line);
}
#statusRight { text-align: right; }

/* tooltip --------------------------------------------------------------- */
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 320px;
  background: rgba(13, 16, 14, .97);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 10px 32px rgba(0,0,0,.55);
}

.tooltip .tt-title { font-weight: 700; margin-bottom: 2px; }
.tooltip .tt-sub { color: var(--text-dim); margin-bottom: 7px; font-size: 11.5px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 18px; font-family: var(--font-mono); font-size: 11.5px; }
.tooltip .tt-row span:first-child { color: var(--text-dim); font-family: var(--font-ui); }
.tooltip .pos { color: #6fce77; }
.tooltip .neg { color: #e88588; }

/* overlay card ---------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}
.overlay.open { opacity: 1; }

.card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,.65);
  position: relative;
  transform: scale(0.96);
  opacity: 0;
  transition: transform 220ms var(--ease-out), opacity 220ms var(--ease-out);
}
.overlay.open .card { transform: scale(1); opacity: 1; }

.card .x {
  position: absolute;
  top: 12px; right: 14px;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 120ms ease;
}
.card .x:hover { color: var(--text); }

.card-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
  padding-right: 22px;
}

.card-head img {
  width: 44px;
  height: 44px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
}

.card-head h2 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 700; letter-spacing: -.2px; }
.card-head .sub { color: var(--text-dim); font-size: 12.5px; margin-top: 4px; }

.card-big {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.card-big .price { font-family: var(--font-mono); font-size: 32px; font-weight: 600; letter-spacing: -1px; }
.card-big .chg { font-family: var(--font-mono); font-size: 13.5px; font-weight: 500; }
.card-big .chg.pos { color: #6fce77; }
.card-big .chg.neg { color: #e88588; }
.card-big .chg.flat { color: var(--text-dim); }
.card-big .live-badge {
  margin-left: auto;
  align-self: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .3px;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
@media (prefers-reduced-motion: no-preference) {
  .card-big .live-badge { animation: live-pulse 2s ease-in-out infinite; }
}
@keyframes live-pulse { 50% { opacity: .55; } }

/* sparkline ------------------------------------------------------------- */
.card-spark {
  position: relative;
  height: 64px;
  margin-bottom: 14px;
  border-radius: 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.card-spark svg { display: block; width: 100%; height: 100%; }
.card-spark .spark-loading,
.card-spark .spark-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.card-spark .spark-range {
  position: absolute;
  top: 5px; left: 8px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--text-faint);
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 9px;
  margin-bottom: 16px;
}

.card-grid .cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
}

.card-grid .k { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .4px; }
.card-grid .v { font-family: var(--font-mono); font-size: 13px; font-weight: 500; margin-top: 3px; }
.card-grid .v.pos { color: #6fce77; }
.card-grid .v.neg { color: #e88588; }

.card-actions { display: flex; gap: 10px; }

.card-actions a, .card-actions button {
  flex: 1;
  text-align: center;
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: filter 140ms ease, transform 140ms var(--ease-out);
}

.card-actions a.primary {
  background: #2d5e91;
  border-color: #3a76b5;
}

.card-actions a:hover, .card-actions button:hover { filter: brightness(1.15); }
.card-actions a:active, .card-actions button:active { transform: scale(0.97); }

/* toast ----------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  opacity: 0;
  z-index: 200;
  background: #16241a;
  border: 1px solid #2c4733;
  color: #bfe6c8;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  transition: transform 280ms var(--ease-out), opacity 280ms var(--ease-out);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.err { background: #3a2326; border-color: #5c3236; color: #f0c9cb; }

/* focus ----------------------------------------------------------------- */
.seg button:focus-visible,
.icon-btn:focus-visible,
.crumbs .back:focus-visible,
.crumbs-path .crumb:focus-visible,
.boot .retry:focus-visible,
.card-actions a:focus-visible,
.card-actions button:focus-visible,
.card .x:focus-visible,
.pm-link:focus-visible,
.check input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .cat, .tile {
    transition: background-color .3s ease, opacity .3s ease;
  }
  .tile.kb-focus { z-index: 6; }
  .card { transform: none; transition: opacity 150ms ease; }
  .overlay.open .card { transform: none; }
  .toast { transform: translateX(-50%); transition: opacity 200ms ease; }
  .toast.show { transform: translateX(-50%); }
  .skeleton span { animation-duration: 2.4s; }
  .popover { animation: none; }
  .seg button:active,
  .icon-btn:active,
  .crumbs .back:active,
  .boot .retry:active,
  .card-actions a:active,
  .card-actions button:active { transform: none; }
  .spinner { animation-duration: 1.2s; }
}

@media (max-width: 820px) {
  .topbar { padding: 9px 12px 7px; }
  .search { width: 110px; }
  #heatmap { margin: 4px; }
  .statusbar { font-size: 10px; }
  /* legend collapses to just the gradient key, label hidden */
  .legend-min, .legend-max { display: none; }
  .legend-bar { width: 72px; }
  .popover { right: 12px; }
}
