/* kg-to-3d web viewer. Warm dark "architect's model" look, same palette as the video. */

@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #16130F;
  --ground: #1D1914;
  --text: #F5EFE4;
  --card: #2A231C;
  --card-border: #CDBFA6;
  --liquid: #FFB547;
  --gas: #CFE6F2;
  --loop: #7FD6CB;
  --muted: #CDBFA6;
  --glass: rgba(42, 35, 28, 0.8);
  --glass-line: rgba(205, 191, 166, 0.28);
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --pad: 12px;
  --ease: cubic-bezier(0.3, 0.1, 0.2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-weight: 600;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: fixed;
  inset: 0;
  background: var(--bg);
}
#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

/* ---------- 3D labels (CSS2DRenderer), real HTML text ---------- */

#labels {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#labels > div { pointer-events: none; }

.anchor {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}
.tag {
  position: absolute;
  left: 0;
  bottom: 14px;
  white-space: nowrap;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.02em;
  color: var(--text);
  background: rgba(42, 35, 28, 0.9);
  border: 1px solid rgba(205, 191, 166, 0.34);
  border-radius: 7px;
  padding: 3px 8px 3px 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.22s linear, visibility 0s linear 0s;
}
.tag::after {
  content: "";
  position: absolute;
  left: calc(var(--lx, 50%) - 1px);
  top: 100%;
  width: 1px;
  height: 14px;
  background: rgba(205, 191, 166, 0.55);
}
.tag .pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.tag:not(.is-end) .pip { display: none; }
.tag.is-end {
  font-size: 12px;
  line-height: 18px;
  border-color: var(--c, var(--muted));
  background: #342B22;
}
.tag.is-end .pip { background: var(--c, var(--muted)); }
.tag.is-hidden {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s linear, visibility 0s linear 0.22s;
}
.tag.is-cap {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  bottom: 6px;
}
.tag.is-cap::after { display: none; }

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    max(var(--pad), env(safe-area-inset-top))
    max(var(--pad), env(safe-area-inset-right))
    max(var(--pad), env(safe-area-inset-bottom))
    max(var(--pad), env(safe-area-inset-left));
}
#hud[hidden] { display: none; }
#hud > * { pointer-events: none; }

.top {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
}

.card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  padding: 10px 14px 11px;
  min-width: 0;
}
.kicker {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 10.5px;
  line-height: 14px;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}
.line {
  margin-top: 3px;
  font-size: 15px;
  line-height: 20px;
  color: var(--text);
}
.sub {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 17px;
  color: var(--muted);
}

#topcard {
  flex: 1 1 auto;
  pointer-events: auto;
  min-height: 44px;
}
#topcard .kicker { display: flex; align-items: center; gap: 7px; }
#topcard .kicker .pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--muted));
  flex: none;
}
#topcard.is-swap .line, #topcard.is-swap .kicker { opacity: 0; }
#topcard .line, #topcard .kicker { transition: opacity 0.16s linear; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  pointer-events: auto;
  cursor: pointer;
  padding: 0;
  font: inherit;
  transition: background-color 0.18s linear, border-color 0.18s linear;
}
.icon-btn:active { background: #3A3026; }
.icon-btn:focus-visible, .route:focus-visible, .objcard-close:focus-visible, a:focus-visible {
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.dock {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 560px;
  pointer-events: none;
}
.route {
  flex: 1 1 0;
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px;
  color: var(--text);
  font-family: var(--ui);
  font-weight: 600;
  font-size: 13px;
  line-height: 18px;
  text-align: left;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  pointer-events: auto;
  cursor: pointer;
  transition: background-color 0.18s linear, border-color 0.18s linear;
}
.route .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
  box-shadow: 0 0 0 3px rgba(42, 35, 28, 1), 0 0 0 4px transparent;
  transition: box-shadow 0.18s linear;
}
.route:active { background: #3A3026; }
.route.is-active {
  background: #3A3026;
  border-color: var(--c);
}
.route.is-active .dot {
  box-shadow: 0 0 0 3px rgba(58, 48, 38, 1), 0 0 0 4px var(--c);
}

.objcard {
  position: relative;
  width: 100%;
  max-width: 560px;
  padding-right: 48px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s linear, visibility 0s linear 0.2s;
}
.objcard.is-on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.2s linear, visibility 0s linear 0s;
}
.objcard-close {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

/* ---------- navigation hint ---------- */

.hint {
  display: flex;
  gap: 4px;
  padding: 10px 6px 9px;
  max-width: 100%;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s linear, visibility 0s linear 0.5s;
}
.hint.is-on {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s linear, visibility 0s linear 0s;
}
.hint .item {
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  font-size: 11.5px;
  line-height: 14px;
  color: var(--text);
}
.hint svg { color: var(--text); }

/* ---------- info panel ---------- */

.info {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding:
    var(--pad)
    max(var(--pad), env(safe-area-inset-right))
    max(var(--pad), env(safe-area-inset-bottom))
    max(var(--pad), env(safe-area-inset-left));
  background: rgba(22, 19, 15, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s linear, visibility 0s linear 0.25s;
  z-index: 20;
  touch-action: none;
}
.info.is-on {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s linear, visibility 0s linear 0s;
}
.info-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
  background: #2A231C;
  border: 1px solid var(--glass-line);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  padding: 18px 20px 20px;
  transform: translateY(14px);
  transition: transform 0.3s var(--ease);
}
.info.is-on .info-card { transform: none; }
.info h1 {
  margin: 4px 0 10px;
  font-size: 22px;
  line-height: 28px;
  font-weight: 600;
}
.info p {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 21px;
  color: var(--text);
}
.info p.credit { color: var(--muted); font-size: 13px; line-height: 19px; }
.info p.links { margin: 14px 0 0; }
.info a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--muted);
  text-underline-offset: 3px;
}
.info a.btn-link { display: inline-block; padding: 6px 0; }

/* ---------- loader ---------- */

#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--bg);
  opacity: 1;
  transition: opacity 0.5s linear;
}
#loader.is-done { opacity: 0; pointer-events: none; }
.loader-inner {
  width: min(260px, 70vw);
  text-align: center;
}
.loader-title { font-size: 22px; line-height: 28px; margin-bottom: 22px; }
.loader-bar {
  height: 3px;
  background: #2A231C;
  border-radius: 2px;
  overflow: hidden;
}
.loader-fill {
  height: 100%;
  width: 0%;
  background: var(--muted);
  border-radius: 2px;
  transition: width 0.25s linear;
}
.loader-bar.is-indeterminate .loader-fill {
  width: 38%;
  animation: slide 1.3s var(--ease) infinite;
}
@keyframes slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(290%); }
}
.loader-text {
  margin-top: 12px;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  z-index: 60;
}

/* ---------- wide screens ---------- */

@media (min-width: 720px) {
  :root { --pad: 20px; }
  .top { justify-content: flex-start; }
  #topcard { flex: 0 1 460px; }
  .top .icon-btn:first-of-type { margin-left: auto; }
  .route { font-size: 15px; min-height: 56px; }
  .line { font-size: 16px; line-height: 22px; }
  .hint .item { width: 130px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .loader-bar.is-indeterminate .loader-fill { animation: none; width: 100%; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
