:root {
  --pg-bg: #07090f;
  --pg-panel: rgba(255, 255, 255, 0.04);
  --pg-border: rgba(255, 255, 255, 0.08);
  --pg-ink: rgba(255, 255, 255, 0.92);
  --pg-accent: #7ef3ff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body.playground-shell {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 10%, rgba(126, 243, 255, 0.1), transparent 45%), var(--pg-bg);
  color: var(--pg-ink);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  display: flex;
  flex-direction: column;
}

.pg-menu-bar {
  display: flex;
  gap: 10px;
  width: 100%;
}

.pg-menu {
  position: relative;
}

.pg-menu button {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.pg-menu button:hover,
.pg-menu button:focus {
  background: rgba(255, 255, 255, 0.08);
}

.pg-menu ul {
  display: none;
  position: absolute;
  top: 28px;
  left: 0;
  min-width: 160px;
  backdrop-filter: blur(12px);
  background: rgba(9, 11, 18, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 8px 0;
  list-style: none;
  margin: 0;
}

.pg-menu:hover ul {
  display: block;
}

.pg-menu ul li {
  padding: 6px 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}

.pg-menu ul li:hover {
  background: rgba(255, 255, 255, 0.08);
}

.playground-main {
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(600px, 1fr) 300px;
  gap: 20px;
  padding: clamp(20px, 3vw, 40px);
  align-items: stretch;
}

.canvas-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  min-height: 0;
  height: 100%;
}

/* Side panels styling */
.playground-main > .panel:first-child,
.playground-main > .panel:last-child {
  border-radius: 24px;
  background: var(--pg-panel);
  border: 1px solid var(--pg-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

/* Middle canvas panel - distinct styling */
.canvas-panel {
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.98);
  border: 2px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  position: relative;
}

/* Generic panel fallback */
.panel {
  border-radius: 24px;
  background: var(--pg-panel);
  border: 1px solid var(--pg-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--pg-border);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.68);
}

.canvas-menu-bar {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 0;
  background: rgba(250, 250, 252, 0.95);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
}

.menu-set {
  display: flex;
  gap: 10px;
}

.menu-set.hidden {
  display: none;
}

.canvas-menu {
  position: relative;
  z-index: 3;
}

.canvas-menu button {
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: rgba(0, 0, 0, 0.85);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-transform: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.canvas-menu button:hover {
  background: rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.95);
}

.canvas-menu ul {
  display: none;
  position: absolute;
  top: 38px;
  left: 0;
  min-width: 200px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 6px 0;
  list-style: none;
  z-index: 4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
}

.canvas-menu.open ul,
.canvas-menu:hover ul {
  display: block;
}

.canvas-menu ul li {
  padding: 8px 16px;
  font-size: 13px;
  letter-spacing: 0.01em;
  text-transform: none;
  color: rgba(0, 0, 0, 0.85);
  cursor: pointer;
  transition: background 0.15s ease;
}

.canvas-menu ul li:hover {
  background: rgba(0, 0, 0, 0.05);
  color: rgba(0, 0, 0, 0.95);
}

.panel-content {
  flex: 1;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.canvas-surface {
  position: relative;
  flex: 1;
  border-radius: 20px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  overflow: hidden;
  min-height: 500px;
  margin: 16px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04);
}

.canvas-surface canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-status-note {
  position: absolute;
  bottom: 16px;
  right: 16px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.35);
  pointer-events: none;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.canvas-status-note[data-intent="error"] {
  color: rgba(239, 68, 68, 0.95);
  background: rgba(254, 226, 226, 0.9);
  border-color: rgba(239, 68, 68, 0.2);
}

.canvas-hud {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.canvas-hud .status-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.canvas-hud .status-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: rgba(0, 0, 0, 0.5);
}

.canvas-hud .status-value {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(0, 0, 0, 0.9);
}

.canvas-guard {
  position: absolute;
  inset: 0;
  background: rgba(7, 9, 15, 0.18);
  cursor: not-allowed;
  transition: opacity 0.2s ease;
}

.canvas-guard.hidden {
  display: none;
}

.legend-stub {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}

/* Hide mobile panel toggles on desktop */
.panel-toggle {
  display: none;
}

.panel-toggle-hidden {
  display: none !important;
}

.tool-tabs {
  display: flex;
  gap: 8px;
}

.tool-tabs button {
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.1em;
  padding: 10px 12px;
  cursor: pointer;
}

.tool-tabs button.active {
  border-color: rgba(126, 243, 255, 0.8);
  background: rgba(126, 243, 255, 0.15);
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-toggle button {
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.15em;
  padding: 10px 14px;
  cursor: pointer;
}

.mode-toggle button.active {
  border-color: rgba(126, 243, 255, 0.8);
  background: rgba(126, 243, 255, 0.15);
}

.builder-toolbox,
.tutorial-deck {
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.builder-toolbox h4,
.tutorial-deck h4 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}

.tool-list,
.tutorial-listing {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-list li {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
  cursor: grab;
  user-select: none;
  transition: background 0.2s ease, border 0.2s ease, transform 0.2s ease;
}

.tool-list li:hover,
.tool-list li.active {
  background: rgba(126, 243, 255, 0.12);
  border-color: rgba(126, 243, 255, 0.4);
  color: #7ef3ff;
  transform: translateX(4px);
}

.tool-list li:active {
  cursor: grabbing;
}

.tutorial-listing li {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
}

.tutorial-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.02);
}

.tutorial-card button {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
}

.tutorial-card.active {
  border-color: rgba(126, 243, 255, 0.6);
  background: rgba(126, 243, 255, 0.08);
}

.tutorial-card strong {
  display: block;
  margin-bottom: 6px;
}

.tutorial-detail {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.02);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tutorial-detail-title {
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
}

.tutorial-detail-description {
  margin: 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
}

.tutorial-detail-notes {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(126, 243, 255, 0.7);
}

.hidden {
  display: none !important;
}

.inspector-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inspector-list li {
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}


.dag-toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1500;
}

.dag-toast {
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(7, 9, 15, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--pg-accent);
  font-size: 13px;
}

.dag-toast-success {
  border-color: rgba(46, 204, 113, 0.65);
}

.dag-toast-error {
  border-color: rgba(255, 99, 71, 0.75);
}

.dag-loading-indicator {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1600;
}

.dag-loading-indicator.visible {
  display: flex;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--pg-accent);
  animation: playground-spin 0.9s linear infinite;
}

.loading-text {
  color: var(--pg-accent);
  font-weight: 600;
  margin-left: 12px;
  letter-spacing: 0.08em;
}

@keyframes playground-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================================================
   MOBILE OPTIMIZATIONS
   ======================================================================== */

/* Tablet: Reduce panel widths */
@media (max-width: 1024px) {
  .playground-main {
    grid-template-columns: 280px minmax(0, 1fr) 260px;
    gap: 20px;
    padding: clamp(20px, 3vw, 40px);
  }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  /* Single column layout on mobile */
  .playground-main {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto 1fr;
    gap: 16px;
    padding: 16px;
  }
  
  /* Hide side panels by default, show as overlays when needed */
  .playground-main > .panel:first-child,
  .playground-main > .panel:last-child {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-radius: 0;
    border-right: 1px solid var(--pg-border);
  }
  
  .playground-main > .panel:last-child {
    left: auto;
    right: 0;
    transform: translateX(100%);
    border-right: none;
    border-left: 1px solid var(--pg-border);
  }
  
  /* Show panel when active */
  .playground-main > .panel.panel-open {
    transform: translateX(0);
  }
  
  /* Overlay backdrop when panel is open */
  .playground-main::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .playground-main.panel-open::before {
    opacity: 1;
    pointer-events: all;
  }
  
  /* Center canvas section takes full width */
  .canvas-panel {
    width: 100%;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
  }
  
  /* Header optimizations */
  .app-header {
    padding: 10px 16px;
    flex-wrap: wrap;
  }
  
  .app-logo {
    font-size: 14px;
  }
  
  .header-nav {
    order: 3;
    width: 100%;
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  
  .header-btn {
    font-size: 12px;
    padding: 6px 12px;
    min-height: 36px; /* Touch-friendly */
  }
  
  /* Panel header - add toggle button */
  .panel header {
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
  }
  
  /* Panel toggle buttons (mobile only) */
  .panel-toggle,
  .panel-toggle-hidden {
    display: block !important;
    position: fixed;
    bottom: 20px;
    z-index: 250;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--pg-accent);
    border: none;
    color: #000;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(126, 243, 255, 0.3);
    transition: transform 0.2s ease, opacity 0.2s ease;
    font-weight: 600;
  }
  
  .panel-toggle:active {
    transform: scale(0.95);
  }
  
  .panel-toggle-left {
    left: 20px;
  }
  
  .panel-toggle-right {
    right: 20px;
  }
  
  /* Hide toggle when panel is open */
  .playground-main > .panel:first-child.panel-open ~ .panel-toggle-left,
  .playground-main > .panel:last-child.panel-open ~ .panel-toggle-right {
    opacity: 0.5;
  }
  
  
  /* Canvas menu bar mobile */
  .canvas-menu-bar {
    padding: 6px;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }
  
  .menu-set {
    gap: 6px;
    flex-wrap: wrap;
  }
  
  .canvas-menu button {
    padding: 8px 12px;
    font-size: 12px;
    min-height: 36px; /* Touch-friendly */
  }
  
  .canvas-menu ul {
    min-width: 160px;
    font-size: 12px;
  }
  
  /* Canvas surface mobile */
  .canvas-surface {
    min-height: 400px;
    border-radius: 18px;
  }
  
  /* Panel content mobile */
  .panel-content {
    padding: 14px 18px;
    gap: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Mode toggle mobile */
  .mode-toggle {
    gap: 8px;
  }
  
  .mode-toggle button {
    padding: 12px 14px;
    font-size: 11px;
    min-height: 44px; /* Touch-friendly */
  }
  
  /* Tool list mobile */
  .tool-list li,
  .tutorial-listing li {
    padding: 12px 14px;
    font-size: 13px;
    min-height: 44px; /* Touch-friendly */
    display: flex;
    align-items: center;
  }
  
  /* Builder toolbox mobile */
  .builder-toolbox,
  .tutorial-deck {
    padding: 12px;
    gap: 10px;
  }
  
  .builder-toolbox h4,
  .tutorial-deck h4 {
    font-size: 11px;
  }
  
  /* Inspector list mobile */
  .inspector-list {
    gap: 10px;
  }
  
  .inspector-list li {
    padding: 12px 14px;
    font-size: 13px;
  }
  
  /* Canvas HUD mobile */
  .canvas-hud {
    bottom: 12px;
    left: 12px;
    padding: 6px 10px;
    font-size: 10px;
    gap: 8px;
  }
  
  .canvas-status-note {
    bottom: 12px;
    right: 12px;
    font-size: 11px;
  }
  
  /* Toast container mobile */
  .dag-toast-container {
    top: 16px;
    right: 16px;
    left: 16px;
    max-width: calc(100vw - 32px);
  }
  
  .dag-toast {
    min-width: auto;
    width: 100%;
    padding: 12px 16px;
    font-size: 12px;
  }
}

/* Extra small mobile */
@media (max-width: 640px) {
  .playground-main {
    padding: 12px;
    gap: 12px;
  }
  
  .app-header {
    padding: 8px 12px;
  }
  
  .app-logo {
    font-size: 12px;
  }
  
  .header-nav {
    gap: 6px;
  }
  
  .header-btn {
    font-size: 11px;
    padding: 5px 10px;
    min-height: 32px;
  }
  
  .panel header {
    padding: 12px 16px;
    font-size: 11px;
  }
  
  .panel-content {
    padding: 12px 16px;
  }
  
  .canvas-menu-bar {
    padding: 4px;
    gap: 6px;
  }
  
  .canvas-menu button {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 32px;
  }
  
  .canvas-surface {
    min-height: 350px;
    border-radius: 16px;
  }
  
  .mode-toggle button {
    padding: 10px 12px;
    font-size: 10px;
    min-height: 40px;
  }
  
  .tool-list li,
  .tutorial-listing li {
    padding: 10px 12px;
    font-size: 12px;
    min-height: 40px;
  }
  
  .panel-toggle {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  
  .panel-toggle-left {
    left: 16px;
    bottom: 16px;
  }
  
  .panel-toggle-right {
    right: 16px;
    bottom: 16px;
  }
  
  /* Prevent text size adjustment on iOS */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  
  /* Improve touch targets */
  button, a, .canvas-menu button, .mode-toggle button, .tool-list li {
    -webkit-tap-highlight-color: rgba(126, 243, 255, 0.2);
    tap-highlight-color: rgba(126, 243, 255, 0.2);
  }
}

