/* Ungrade Enhanced Visuals: 3D Depth, Film Grain, Liquid Ambient & Living Sphere */

/* 1. Film Grain / Noise Overlay */
.noise-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  mix-blend-mode: overlay;
}

[data-theme="light"] .noise-layer {
  opacity: 0.03;
  mix-blend-mode: multiply;
}

/* 2. Ambient Fluid Aurora Canvas */
.ambient-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.75;
  filter: blur(48px);
  transform: translateZ(0);
}

[data-theme="light"] .ambient-canvas {
  opacity: 0.45;
  filter: blur(60px);
}

/* Ensure app-scroll content sits above ambient canvas */
.app-shell {
  perspective: 1200px;
}

.app-scroll {
  position: relative;
  z-index: 2;
}

/* 3. 3D Card Depth & Specular Sheen */
.hero,
.mode-card,
.article-card,
.checkin-card,
.step-card,
.practice-timer,
.practice-card {
  position: relative;
  transform-style: preserve-3d;
  will-change: transform, box-shadow;
  transition: transform 0.22s cubic-bezier(0.2, 0, 0.2, 1), 
              box-shadow 0.25s cubic-bezier(0.2, 0, 0.2, 1),
              border-color 0.25s ease;
}

/* Specular reflection glint */
.card-specular-glare,
.living-sphere-container .card-specular-glare {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: inherit;
  pointer-events: none !important;
  opacity: 0;
  transition: opacity 0.22s ease;
  z-index: 8 !important;
  background: radial-gradient(circle 220px at var(--glare-x, 50%) var(--glare-y, 50%), rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0.08) 45%, transparent 75%);
}

[data-theme="light"] .card-specular-glare,
[data-theme="light"] .living-sphere-container .card-specular-glare {
  background: radial-gradient(circle 220px at var(--glare-x, 50%) var(--glare-y, 50%), rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0.15) 45%, transparent 75%);
}

.card-tilted .card-specular-glare {
  opacity: 1 !important;
}

.living-sphere-container.sphere-dragging .card-specular-glare {
  opacity: 0 !important;
  visibility: hidden !important;
  transition: none !important;
}

/* Internal elements pop out slightly with 3D translation */
.hero-copy,
.hero-art,
.mode-card h2,
.mode-card p,
.mode-card .round-arrow,
.checkin-card h2,
.checkin-card .button {
  transform: translateZ(10px);
  transition: transform 0.22s ease;
}

/* 4. Spring Stagger Entrance for Cards */
@keyframes springCardIn {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.965);
  }
  65% {
    opacity: 1;
    transform: translateY(-2px) scale(1.006);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.animate-spring-in {
  animation: springCardIn 520ms cubic-bezier(0.18, 0.89, 0.32, 1.15) backwards;
  animation-delay: calc(var(--stagger-index, 0) * 48ms);
}

@media (prefers-reduced-motion: reduce) {
  .animate-spring-in {
    animation: none !important;
  }
  .hero, .mode-card, .article-card, .checkin-card, .step-card {
    transform: none !important;
  }
}

/* 5. Living Breathing Sphere Widget */
.living-sphere-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 14px 14px 18px;
  margin: 12px 0 16px;
  background-color: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  touch-action: pan-y !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-tap-highlight-color: transparent !important;
  outline: none !important;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, padding 0.58s cubic-bezier(0.16, 1, 0.3, 1);
}

.living-sphere-container.collapsed {
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, padding 0.40s cubic-bezier(0.25, 0, 0.2, 1);
}

.living-sphere-container:hover {
  border-color: color-mix(in srgb, var(--border) 75%, var(--text) 25%);
}

.living-sphere-container:focus,
.living-sphere-container:focus-visible,
.living-sphere-container:active {
  outline: none !important;
  box-shadow: none !important;
}

/* Dynamic breathing ambient glow inside the block: blooms on inhale, retains soft resting glow on exhale */
.living-sphere-container::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(circle at 50% 52%, color-mix(in srgb, var(--accent) 30%, var(--accent-subtle)) 0%, var(--accent-subtle) calc(32% + var(--block-glow, 0) * 28%), transparent calc(52% + var(--block-glow, 0) * 26%));
  opacity: calc(0.20 + var(--block-glow, 0) * 0.80);
  will-change: opacity;
  z-index: 1;
}

.living-sphere-container.collapsed::before {
  opacity: 0 !important;
  transition: opacity 0.25s ease;
}

.sphere-collapse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: left;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-tap-highlight-color: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  position: relative;
  z-index: 5;
}

.sphere-collapse-header:focus,
.sphere-collapse-header:focus-visible,
.sphere-collapse-header:active {
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

.sphere-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sphere-collapse-header .eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted);
}

.sphere-collapse-header .small.muted {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

.sphere-chevron-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-raised, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border);
  color: var(--muted);
  transition: transform 0.44s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.25s ease,
              border-color 0.25s ease,
              color 0.25s ease;
  flex-shrink: 0;
}

.sphere-chevron-icon svg {
  width: 16px;
  height: 16px;
  transition: transform 0.44s cubic-bezier(0.16, 1, 0.3, 1);
  transform: rotate(90deg); /* points down when collapsed */
}

.living-sphere-container:not(.collapsed) .sphere-chevron-icon svg {
  transform: rotate(-90deg); /* points up when expanded */
}

.living-sphere-container:not(.collapsed) .sphere-chevron-icon {
  background: var(--surface-raised);
  border-color: color-mix(in srgb, var(--border) 70%, var(--text) 30%);
  color: var(--text);
}

/* 120 FPS GPU-Accelerated Synchronized Grid Track */
.sphere-collapsible-wrapper {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.60s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
  will-change: grid-template-rows;
}

.living-sphere-container:not(.collapsed) .sphere-collapsible-wrapper {
  grid-template-rows: 1fr;
}

.living-sphere-container.collapsed .sphere-collapsible-wrapper {
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.40s cubic-bezier(0.25, 0, 0.2, 1);
}

.sphere-collapsible-body {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  width: 100%;
  contain: paint;
  padding-top: 8px;
}

/* Base Canvas Styles */
.sphere-collapsible-body .living-sphere-canvas {
  width: 280px;
  height: 280px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  cursor: grab;
  touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  position: relative;
  z-index: 2;
  transform-origin: center top;
  will-change: transform, opacity;
}

.sphere-collapsible-body .living-sphere-canvas:active {
  cursor: grabbing;
}

/* Static resting state when collapsed (initial load before user interaction) */
.living-sphere-container.collapsed .sphere-collapsible-body .living-sphere-canvas {
  transform: scale(0.82, 0.50) translateY(-14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.42s cubic-bezier(0.25, 0, 0.2, 1),
              opacity 0.26s cubic-bezier(0.25, 0, 0.2, 1);
}

/* Static resting & expanded state: Continuous 120 FPS spring spline with 5% fluid overshoot */
.living-sphere-container:not(.collapsed) .sphere-collapsible-body .living-sphere-canvas {
  transform: scale(1, 1) translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition: transform 0.64s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.35s ease-out;
}

/* Kinetic Plunge & Edge Impact Collapse: Compresses, springs downward, and ignites bottom border */
@keyframes sphere-collapse-fluid {
  0% {
    transform: scale(1, 1) translateY(0);
    opacity: 1;
  }
  24% {
    transform: scale(1.08, 0.85) translateY(10px);
    opacity: 1;
  }
  48% {
    transform: scale(1.22, 0.58) translateY(38px);
    opacity: 0.95;
  }
  72% {
    transform: scale(1.36, 0.28) translateY(60px);
    opacity: 0.55;
  }
  100% {
    transform: scale(1.42, 0.08) translateY(72px);
    opacity: 0;
  }
}

.living-sphere-container.has-interacted.collapsed .sphere-collapsible-body .living-sphere-canvas {
  animation: sphere-collapse-fluid 0.42s cubic-bezier(0.25, 0, 0.2, 1) forwards;
}

/* Bottom Frame Ignition & Uniform 2-Second Cooling System */
@keyframes bottom-frame-ignite-and-cool {
  0% {
    border-bottom-color: color-mix(in srgb, var(--accent) 95%, #fff);
    box-shadow: 
      /* Inner halo (radiates upwards INSIDE the bottom frame line) */
      inset 0 -3px 10px -1px color-mix(in srgb, var(--accent) 85%, #fff),
      inset 0 -12px 30px -2px color-mix(in srgb, var(--accent) 65%, transparent),
      /* Outer halo (radiates downwards OUTSIDE the bottom frame line) */
      0 3px 10px -1px color-mix(in srgb, var(--accent) 85%, #fff),
      0 12px 30px -2px color-mix(in srgb, var(--accent) 65%, transparent);
  }
  100% {
    border-bottom-color: var(--border);
    box-shadow: 
      inset 0 0 0 transparent,
      inset 0 0 0 transparent,
      0 0 0 transparent,
      0 0 0 transparent;
  }
}

.living-sphere-container.sphere-ignited {
  animation: bottom-frame-ignite-and-cool 2.0s cubic-bezier(0.16, 0.84, 0.3, 1) forwards !important;
}

/* Badge Liquid Choreography */
.sphere-collapsible-body .sphere-phase-badge {
  transform-origin: center top;
  will-change: transform, opacity;
}

.living-sphere-container.collapsed .sphere-collapsible-body .sphere-phase-badge {
  transform: scale(0.85, 0.4) translateY(-16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.25, 0, 0.2, 1),
              opacity 0.22s cubic-bezier(0.25, 0, 0.2, 1);
}

.living-sphere-container:not(.collapsed) .sphere-collapsible-body .sphere-phase-badge {
  transform: scale(1, 1) translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition: transform 0.58s cubic-bezier(0.34, 1.35, 0.64, 1) 0.08s,
              opacity 0.38s ease-out 0.08s;
}

@keyframes badge-collapse-fluid {
  0% {
    transform: scale(1, 1) translateY(0);
    opacity: 1;
  }
  40% {
    transform: scale(0.92, 0.6) translateY(8px);
    opacity: 0.6;
  }
  100% {
    transform: scale(0.80, 0.2) translateY(18px);
    opacity: 0;
  }
}

.living-sphere-container.has-interacted.collapsed .sphere-collapsible-body .sphere-phase-badge {
  animation: badge-collapse-fluid 0.32s cubic-bezier(0.25, 0, 0.2, 1) forwards;
}

.sphere-collapsible-body .sphere-scroll-rail {
  pointer-events: none;
}

.living-sphere-container:not(.collapsed) .sphere-collapsible-body .sphere-scroll-rail {
  pointer-events: auto;
}

.living-sphere-container > *:not(.card-specular-glare):not(.sphere-scroll-rail) {
  position: relative;
  z-index: 2;
}

/* 18% side scroll rails for smooth vertical page scrolling */
.sphere-scroll-rail {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  z-index: 10;
  touch-action: pan-y !important;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

.sphere-scroll-rail.left {
  left: 0;
}

.sphere-scroll-rail.right {
  right: 0;
}

.living-sphere-canvas {
  width: 280px;
  height: 280px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  cursor: grab;
  touch-action: none !important;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 2;
}

.living-sphere-canvas:active {
  cursor: grabbing;
}

.sphere-phase-badge {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--accent);
  margin-top: 4px;
  padding: 5px 14px 5px 10px;
  min-width: 114px;
  justify-content: center;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.sphere-phase-badge .phase-text-canvas {
  display: block;
  width: 68px;
  height: 20px;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.phase-progress-ring {
  position: relative;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ring-canvas {
  width: 18px;
  height: 18px;
  display: block;
}

.sphere-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  text-align: center;
  line-height: 1.5;
}

.sphere-toggle-btn {
  margin-top: 10px;
  font-size: 12px;
  padding: 6px 16px;
  min-height: 34px;
}

/* 6. Frosted Matte Header & Navigation Dock */
.app-header {
  background-color: rgba(17, 19, 21, 0.80) !important;
  background-color: color-mix(in srgb, var(--header, var(--bg)) 80%, transparent) !important;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015) 50%, transparent 80%) !important;
  -webkit-backdrop-filter: blur(16px) saturate(1.2) !important;
  backdrop-filter: blur(16px) saturate(1.2) !important;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 18px rgba(0, 0, 0, 0.07) !important;
  transition: background-color 0.3s ease, border-color 0.3s ease !important;
}

[data-theme="light"] .app-header {
  background-color: rgba(248, 250, 255, 0.82) !important;
  background-color: color-mix(in srgb, var(--header, var(--bg)) 82%, transparent) !important;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.3) 50%, transparent 80%) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 4px 18px rgba(31, 61, 105, 0.05) !important;
}

.main-nav,
.main-nav.glass-nav {
  background-color: rgba(17, 19, 21, 0.80) !important;
  background-color: color-mix(in srgb, var(--bg) 80%, transparent) !important;
  background-image: linear-gradient(0deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.012) 50%, transparent 80%) !important;
  -webkit-backdrop-filter: blur(16px) saturate(1.2) !important;
  backdrop-filter: blur(16px) saturate(1.2) !important;
  border-top: 1px solid color-mix(in srgb, var(--border) 75%, transparent) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 -6px 20px rgba(0, 0, 0, 0.09) !important;
  transition: background-color 0.3s ease, border-color 0.3s ease !important;
}

[data-theme="light"] .main-nav,
[data-theme="light"] .main-nav.glass-nav {
  background-color: rgba(248, 250, 255, 0.82) !important;
  background-color: color-mix(in srgb, var(--bg) 82%, transparent) !important;
  background-image: linear-gradient(0deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.3) 50%, transparent 80%) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 -6px 20px rgba(31, 61, 105, 0.05) !important;
}

/* Allow content to gracefully scroll behind frosted bottom navigation dock */
.app-scroll {
  margin-bottom: calc(-1 * (var(--nav-height) + env(safe-area-inset-bottom)));
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 24px);
}
