:root {
  /* Keep in sync with docs/styles.css theme tokens (subset). */
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(17, 24, 39, 0.12);
  --buttonSecondaryBg: rgba(17, 24, 39, 0.05);
  --progressTrackBg: rgba(17, 24, 39, 0.12);
  --accent: #2563eb;
  --accentHover: #1d4ed8;
  --positive: #059669;
  --negative: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e1a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.08);
    --buttonSecondaryBg: rgba(255, 255, 255, 0.05);
    --progressTrackBg: rgba(255, 255, 255, 0.1);
    --accent: #60a5fa;
    --accentHover: #93c5fd;
    --positive: #34d399;
    --negative: #f87171;
  }
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(17, 24, 39, 0.12);
  --buttonSecondaryBg: rgba(17, 24, 39, 0.05);
  --progressTrackBg: rgba(17, 24, 39, 0.12);
  --accent: #2563eb;
  --accentHover: #1d4ed8;
  --positive: #059669;
  --negative: #dc2626;
}

:root[data-theme="dark"] {
  --bg: #0a0e1a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.08);
  --buttonSecondaryBg: rgba(255, 255, 255, 0.05);
  --progressTrackBg: rgba(255, 255, 255, 0.1);
  --accent: #60a5fa;
  --accentHover: #93c5fd;
  --positive: #34d399;
  --negative: #f87171;
}

/* Keyboard focus visibility (WCAG SC 2.4.7). */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* App shell
 *
 * iOS Safari/PWA note:
 * - Avoid hard-coding a header height (it can wrap on iPhone).
 * - Use a flex column layout so the header takes its natural height and the
 *   stage fills the remaining viewport.
 */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.appHeader h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.headerControls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.browseGroup {
  display: flex;
  align-items: center;
  gap: 6px;
}

.snapshotDetails {
  /* Collapsible loader so the header stays tidy after a snapshot loads
   * (Issue #37, 31-Dec-2025).
   */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

@media (min-width: 920px) {
  .snapshotDetails {
    flex-direction: row;
    align-items: center;
  }
}

.snapshotDetails > summary {
  list-style: none;
  /* summary defaults to display:list-item in many browsers, which can cause
   * subtle baseline/centering misalignment against real <button> elements.
   */
  display: inline-flex;
  align-items: center;
}

.snapshotDetails > summary::-webkit-details-marker {
  display: none;
}

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

.input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-width: 260px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(96, 165, 250, 0.15);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  background: rgba(96, 165, 250, 0.25);
  border-color: var(--accent);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.button:disabled:hover {
  background: rgba(96, 165, 250, 0.15);
  border-color: var(--border);
}

.buttonSecondary {
  background: var(--buttonSecondaryBg);
}

.statusInline {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  margin-left: 8px;
  padding: 6px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(640px, 44vw);
}

.statusInline.ok {
  color: var(--positive);
}

.statusInline.bad {
  color: var(--negative);
}

.progressContainer {
  width: 120px;
  height: 6px;
  background: var(--progressTrackBg);
  border-radius: 3px;
  overflow: hidden;
}

.progressBar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.15s ease-out;
}

.progressBar.indeterminate {
  width: 30%;
  animation: progressIndeterminate 1.2s ease-in-out infinite;
}

@keyframes progressIndeterminate {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(250%);
  }
  100% {
    transform: translateX(-100%);
  }
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(
    circle at 30% 20%,
    rgba(96, 165, 250, 0.15),
    transparent 45%
  );
}

.glCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  /* Ensure touch devices can drag/pinch the canvas without the browser
   * interpreting gestures as page scroll/zoom (Issue #39, 31-Dec-2025).
   */
  touch-action: none;
}

.labelOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
}

.starLabel {
  position: absolute;
  transform: translate(-50%, -120%);
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  /* Depth hinting (set inline): opacity + scale are adjusted by JS. */
  transform-origin: center bottom;
}

.starLabel.isFocus {
  border-color: rgba(80, 240, 255, 0.35);
  box-shadow: 0 0 18px rgba(80, 240, 255, 0.18);
}

.starLabel .uuid {
  color: var(--muted);
  margin-left: 6px;
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.panelTitle {
  font-weight: 700;
  color: var(--text);
}

.buttonSmall {
  padding: 4px 8px;
  font-size: 12px;
}

.panelBody {
  color: var(--muted);
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: min(420px, calc(100vw - 28px));
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 20;
}

.hud a {
  color: var(--accent);
}

.hudBody {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.hud.isCollapsed .hudBody {
  display: none;
}

.legend.isCollapsed .legendBody {
  display: none;
}

.legend {
  position: absolute;
  top: 14px;
  right: 14px;
  max-width: min(520px, calc(100vw - 28px));
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
  line-height: 1.35;
  user-select: none;
  z-index: 20;
}

.legendBody {
  color: var(--muted);
}

.legend .k {
  color: var(--text);
  font-weight: 600;
}

.legendHint {
  margin-top: 8px;
  color: var(--text);
  opacity: 0.8;
}

.focusBadge {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 12px;
  user-select: none;
  max-width: min(720px, calc(100vw - 28px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 15;
}

.focusBadge .uuid {
  color: var(--muted);
  margin-left: 8px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}

.focusBadge .alias {
  font-weight: 700;
}

.help {
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  user-select: none;
}

@media (max-width: 640px) {
  .input {
    min-width: 0;
    flex: 1 1 100%;
  }
  .statusInline {
    flex: 1 1 100%;
    margin-left: 0;
    max-width: none;
    white-space: normal;
  }
  .legend {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: auto;
    max-width: min(520px, calc(100vw - 24px));
  }
  .focusBadge {
    top: auto;
    bottom: 64px;
    left: 12px;
    transform: none;
    max-width: min(720px, calc(100vw - 24px));
  }
}

/* Tablet and below: keep the long status line from compressing the header
 * controls. Prefer a clean second row for status.
 */
@media (max-width: 920px) {
  .statusInline {
    flex: 1 1 100%;
    margin-left: 0;
    max-width: none;
  }
}

/* iPhone: keep panels from blocking the entire viewport.
 *
 * Use a bottom-sheet style HUD and default the legend to collapsed via JS.
 */
@media (max-width: 520px) {
  .hud {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
    max-height: 45vh;
    overflow: auto;
  }

  .legend {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }

  .help {
    display: none;
  }
}

/* ==========================================================================
   Issue #104: Smooth animated transitions for graph explorer
   ========================================================================== */

:root {
  --transition-focus-pulse: 280ms;
}

/* Focus pulse: briefly highlight the focused node's label. */
.starLabel.focusPulse {
  animation: focusPulse var(--transition-focus-pulse) ease;
}

@keyframes focusPulse {
  0% {
    box-shadow: 0 0 0 rgba(80, 240, 255, 0);
    transform: translate(-50%, -120%) scale(1);
  }
  50% {
    box-shadow: 0 0 24px rgba(80, 240, 255, 0.45);
    transform: translate(-50%, -120%) scale(1.12);
  }
  100% {
    box-shadow: 0 0 18px rgba(80, 240, 255, 0.18);
    transform: translate(-50%, -120%) scale(1);
  }
}

/* Fade adjacent node labels in/out as neighbourhood changes. */
.starLabel {
  transition: opacity 200ms ease;
}

/* Focus badge transition. */
.focusBadge {
  transition: opacity 200ms ease;
}

/* ── Touch feedback (#106) ──────────────────────────────────────────────── */

/* Ripple effect shown on tap-to-focus (#106). */
.touchRipple {
  position: absolute;
  width: 36px;
  height: 36px;
  margin-left: -18px;
  margin-top: -18px;
  border-radius: 50%;
  background: rgba(80, 240, 255, 0.35);
  pointer-events: none;
  animation: rippleExpand 350ms ease-out forwards;
}

@keyframes rippleExpand {
  0% {
    transform: scale(0.3);
    opacity: 1;
  }
  100% {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* Haptic-style visual pulse for buttons on tap (#106). */
.headerControls button:active,
.headerControls .btn:active {
  transform: scale(0.93);
  transition: transform 0.08s ease-out;
}

/* Prevent text selection on long-press (Issue #21 + #106). */
.stage {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Skip all graph transitions when reduced motion is preferred. */
@media (prefers-reduced-motion: reduce) {
  .starLabel.focusPulse {
    animation: none;
  }

  .starLabel {
    transition: none;
  }

  .focusBadge {
    transition: none;
  }

  .touchRipple {
    animation: none;
  }

  .headerControls button:active,
  .headerControls .btn:active {
    transform: none;
  }
}
