/* ==========================================================================
   KIDQUEST DECISION STUDIO - MAIN STYLESHEET
   Vanilla CSS3 + Shoelace Web Components Hybrid Architecture
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  /* Baseline Tokens */
  --font-display: 'Fredoka', cursive, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 24px var(--border-glow);

  --header-height: 68px;
  --sidebar-width: 320px;
  --transition-smooth: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --spring-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-body);
  user-select: none;
  -webkit-user-select: none;
}

/* --------------------------------------------------------------------------
   TOP APP BAR
   -------------------------------------------------------------------------- */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 2px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 50;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 240px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: var(--shadow-sm);
  animation: pulse-idle 3s ease-in-out infinite;
}

@keyframes pulse-idle {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--border-glow)); }
  50% { transform: scale(1.04); filter: drop-shadow(0 0 8px var(--border-glow)); }
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  line-height: 1.1;
}

.brand-text .sub-title {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Control Clusters */
.header-center-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  justify-content: center;
  max-width: 680px;
}

.model-selector-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.6rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   MAIN WORKSPACE SPLIT (Sidebar + Interactive SVG Canvas)
   -------------------------------------------------------------------------- */
.workspace-container {
  position: absolute;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  overflow: hidden;
}

/* LEFT PALETTE SIDEBAR */
.palette-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-surface);
  border-right: 2px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 20;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-smooth);
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-nav {
  display: flex;
  padding: 0.5rem 0.75rem;
  gap: 0.4rem;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.cat-btn {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all var(--transition-smooth);
}

.cat-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.cat-btn.active {
  background: var(--accent-main);
  color: #000000;
  font-weight: 700;
  box-shadow: 0 2px 8px var(--border-glow);
}

.palette-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Palette Card (Draggable Block) */
.palette-block {
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  cursor: grab;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  transition: transform var(--spring-bounce), border-color var(--transition-smooth), box-shadow var(--transition-smooth);
}

.palette-block:hover {
  transform: translateY(-2px) scale(1.02);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md);
}

.palette-block:active {
  cursor: grabbing;
}

.block-avatar {
  font-size: 1.75rem;
  line-height: 1;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.block-info {
  flex: 1;
}

.block-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.block-desc {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.block-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  margin-top: 0.4rem;
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  color: var(--badge-text);
}

/* --------------------------------------------------------------------------
   CANVAS VIEWPORT & SVG WIRING
   -------------------------------------------------------------------------- */
.canvas-viewport {
  flex: 1;
  height: 100%;
  position: relative;
  background-color: var(--bg-canvas);
  background-image: var(--canvas-pattern);
  background-size: 28px 28px;
  overflow: hidden;
  cursor: default;
}

#wireSvg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.wire-path {
  fill: none;
  stroke: var(--wire-default);
  stroke-width: 4;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--border-glow));
  transition: stroke 0.3s ease;
}

.wire-path.active-wire {
  stroke: var(--wire-pulse);
  stroke-width: 5;
  stroke-dasharray: 8 6;
  animation: wire-flow 1.2s linear infinite;
}

.wire-path.yes-wire {
  stroke: var(--wire-yes);
}

.wire-path.no-wire {
  stroke: var(--wire-no);
}

@keyframes wire-flow {
  from { stroke-dashoffset: 28; }
  to { stroke-dashoffset: 0; }
}

/* --------------------------------------------------------------------------
   DECISION NODES ON CANVAS
   -------------------------------------------------------------------------- */
.node {
  position: absolute;
  width: 290px;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  cursor: move;
  z-index: 20;
  transition: box-shadow var(--transition-smooth), border-color var(--transition-smooth), transform 0.15s ease;
}

.node:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.node.selected {
  border-color: var(--accent-main);
  box-shadow: 0 0 0 3px var(--border-glow), var(--shadow-lg);
}

.node.executing {
  animation: node-bounce 0.8s ease-in-out infinite alternate;
  border-color: #38bdf8;
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.7);
}

@keyframes node-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

.node-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  background: rgba(255, 255, 255, 0.03);
}

.node-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.node-icon {
  font-size: 1.35rem;
}

.node-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.node-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.node-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-smooth);
}

.node-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.node-body {
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.node-prompt {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.node-badge-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Ports & Connection Handles */
.ports-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.85rem;
  background: rgba(0, 0, 0, 0.2);
  border-bottom-left-radius: inherit;
  border-bottom-right-radius: inherit;
  border-top: 1px solid var(--border-subtle);
}

.port {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
}

.port-handle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 3px solid var(--accent-main);
  cursor: crosshair;
  transition: transform var(--spring-bounce), background-color var(--transition-smooth);
}

.port-handle:hover {
  transform: scale(1.35);
  background: var(--accent-main);
  box-shadow: 0 0 10px var(--border-glow);
}

.port-handle.port-yes {
  border-color: var(--accent-secondary);
}

.port-handle.port-no {
  border-color: var(--accent-danger);
}

/* --------------------------------------------------------------------------
   SIMULATOR MASCOT ("Pip the Owl" & "Sparky the Cheetah")
   -------------------------------------------------------------------------- */
#mascotAvatar {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--accent-main);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 15px var(--border-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  z-index: 35;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#mascotAvatar.active {
  opacity: 1;
  animation: mascot-hop 0.4s ease-in-out infinite alternate;
}

@keyframes mascot-hop {
  from { transform: translate(-50%, -50%) scale(1); }
  to { transform: translate(-50%, -58%) scale(1.1); }
}

/* --------------------------------------------------------------------------
   BOTTOM CONTROLS DOCK
   -------------------------------------------------------------------------- */
.bottom-dock {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 2px solid var(--border-accent);
  border-radius: var(--radius-full);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 30;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

/* --------------------------------------------------------------------------
   BREATHING WIDGET (For Big Feelings / Stoplight Model)
   -------------------------------------------------------------------------- */
.breathing-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 1.5rem;
}

.breathing-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.3) 0%, rgba(16, 185, 129, 0.1) 70%);
  border: 4px solid var(--sl-color-primary-500);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  box-shadow: 0 0 30px var(--border-glow);
  animation: breathe-cycle 6s ease-in-out infinite;
}

@keyframes breathe-cycle {
  0%, 100% { transform: scale(0.8); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; filter: drop-shadow(0 0 15px rgba(56, 189, 248, 0.8)); }
}

/* --------------------------------------------------------------------------
   RESPONSIVE ADJUSTMENTS (iPads / Mobile)
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 260px;
    --header-height: 60px;
  }
  .brand-text .sub-title { display: none; }
  .node { width: 250px; }
}

@media (max-width: 680px) {
  .palette-sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
  }
  .palette-sidebar.open {
    transform: translateX(0);
  }
}
