/* melody.games · cosmic perspectives — full-viewport 3D viewer with HUD.
   Tokens + reset + header/brand/explore/footer base live in packages/brand/. */

:root {
  /* Dark cosmic backdrop for the canvas frame and viewer gradient — only
     used here, so kept app-local rather than promoted to shared tokens. */
  --space: #0e1724;
  --space-2: #17233a;
}

/* The viewer fills the viewport; header, canvas, footer are grid rows. */
body {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
}

input { font: inherit; }

.panel-toggle {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  background: var(--paper-card);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-cn);
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
}

.panel-toggle:hover {
  background: rgba(42, 53, 84, .08);
}

.panel-toggle-icon {
  width: 14px;
  height: 2px;
  display: inline-block;
  background: currentColor;
  position: relative;
}

.panel-toggle-icon::before,
.panel-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: currentColor;
}

.panel-toggle-icon::before { top: -5px; }
.panel-toggle-icon::after { top: 5px; }

.viewer {
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #0c1320, var(--space) 45%, #1c2131);
}

.canvas-frame {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(255, 250, 240, 0.18);
  border-radius: 8px;
  background: linear-gradient(145deg, #0c1320, var(--space) 45%, #1c2131);
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#stage:active {
  cursor: grabbing;
}

.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.labels[hidden] {
  display: none;
}

.label-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  max-width: min(210px, 42vw);
  padding: 5px 10px 6px;
  border: 1.5px solid rgba(255, 250, 240, 0.78);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  font-family: var(--font-cn);
  font-size: 12px;
  line-height: 1.15;
  letter-spacing: 1px;
  white-space: nowrap;
}

.label-pin b {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--pin-color, var(--ink));
  color: var(--paper-card);
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 1px;
}

.hud {
  position: relative;
  order: -1;
  flex: 0 0 340px;
  width: 340px;
  min-height: 0;
  z-index: 4;
  max-height: 100%;
  align-self: stretch;
  overflow-y: auto;
  padding: 18px;
  background: var(--paper-card);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 5px 0 rgba(42, 53, 84, 0.18);
  transition: transform 0.24s ease, opacity 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(42, 53, 84, 0.26) transparent;
}

.hud::-webkit-scrollbar {
  width: 6px;
}

.hud::-webkit-scrollbar-thumb {
  background: rgba(42, 53, 84, 0.24);
  border-radius: 3px;
}

.hud.collapsed {
  display: none;
}

.hud-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.hud-close:hover {
  background: var(--ink);
  color: var(--paper-card);
}

.perspective-rail {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 8;
  width: min(820px, calc(100% - 28px));
  min-height: 46px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1.5px solid rgba(255, 250, 240, 0.28);
  border-radius: 8px;
  background: rgba(12, 19, 32, 0.78);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
}

.perspective-steps {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
}

.perspective-step,
.perspective-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  color: rgba(255, 250, 240, 0.78);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, opacity 0.18s ease;
}

.perspective-step {
  min-width: 0;
  min-height: 32px;
  padding: 5px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-family: var(--font-cn);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.perspective-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 250, 240, 0.1);
  font-size: 23px;
  line-height: 1;
}

.perspective-step:hover,
.perspective-arrow:hover {
  background: rgba(255, 250, 240, 0.16);
  color: var(--paper-card);
}

.perspective-step.is-active {
  background: var(--paper-card);
  color: var(--ink);
  font-weight: 700;
}

.perspective-arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

.control-group {
  margin-top: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-family: var(--font-cn);
  font-size: 13px;
  color: var(--ink);
  letter-spacing: 0.8px;
  cursor: pointer;
  user-select: none;
}

.check input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  background: var(--paper-card);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.check input[type="checkbox"]:checked {
  background: var(--ink);
}

.check input[type="checkbox"]:checked::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid var(--paper-card);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.slider {
  display: grid;
  gap: 7px;
  margin-top: 4px;
  font-family: var(--font-cn);
  font-size: 13px;
  color: var(--ink-2);
  letter-spacing: 0.8px;
}

.slider input[type="range"] {
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(42, 53, 84, 0.16);
  outline: none;
}

.slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-card);
  cursor: grab;
}

.slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-card);
  cursor: grab;
}

/* Footer is a grid row beneath the viewer; the shared margin-top would push
   it off-screen, so reset it and use a tinted strip instead. */
.site-footer {
  margin-top: 0;
  min-height: 42px;
  padding: 10px 16px;
  align-items: center;
  background: rgba(255, 250, 240, 0.92);
  border-top: 1px solid rgba(42, 53, 84, 0.14);
}

.site-footer .sep { color: var(--coral); }

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .viewer {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 10px 10px var(--sheet-visible, 64px);
  }

  .canvas-frame {
    border-width: 1.5px;
    border-radius: 8px;
  }

  .perspective-rail {
    bottom: 10px;
    width: calc(100% - 20px);
    grid-template-columns: 36px minmax(0, 1fr) 36px;
    min-height: 44px;
    padding: 5px;
  }

  .perspective-steps {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .perspective-steps::-webkit-scrollbar {
    display: none;
  }

  .perspective-step {
    flex: 0 0 auto;
    min-width: 54px;
    scroll-snap-align: center;
  }

  .site-footer {
    display: none;
  }

  .hud {
    display: block;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    flex: none;
    max-height: min(62dvh, 540px);
    padding: 30px 16px max(16px, env(safe-area-inset-bottom));
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.26);
    z-index: 25;
  }

  .hud::before {
    content: "";
    position: absolute;
    top: 9px;
    left: 50%;
    width: 44px;
    height: 5px;
    transform: translateX(-50%);
    border-radius: 999px;
    background: rgba(42, 53, 84, 0.22);
    pointer-events: none;
  }

  .hud.collapsed {
    display: block;
    transform: translateY(calc(100% - 64px));
    opacity: 1;
    pointer-events: auto;
  }

  .hud.collapsed::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    cursor: pointer;
  }

}

@media (max-width: 460px) {
  .panel-toggle-label {
    display: none;
  }

  .panel-toggle {
    width: 38px;
    justify-content: center;
    padding: 8px;
  }

  .label-pin {
    max-width: 46vw;
    font-size: 11px;
    padding: 4px 8px 5px;
  }

  .perspective-step {
    min-width: 48px;
    padding-inline: 7px;
  }
}
