/* ==========================================================
   Mason's World — interactive 3D homepage
   ========================================================== */

html, body.world-body { height: 100%; }

body.world-body {
  --sky-top: #6cc0f5;
  --sky-bottom: #e3f4ff;
  --panel-width: min(580px, 46vw);
  --glass: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.9);
  --glass-text: #0b1220;
  overflow: hidden;
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
html.dark-mode body.world-body {
  --glass: rgba(14, 18, 30, 0.78);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-text: #eef1f7;
}

/* --- Sky layer behind the canvas --- */
.world-sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.world-stars {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  opacity: 0;
  animation: worldTwinkle 4s ease-in-out infinite alternate;
}
@keyframes worldTwinkle { from { filter: brightness(0.75); } to { filter: brightness(1.25); } }
.world-sun, .world-moon {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  opacity: 0;
  will-change: transform;
}
.world-sun {
  width: 96px;
  height: 96px;
  background: radial-gradient(circle, #fffbe8 0 32%, #ffe58a 46%, rgba(255, 214, 102, 0.35) 62%, rgba(255, 214, 102, 0) 72%);
  filter: blur(0.3px);
}
.world-moon {
  width: 64px;
  height: 64px;
  background: radial-gradient(circle at 38% 38%, #ffffff 0 30%, #e6ebff 55%, #c7d0f5 70%);
  box-shadow: 0 0 40px 10px rgba(199, 210, 254, 0.35);
}

.world-canvas { position: fixed; inset: 0; }
.world-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* --- Glass UI primitives --- */
.world-topbar, .world-chip, .world-hint, .world-time, .world-dock, .world-label {
  -webkit-backdrop-filter: blur(16px) saturate(170%);
  backdrop-filter: blur(16px) saturate(170%);
}

/* --- Top bar --- */
.world-topbar {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.world-topbar > * { pointer-events: auto; }
.world-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 6px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px -12px rgba(16, 24, 40, 0.35);
  color: var(--glass-text);
  -webkit-backdrop-filter: blur(16px) saturate(170%);
  backdrop-filter: blur(16px) saturate(170%);
}
.world-brand:hover { color: var(--glass-text); }
.world-brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
}
.world-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.world-brand-text strong { font-family: var(--font-heading); font-size: 0.98rem; letter-spacing: -0.02em; }
.world-brand-text small { font-size: 0.72rem; color: var(--color-text-muted); }
.world-top-actions { display: flex; gap: 8px; }
.world-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--glass-text);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: 0 10px 30px -12px rgba(16, 24, 40, 0.35);
  transition: transform var(--transition-fast);
}
.world-chip:hover { color: var(--glass-text); transform: translateY(-1px); }

/* --- Hint toast --- */
.world-hint {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--glass-text);
  font-size: var(--text-sm);
  white-space: nowrap;
  box-shadow: 0 10px 30px -12px rgba(16, 24, 40, 0.35);
  opacity: 0;
  transition: opacity 600ms ease;
  pointer-events: none;
}
.world-hint.is-visible { opacity: 1; }
.world-hint i { color: var(--color-accent); margin-right: 4px; }

/* --- Floating place labels --- */
.world-labels { position: fixed; inset: 0; z-index: 10; pointer-events: none; overflow: hidden; }
.world-label {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--glass-text);
  font-family: var(--font-body);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 10px 24px -10px rgba(16, 24, 40, 0.45);
  transition: opacity 250ms ease, box-shadow 200ms ease, padding 200ms ease;
  will-change: transform;
}
.world-label::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: 1px solid var(--glass-border);
  border-bottom: 1px solid var(--glass-border);
  transform: translateX(-50%) rotate(45deg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.world-label-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  color: #fff;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.world-label-text { display: flex; flex-direction: column; line-height: 1.2; }
.world-label-text strong { font-size: 0.85rem; font-weight: 650; letter-spacing: -0.01em; }
.world-label-text small {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  max-height: 0;
  overflow: hidden;
  transition: max-height 200ms ease;
}
.world-label.is-hover, .world-label:hover, .world-label:focus-visible { box-shadow: 0 0 0 3px rgba(36, 80, 216, 0.35), 0 14px 30px -10px rgba(16, 24, 40, 0.5); }
.world-label.is-hover .world-label-text small, .world-label:hover .world-label-text small { max-height: 20px; }
.world-label.is-active { box-shadow: 0 0 0 3px var(--color-accent), 0 14px 30px -10px rgba(16, 24, 40, 0.5); }
.world-label.is-dim { opacity: 0.35; }
.world-label.is-hidden { opacity: 0; pointer-events: none; }

/* --- Mason's speech bubble --- */
.world-bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 220px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #ffffff;
  color: #0b1220;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 12px 30px -10px rgba(16, 24, 40, 0.45);
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms ease;
  will-change: transform;
}
.world-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  transform: translateX(-50%) rotate(45deg);
}
.world-bubble.is-visible { opacity: 1; pointer-events: auto; }

/* --- Time of day widget --- */
.world-time {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  width: 236px;
  padding: 12px 14px 10px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--glass-text);
  box-shadow: 0 10px 30px -12px rgba(16, 24, 40, 0.35);
}
.world-time-row { display: flex; align-items: center; gap: 8px; }
.world-time-row > i { color: #f59e0b; width: 18px; text-align: center; }
html.dark-mode .world-time-row > i { color: #c4b5fd; }
.world-time-text { white-space: nowrap; font-family: var(--font-heading); font-weight: 650; font-size: 1.05rem; letter-spacing: -0.02em; flex: 1; font-variant-numeric: tabular-nums; }
.world-time-btn {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--glass-text);
  background: transparent;
}
.world-time-btn.is-active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.world-time input[type="range"] { width: 100%; margin: 8px 0 2px; accent-color: var(--color-accent); }
.world-time-caption { font-size: 0.68rem; color: var(--color-text-muted); letter-spacing: 0.02em; }

/* --- Dock --- */
.world-dock {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: 0 16px 40px -14px rgba(16, 24, 40, 0.45);
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  scrollbar-width: none;
  transition: transform 400ms cubic-bezier(.2,.7,.2,1);
}
.world-dock::-webkit-scrollbar { display: none; }
.world-dock-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--glass-text);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.world-dock-btn i { color: var(--color-accent); }
.world-dock-btn:hover { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }
.world-dock-btn.is-active { background: var(--color-text); color: var(--color-bg); }
.world-dock-btn.is-active i { color: inherit; }

/* --- Side panel --- */
.world-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 30;
  width: var(--panel-width);
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  box-shadow: 0 30px 80px -20px rgba(16, 24, 40, 0.5);
  transform: translateX(calc(100% + 24px));
  transition: transform 550ms cubic-bezier(.2,.7,.2,1);
  overflow: hidden;
}
.world-panel.is-open { transform: none; }
.world-panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 18px 16px 20px;
  border-bottom: 1px solid var(--color-border-subtle);
  background: linear-gradient(135deg, color-mix(in srgb, var(--color-accent) 10%, var(--color-bg)), var(--color-bg) 70%);
}
.world-panel-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  color: #fff;
  font-size: 1.2rem;
  flex-shrink: 0;
  box-shadow: 0 10px 20px -8px rgba(36, 80, 216, 0.6);
}
.world-panel-titles { flex: 1; min-width: 0; }
.world-panel-sub { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--color-accent); }
.world-panel-title { font-size: 1.5rem; margin: 2px 0 0; }
.world-panel-full, .world-panel-close {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  background: var(--color-surface-elevated);
  flex-shrink: 0;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.world-panel-full:hover, .world-panel-close:hover { color: var(--color-accent); border-color: var(--color-accent); }
.world-panel-full[hidden] { display: none; }
.world-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 32px;
  overscroll-behavior: contain;
}
.world-panel-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}
.world-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  background: var(--color-surface-elevated);
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.world-nav-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.world-nav-btn i { font-size: 0.75rem; }

/* Re-fit the classic page content into the panel */
.world-panel-body .section { padding: 28px 0 8px; }
.world-panel-body .section:first-child { padding-top: 16px; }
.world-panel-body .container,
.world-panel-body .container-reading { max-width: none; padding: 0; }
.world-panel-body h2 { font-size: 1.45rem; margin-bottom: var(--space-md); }
.world-panel-body h3 { font-size: 1.15rem; }
.world-panel-body .section-divider { margin: 8px 0; max-width: none !important; }
.world-panel-body .achievement-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }
.world-panel-body .achievement-card { padding: var(--space-lg) var(--space-md); }
.world-panel-body .project-card { padding: var(--space-lg); }
.world-panel-body .project-grid,
.world-panel-body .coaching-images,
.world-panel-body .venture-showcase,
.world-panel-body .featured-grid { grid-template-columns: 1fr; }
.world-panel-body .company-hero { grid-template-columns: auto 1fr; padding: var(--space-lg); gap: var(--space-md); }
.world-panel-body .company-hero-cta { grid-column: 1 / -1; justify-content: center; }
.world-panel-body .about-prose { font-size: var(--text-base); }
.world-panel-body .interests-card { padding: var(--space-lg); }
.world-panel-body .award-spotlight { padding: var(--space-lg); gap: var(--space-md); }
.world-panel-body .timeline-item { padding-bottom: var(--space-lg); }

.world-panel-lead { padding-top: var(--space-lg); }
.world-panel-lead h2 { font-size: 1.6rem; margin-bottom: var(--space-sm); }
.world-panel-lead .world-hello { font-size: 2.2rem; }
.world-panel-lead .hero-badge { margin-bottom: var(--space-md); }
.world-panel-lead .hero-social { margin: var(--space-md) 0; }
.world-panel-lead .stat-ribbon { margin: var(--space-lg) 0 0; }

.world-panel-loading { padding: var(--space-2xl) 0; color: var(--color-text-muted); text-align: center; }
.world-panel-loading i { margin-right: 6px; }
.world-panel-intro { font-size: var(--text-lg); color: var(--color-text-secondary); margin: var(--space-lg) 0; }
.world-panel-more { margin-top: var(--space-xl); text-align: center; }

.world-subscribe {
  margin-top: var(--space-xl);
  padding: var(--space-xl);
  border-radius: var(--border-radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  text-align: center;
}
.world-subscribe h3 { margin-bottom: var(--space-xs); }
.world-subscribe p { font-size: var(--text-sm); margin-bottom: 0; }
.world-subscribe .newsletter-form { margin-top: var(--space-md); }

/* --- Loading screen --- */
.world-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
  transition: opacity 700ms ease, visibility 700ms;
}
.world-loading.is-done { opacity: 0; visibility: hidden; }
.world-loading-inner { text-align: center; color: #0b1220; }
.world-loading-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-md);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: 0 20px 40px -12px rgba(36, 80, 216, 0.6);
  animation: worldBob 1.6s ease-in-out infinite;
}
.world-loading-inner p { color: #0b1220; font-weight: 600; margin-bottom: var(--space-md); }
.world-loading-bar { width: 180px; height: 6px; margin: 0 auto; border-radius: 6px; background: rgba(255,255,255,0.6); overflow: hidden; }
.world-loading-bar span { display: block; width: 40%; height: 100%; border-radius: 6px; background: var(--gradient-accent); animation: worldLoad 1.2s ease-in-out infinite; }
@keyframes worldBob { 50% { transform: translateY(-8px); } }
@keyframes worldLoad { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

.world-fallback {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xl);
  text-align: center;
  background: var(--color-bg);
}
.world-fallback[hidden] { display: none; }
.world-fallback h1 { font-size: 2rem; }

/* --- Panel open state on desktop: slide the dock left of the panel --- */
@media (min-width: 821px) {
  body.panel-open .world-dock { transform: translateX(calc(-50% - var(--panel-width) / 2 - 6px)); }
  body.panel-open .world-hint { opacity: 0; }
}

/* --- Mobile --- */
@media (max-width: 820px) {
  body.world-body { --panel-height: 60vh; }
  .world-topbar { top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; }
  .world-chip span { display: none; }
  .world-brand-text small { display: none; }
  .world-hint { top: 72px; font-size: var(--text-xs); white-space: normal; text-align: center; width: max-content; max-width: calc(100vw - 32px); }
  .world-time { left: 12px; bottom: 76px; width: 200px; padding: 8px 12px 6px; border-radius: 14px; }
  .world-time-text { font-size: 0.92rem; }
  .world-time input[type="range"] { margin: 4px 0 0; }
  .world-time-caption { display: none; }
  .world-dock { bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; right: 12px; transform: none; max-width: none; }
  .world-dock-btn span { display: none; }
  .world-dock-btn { flex: 1; justify-content: center; padding: 10px; }
  .world-dock-btn i { font-size: 1rem; }
  .world-label-text small { display: none; }
  .world-label { padding: 4px 10px 4px 4px; }
  .world-label-icon { width: 26px; height: 26px; }
  .world-label-text strong { font-size: 0.78rem; }
  .world-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: var(--panel-height);
    border-radius: 24px 24px 0 0;
    transform: translateY(calc(100% + 24px));
  }
  .world-panel-head { padding: 14px 14px 12px 16px; }
  .world-panel-body { padding: 4px 16px 24px; }
  .world-panel-title { font-size: 1.2rem; }
  body.panel-open .world-time,
  body.panel-open .world-dock { opacity: 0; pointer-events: none; }
}
