/* Dataset browser for the Hugging Face Space. Same showroom as the labs viewer. */

:root {
  --ink: #0b0b0b;
  --ink-muted: #5c5c5c;
  --paper: #fff;
  --paper-2: #f2f2f2;
  --line: #e3e3e3;
  --line-dark: rgba(255, 255, 255, 0.14);
  --green: #22c55e;
  --green-ink: #15803d;
  --error: #b42318;
  --focus: var(--green-ink);
  --max: 1240px;
  --gutter: clamp(16px, 4vw, 48px);
  --edge: max(var(--gutter), calc((100% - var(--max)) / 2));
  --section: clamp(72px, 9vw, 128px);
  --bar: 64px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: Bungee, var(--font);
  --arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M2.5 8h11M9 3.5 13.5 8 9 12.5'/></svg>");
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: var(--bar);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

h1,
h2,
h3 {
  font-weight: 500;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.5rem, 5.5vw, 4.75rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.875rem, 3.5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

h3 {
  font-size: 1.375rem;
  line-height: 1.3;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.foot {
  --focus: var(--green);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  z-index: 60;
  top: -64px;
  left: 16px;
  padding: 10px 14px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
}

.skip:focus {
  top: 12px;
}

.lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-family: var(--display);
  font-size: 1.1875rem;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.02em;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.lockup-crate {
  flex: none;
  width: 1.4em;
  height: 1.4em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 22px;
  border: 0;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font: 500 16px/1.25 var(--font);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  background: #333;
}

.btn--secondary {
  background: var(--paper-2);
  color: var(--ink);
}

.btn--secondary:hover {
  background: var(--line);
}

.arrow {
  flex: none;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--arrow) center / contain no-repeat;
  mask: var(--arrow) center / contain no-repeat;
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
}

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: var(--bar);
  padding: 0 var(--edge);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.topbar .lockup {
  grid-column: 2;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}

.topbar-link:hover {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.topbar-datasets {
  grid-column: 1;
  justify-self: start;
  white-space: nowrap;
}

.datasets-short {
  display: none;
}

.topbar-cta {
  grid-column: 3;
  justify-self: end;
}

.datasets {
  padding: calc(var(--bar) + clamp(32px, 5vw, 72px)) var(--edge) var(--section);
}

.datasets h1 {
  max-width: 18em;
}

.lead {
  max-width: 40rem;
  margin-top: 16px;
  color: var(--ink-muted);
  font-size: 1.125rem;
}

.dataset-card {
  max-width: 920px;
  margin-top: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.dataset-card-link {
  display: block;
  padding: clamp(20px, 3vw, 32px);
  text-decoration: none;
}

.dataset-card-link:hover {
  background: var(--paper-2);
}

.kicker {
  color: var(--green-ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dataset-card h2 {
  margin-top: 8px;
}

.dataset-card-link > p {
  max-width: 40rem;
  margin-top: 12px;
  color: var(--ink-muted);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 28px;
  margin-top: 24px;
  padding: 0;
  list-style: none;
}

.stats b {
  display: block;
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.stats span {
  color: var(--ink-muted);
  font-size: 13px;
}

.browse {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  font-weight: 500;
}

.source {
  margin: 0;
  padding: 0 clamp(20px, 3vw, 32px) 8px;
}

#browser,
.viewer {
  max-width: 920px;
}

#browser > #session-status {
  margin-top: 12px;
  color: var(--ink-muted);
}

#session-status:empty {
  display: none;
}

.explorer {
  margin-top: 28px;
  border-top: 1px solid var(--line);
}

.folder {
  border-bottom: 1px solid var(--line);
}

.folder-name {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 16px 8px 8px;
  font-size: 1.05rem;
}

.folder-name .arrow {
  transform: rotate(90deg);
}

.folder-files {
  margin: 0;
  padding: 0 0 8px 28px;
  list-style: none;
}

.folder-files a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 10px 8px;
  color: inherit;
  text-decoration: none;
}

.folder-files a:hover {
  background: var(--paper-2);
}

.session-meta {
  color: var(--ink-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.viewer-back {
  margin-bottom: 16px;
}

.viewer-back a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 500;
  text-decoration: none;
}

.viewer-back a:hover {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.viewer-back .arrow {
  transform: rotate(180deg);
}

.viewer-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 8px;
}

.viewer-meta {
  color: var(--ink-muted);
}

.viewer-source {
  margin: 0;
}

.viewer-source .text-link {
  min-height: 0;
  font-size: 14px;
}

.stage {
  position: relative;
  margin-top: 20px;
  overflow: hidden;
  border-radius: 4px;
  background: #111;
  aspect-ratio: 16 / 9;
}

.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.cursor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #111;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9), 0 0 10px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.cursor.down {
  background: var(--green);
  box-shadow: 0 0 0 2px #fff, 0 0 12px rgba(34, 197, 94, 0.85);
}

.hud {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

.hud-wasd,
.hud-mouse,
.hud-extra {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.hud-wasd {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 40px);
}

.hud span {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  font-weight: 500;
}

.hud-wasd [data-key="W"] {
  grid-column: 2;
}

.hud-wasd [data-key="A"] {
  grid-row: 2;
  grid-column: 1;
}

.hud-wasd [data-key="S"] {
  grid-row: 2;
  grid-column: 2;
}

.hud-wasd [data-key="D"] {
  grid-row: 2;
  grid-column: 3;
}

.hud span.on {
  border-color: #fff;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.55);
}

.hud span.down {
  box-shadow: 0 0 0 2px var(--green), 0 0 18px rgba(34, 197, 94, 0.45);
}

.hud span.up {
  border-style: dashed;
  color: #fff;
}

.hud span.hud-delta {
  display: flex;
  gap: 0.35em;
  width: auto;
  height: 28px;
  padding: 0 10px;
  font: 500 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

.hud span.hud-delta.on {
  border-color: #fff;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  box-shadow: none;
}

.hud-delta i {
  font-style: normal;
  opacity: 0.65;
}

.hud-delta b {
  min-width: 3ch;
  font-weight: inherit;
  text-align: right;
}

.stage-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  text-align: center;
}

.stage-message a {
  color: #fff;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.transport .btn {
  min-height: 44px;
  padding: 10px 16px;
}

.transport :disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.frame-counter {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin-top: 10px;
  color: var(--ink-muted);
  font-size: 14px;
}

.foot {
  padding: clamp(56px, 6vw, 88px) var(--edge) 48px;
  background: var(--ink);
  color: #fff;
}

.foot-inner {
  max-width: var(--max);
  margin: 0 auto;
}

.foot .lockup {
  font-size: 1.25rem;
}

.foot-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
  margin-top: 48px;
  padding-top: 40px;
  border-top: 1px solid var(--line-dark);
  font-size: 15px;
}

.foot-title {
  margin-bottom: 12px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 14px;
}

.foot-cols div a {
  display: block;
  width: fit-content;
  padding: 4px 0;
  text-decoration: none;
}

.foot-cols div a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

@media (max-width: 720px) {
  :root {
    --bar: 56px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
  }

  .topbar-datasets,
  .topbar-cta {
    font-size: 13px;
  }

  .topbar .lockup {
    font-size: 0.8125rem;
  }

  .foot-cols {
    grid-template-columns: 1fr;
    gap: 28px;
  }
}

@media (max-width: 540px) {
  .datasets-full {
    display: none;
  }

  .datasets-short {
    display: inline;
  }

  .hud-wasd {
    grid-template-columns: repeat(3, 32px);
    grid-template-rows: repeat(2, 32px);
  }

  .hud span {
    min-width: 32px;
    height: 32px;
    font-size: 12px;
  }
}

.mcap {
  margin-top: 28px;
}

.mcap-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
}

#mcap-status {
  color: var(--ink-muted);
}

#mcap-status.is-error {
  color: var(--error);
}

.mcap-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 16px;
  margin-top: 12px;
}

.mcap-channels {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px 12px 8px;
}

.mcap-channels legend {
  padding: 0 4px;
  font-size: 13px;
  font-weight: 500;
}

.mcap-channels label {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  column-gap: 8px;
  row-gap: 1px;
  align-items: start;
  padding: 6px 0;
  font-size: 12px;
}

.mcap-channels input {
  grid-row: 1 / span 2;
  margin: 2px 0 0;
}

.mcap-channel-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.3;
}

.mcap-channel-note {
  color: var(--ink-muted);
  line-height: 1.35;
}

.mcap-readout {
  min-width: 0;
  max-height: 460px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.mcap-card {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  transition: opacity 120ms ease;
}

.mcap-card.is-stale {
  opacity: 0.45;
}

.mcap-topic {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 500;
}

.mcap-when,
.mcap-empty {
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 13px;
}

.mcap-card dl {
  margin-top: 8px;
  font-size: 13px;
}

.mcap-field {
  display: grid;
  grid-template-columns: minmax(7rem, 11rem) minmax(0, 1fr);
  gap: 1px 12px;
  padding: 7px 0 2px;
}

.mcap-field-note {
  grid-column: 1 / -1;
  margin: 0 0 4px;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.35;
}

.mcap-card dt {
  color: var(--ink-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.mcap-card dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .mcap-layout {
    grid-template-columns: 1fr;
  }
}
