/* ── Variables ─────────────────────────────────────────── */
:root {
  --c-bg:       #030712;
  --c-surf:     rgba(15,23,42,0.65);
  --c-surf-h:   rgba(30,41,59,0.88);
  --c-border:   rgba(148,163,184,0.12);
  --c-border-h: rgba(96,165,250,0.4);
  --c-accent:   #60a5fa;
  --c-accent-g: rgba(96,165,250,0.18);
  --c-text:     #f1f5f9;
  --c-sub:      #94a3b8;
  --font:       'Space Grotesk', system-ui, sans-serif;
  --mono:       'Space Mono', monospace;
  --r:          14px;
  --ease:       cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset ─────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
img { display: block; }
a { text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ── Base ──────────────────────────────────────────────── */
html { height: 100%; }

body {
  min-height: 100%;
  font-family: var(--font);
  color: var(--c-text);
  background-color: var(--c-bg);
  overflow-x: hidden;
}

body.stargazing {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── Sky canvas ────────────────────────────────────────── */
#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.stargazing #sky {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.stargazing #sky.dragging {
  cursor: grabbing;
}

.sky-overlay {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease);
}

.stargazing .sky-overlay {
  opacity: 1;
  pointer-events: auto;
}

.sky-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.7rem 1rem;
  border: 1px solid rgba(147,197,253,0.45);
  border-radius: 999px;
  background: rgba(5,10,22,0.82);
  color: var(--c-text);
  box-shadow:
    0 16px 40px rgba(0,0,0,0.35),
    0 0 0 1px rgba(96,165,250,0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.constellation-panel {
  position: fixed;
  top: 1.1rem;
  left: 1.1rem;
  z-index: 5;
  width: min(24rem, calc(100vw - 2.2rem));
  padding: 1rem 1rem 1.05rem;
  border: 1px solid rgba(147,197,253,0.22);
  border-radius: 18px;
  background: rgba(4,10,22,0.84);
  color: var(--c-text);
  box-shadow:
    0 18px 48px rgba(0,0,0,0.38),
    0 0 0 1px rgba(96,165,250,0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.constellation-panel-close {
  position: absolute;
  top: 0.65rem;
  right: 0.7rem;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--c-sub);
  font-size: 1.35rem;
  line-height: 1;
}

.constellation-panel-kicker {
  margin-bottom: 0.35rem;
  color: #93c5fd;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.constellation-panel-title {
  margin-bottom: 0.45rem;
  font-family: var(--mono);
  font-size: 1.2rem;
  line-height: 1.15;
}

.constellation-panel-copy {
  margin-bottom: 0.85rem;
  color: var(--c-sub);
  font-size: 0.92rem;
  line-height: 1.55;
}

.constellation-panel-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1rem;
}

.constellation-panel-meta dt {
  margin-bottom: 0.18rem;
  color: var(--c-sub);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.constellation-panel-meta dd {
  font-size: 0.92rem;
}

/* ── Page wrapper ──────────────────────────────────────── */
.page {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.75rem;
  padding: 2rem 1.5rem;
}

/* ── Header ────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  animation: rise 0.6s var(--ease) both;
}

.logo {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1.5px solid var(--c-border-h);
  box-shadow: 0 0 24px rgba(96,165,250,0.35), 0 0 60px rgba(96,165,250,0.08);
}

.site-title {
  font-family: var(--mono);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.accent { color: var(--c-accent); }

/* ── Main ──────────────────────────────────────────────── */
main {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sky-tools {
  display: flex;
  justify-content: center;
  animation: rise 0.5s var(--ease) 0.22s both;
}

.sky-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.65rem 0.95rem;
  border: 1px solid rgba(96,165,250,0.26);
  border-radius: 999px;
  background: rgba(10,15,28,0.54);
  color: var(--c-text);
  letter-spacing: 0.01em;
  transition:
    border-color 0.22s var(--ease),
    background 0.22s var(--ease),
    transform 0.22s var(--ease),
    box-shadow 0.22s var(--ease);
}

.sky-toggle:hover,
.sky-toggle[aria-pressed="true"] {
  border-color: var(--c-border-h);
  background: rgba(20,44,90,0.6);
  box-shadow: 0 0 0 1px rgba(96,165,250,0.2);
}

/* ── Cards grid ────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.875rem;
}

/* ── Card ──────────────────────────────────────────────── */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem 1.25rem;
  background: var(--c-surf);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  color: var(--c-text);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  overflow: hidden;
  transition:
    transform 0.22s var(--ease),
    border-color 0.22s var(--ease),
    box-shadow 0.22s var(--ease),
    background 0.22s var(--ease);
  animation: rise 0.5s var(--ease) both;
  animation-delay: calc(var(--delay, 0) * 75ms + 120ms);
}

.card-shine {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 40% at 50% -10%, var(--c-accent-g), transparent 60%);
  opacity: 0;
  transition: opacity 0.22s var(--ease);
  pointer-events: none;
}

.card:hover {
  transform: translateY(-5px);
  border-color: var(--c-border-h);
  background: var(--c-surf-h);
  box-shadow:
    0 0 0 1px var(--c-border-h),
    0 12px 36px rgba(0,0,0,0.45),
    0 0 30px rgba(96,165,250,0.07);
}

.card:hover .card-shine { opacity: 1; }

.card--featured {
  background: rgba(20,44,90,0.7);
  border-color: rgba(96,165,250,0.22);
}

.card-icon {
  width: 54px;
  height: 54px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.55));
  transition: transform 0.22s var(--ease);
}

.card:hover .card-icon { transform: scale(1.08); }

.card:focus-visible,
.mgmt-toggle:focus-visible,
.sky-toggle:focus-visible,
.sky-fab:focus-visible {
  outline: none;
  border-color: var(--c-border-h);
  box-shadow:
    0 0 0 1px rgba(96,165,250,0.28),
    0 0 0 4px rgba(96,165,250,0.14);
}

.card:focus-visible .card-shine { opacity: 1; }

.card:focus-visible .card-icon { transform: scale(1.08); }

.card-name {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.card-sub {
  font-size: 0.7rem;
  color: var(--c-sub);
  text-align: center;
}

/* ── Small cards (management) ──────────────────────────── */
.card--sm {
  padding: 1rem 0.75rem;
  gap: 0.35rem;
  border-radius: 8px;
}

.card--sm .card-icon { width: 38px; height: 38px; }
.card--sm .card-name { font-size: 0.8rem; }

/* ── Management section ────────────────────────────────── */
.mgmt-wrap {
  width: 100%;
  animation: rise 0.5s var(--ease) 0.38s both;
}

.mgmt-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--c-surf);
  border: 1px solid var(--c-border);
  border-radius: 12px;
  color: var(--c-text);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition:
    border-color 0.22s var(--ease),
    background 0.22s var(--ease),
    border-radius 0.22s var(--ease);
}

.mgmt-toggle:hover {
  border-color: var(--c-border-h);
  background: var(--c-surf-h);
}

.mgmt-toggle.open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: rgba(148,163,184,0.05);
}

.mgmt-icon { width: 26px; height: 26px; object-fit: contain; }

.chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  flex-shrink: 0;
  color: var(--c-sub);
  transition: transform 0.3s var(--ease);
}

.mgmt-toggle.open .chevron { transform: rotate(180deg); }

/* Slide-open panel using max-height */
.mgmt-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s var(--ease);
}

.mgmt-panel.open { max-height: 500px; }

.mgmt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
  gap: 1px;
  background: var(--c-border);
  border: 1px solid var(--c-border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
}

.mgmt-grid .card {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
  border: none;
  background: var(--c-surf);
  animation: none;
}

/* No lift or external shadow — both get clipped by the grid's overflow:hidden */
.mgmt-grid .card:hover {
  transform: none;
  box-shadow: inset 0 0 0 1px var(--c-border-h);
}


/* ── Stargazing mode (Ctrl held) ───────────────────────── */
.stargazing .page {
  opacity: 0;
  pointer-events: none;
}

.page {
  transition: opacity 0.25s ease;
}

/* ── Keyframes ─────────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ────────────────────────────────────────── */

/* Touch devices: skip hover transitions, use tap feedback instead */
@media (hover: none) {
  .card { transition: none; }
  .card:active {
    background: var(--c-surf-h);
    border-color: var(--c-border-h);
  }
}

/* Mobile — allow scrolling, fix centering overflow */
@media (max-width: 680px) {
  .page {
    justify-content: flex-start;
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
  }

  /* FAB moves to top-right corner so it never competes with the bottom sheet */
  .sky-overlay {
    top: 1rem;
    right: 1rem;
    bottom: auto;
    left: auto;
  }

  .sky-fab {
    width: auto;
    min-height: 2.6rem;
    padding: 0.65rem 1.1rem;
    font-size: 0.9rem;
  }

  /* Bottom sheet panel */
  .constellation-panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    max-height: 7rem;      /* collapsed: handle + kicker + title */
    overflow: hidden;
    padding: 0 1.2rem calc(1rem + env(safe-area-inset-bottom, 0px));
    transition: max-height 0.38s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow:
      0 -8px 40px rgba(0,0,0,0.48),
      0 0 0 1px rgba(96,165,250,0.12);
    cursor: pointer; /* whole sheet is tappable */
  }

  /* Drag handle — brightens to hint "tap me" */
  .constellation-panel::before {
    content: '';
    display: block;
    width: 3rem;
    height: 5px;
    margin: 0.7rem auto 0.55rem;
    background: rgba(148,163,184,0.40);
    border-radius: 3px;
    transition: background 0.2s;
  }
  .constellation-panel:not(.panel-expanded):active::before {
    background: rgba(148,163,184,0.72);
  }

  /* Chevron hint — points up when collapsed, down when expanded */
  .constellation-panel::after {
    content: '⌃';
    position: absolute;
    top: 0.55rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: rgba(148,163,184,0.45);
    transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s;
    pointer-events: none;
  }
  .constellation-panel.panel-expanded::after {
    transform: translateX(-50%) rotate(180deg);
  }

  /* Expanded state */
  .constellation-panel.panel-expanded {
    max-height: min(82svh, 38rem);
    overflow-y: auto;
    cursor: default;
  }

  /* × button: collapses only on mobile — label it accordingly */
  .constellation-panel-close {
    top: 0.55rem;
    right: 0.7rem;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.4rem;
  }
  /* Hide × when collapsed — tapping elsewhere expands; it appears after expansion */
  .constellation-panel:not(.panel-expanded) .constellation-panel-close {
    opacity: 0;
    pointer-events: none;
  }

  .constellation-panel-title {
    padding-right: 2.4rem;
    font-size: 1.1rem;
  }

  .constellation-panel-kicker {
    margin-bottom: 0.2rem;
  }

  .constellation-panel-copy,
  .constellation-panel-meta dd {
    font-size: 0.95rem;
  }

  /* Drop blur on mobile for GPU headroom */
  .card,
  .mgmt-toggle,
  .sky-toggle,
  .sky-fab,
  .constellation-panel {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(15,23,42,0.92);
  }

  .card--featured {
    background: rgba(20,44,90,0.9);
  }

  .mgmt-grid .card {
    background: rgba(15,23,42,0.88);
  }
}

/* Compact cards on small phones so 3 fit in one row */
@media (max-width: 420px) {
  .header {
    gap: 0.9rem;
  }

  .card {
    padding: 1.1rem 0.5rem 0.9rem;
    gap: 0.35rem;
  }

  .card-icon {
    width: 40px;
    height: 40px;
  }

  .card-name { font-size: 0.8rem; }
  .card-sub  { display: none; }

  .card--sm .card-icon { width: 30px; height: 30px; }
  .card--sm .card-name { font-size: 0.72rem; }

  .logo { width: 44px; height: 44px; }

  .constellation-panel-meta {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .sky-toggle {
    width: 100%;
    min-height: 2.9rem;
  }

  .sky-tools {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
