/* ==========================================================================
   THE LIVING LLM: Physical 3D Lifecycle Walkthrough
   Visual Styling & Modern Glassmorphic Interface
   ========================================================================== */

:root {
  --bg-color: #070913;
  --panel-bg: rgba(13, 17, 30, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent-cyan: #00e5ff;
  --accent-purple: #9d4edd;
  --accent-amber: #ffb703;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: var(--font-sans);
  color: var(--text-primary);
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#webgl-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ==========================================================================
   HEADER HUD
   ========================================================================== */
.header-hud {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

.brand-card {
  pointer-events: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.4);
  animation: pulse-glow 3s infinite alternate;
}

@keyframes pulse-glow {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.06); filter: brightness(1.2); }
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 11px;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.header-controls {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-btn {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.hud-btn.active {
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.25), rgba(157, 78, 221, 0.25));
  border-color: var(--accent-cyan);
  color: #fff;
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.3);
}

.mode-toggle {
  background: rgba(13, 17, 30, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 3px;
  display: flex;
  gap: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: var(--accent-cyan);
  color: #030712;
  box-shadow: 0 2px 8px rgba(0, 229, 255, 0.4);
}

/* ==========================================================================
   SPARKY COMPANION STATUS WIDGET (Top Center)
   ========================================================================== */
.companion-widget {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: float-bar 4s ease-in-out infinite alternate;
}

@keyframes float-bar {
  0% { transform: translate(-50%, 0); }
  100% { transform: translate(-50%, -4px); }
}

.companion-avatar {
  font-size: 20px;
  filter: drop-shadow(0 0 8px rgba(255, 230, 0, 0.7));
}

.companion-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.companion-state-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(0, 229, 255, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 229, 255, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
}

/* ==========================================================================
   PHASE INTERACTION DRAWER (Right Floating Panel)
   ========================================================================== */
.phase-card {
  position: absolute;
  top: 86px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 200px);
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 20px;
  z-index: 10;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.phase-card::-webkit-scrollbar {
  width: 5px;
}
.phase-card::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
}

.phase-step-tag {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.phase-name {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}

.phase-badge {
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
}

.explanation-box {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent-cyan);
}

.kid-text {
  font-size: 14px;
  line-height: 1.5;
  color: #f1f5f9;
  font-weight: 500;
}

.tech-text {
  font-size: 12px;
  line-height: 1.6;
  color: #cbd5e1;
  font-family: var(--font-sans);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.tech-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tech-pill {
  font-size: 10px;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--accent-cyan);
  padding: 2px 7px;
  border-radius: 4px;
}

.interactive-arena {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.arena-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-amber);
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-btn {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  text-align: center;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}

.action-btn.primary {
  background: linear-gradient(135deg, var(--accent-cyan), #00b4d8);
  color: #030712;
  font-weight: 700;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 229, 255, 0.35);
}

.action-btn.primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(0, 229, 255, 0.5);
}

.action-btn.poke {
  background: linear-gradient(135deg, #f43f5e, #be123c);
  color: #fff;
  font-weight: 700;
  border: none;
  grid-column: 1 / -1;
  padding: 11px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35);
}

.action-btn.poke:hover {
  filter: brightness(1.15);
  box-shadow: 0 6px 20px rgba(244, 63, 94, 0.5);
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.slider-input {
  width: 100%;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

.telemetry-feed {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #38bdf8;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.4;
}

/* ==========================================================================
   BOTTOM STAGE RAIL & NAVIGATION
   ========================================================================== */
.stage-rail-hud {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  width: min(940px, calc(100vw - 32px));
}

.nav-cluster {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 6px 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}

.rail-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.rail-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.08);
}

.phases-carousel {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 4px;
}

.phases-carousel::-webkit-scrollbar {
  display: none;
}

.phase-pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  padding: 7px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.phase-pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.phase-pill.active {
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.25), rgba(157, 78, 221, 0.25));
  border-color: var(--accent-cyan);
  color: #fff;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.35);
}

.phase-num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
}

.phase-pill.active .phase-num {
  background: var(--accent-cyan);
  color: #030712;
}

.keyboard-hint-pill {
  pointer-events: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(13, 17, 30, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 4px 12px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kbd {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ==========================================================================
   POKE RESULT MODAL / SPEECH OVERLAY
   ========================================================================== */
.poke-dialog-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.poke-dialog-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.poke-dialog {
  background: #0f172a;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  width: min(540px, calc(100vw - 40px));
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8), 0 0 40px rgba(0, 229, 255, 0.2);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.poke-dialog-overlay.visible .poke-dialog {
  transform: scale(1);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.dialog-close:hover {
  color: #fff;
}

.dialog-prompt-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  color: var(--accent-cyan);
}

.dialog-output-box {
  background: #050814;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  font-size: 14px;
  line-height: 1.6;
  min-height: 120px;
  max-height: 240px;
  overflow-y: auto;
  font-family: var(--font-mono);
  color: #e2e8f0;
}

.dialog-lesson {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 12px;
  border-radius: 10px;
  border-left: 3px solid var(--accent-amber);
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */
@media (max-width: 860px) {
  .header-hud {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .phase-card {
    top: auto;
    bottom: 90px;
    right: 16px;
    left: 16px;
    width: auto;
    max-height: 48vh;
  }
  .companion-widget {
    display: none;
  }
  .stage-rail-hud {
    bottom: 12px;
  }
  .keyboard-hint-pill {
    display: none;
  }
}
