/**
 * styles.css
 * CodeMentor - Educational Coding Playground & AI Tutor
 * 
 * High-performance, zero-framework CSS design system.
 * Features WCAG 2.1 AA compliant dark & light themes,
 * responsive desktop 3-region layout, mobile bottom-nav tabs,
 * synchronized editor gutter, and accessible modal styling.
 */

/* ==========================================================================
   1. CSS RESET & DESIGN TOKENS
   ========================================================================== */

:root {
  /* Pastel Dragon Ball Theme - Dark Mode (Default) */
  --bg-app: #121524;              /* Deep Gi Indigo space */
  --bg-surface: #181d32;          /* Dragon Ball Navy surface */
  --bg-surface-elevated: #222944;   /* Elevated Slate Indigo */
  --bg-surface-hover: #2e375c;
  --border-subtle: #232b49;
  --border-default: #343e68;
  --border-focus: #ff9e64;        /* Goku Gi Warm Pastel Orange */

  --text-primary: #f8fafc;
  --text-secondary: #a9b5db;      /* Soft lavender slate */
  --text-muted: #7280ab;
  --text-inverse: #121524;

  /* Dragon Ball Signature Accents (Softened Pastel) */
  --accent-primary: #ff8c4a;      /* Goku Gi Pastel Orange */
  --accent-primary-hover: #f97316;
  --accent-highlight: #ffae75;    /* Warm Apricot / Peach highlight */
  --accent-gold: #fde047;         /* Super Saiyan Pastel Aura Gold */
  --accent-glow: rgba(255, 140, 74, 0.28);

  --color-success: #4ade80;       /* Shenron Pastel Jade/Mint */
  --color-success-bg: rgba(74, 222, 128, 0.16);
  --color-warning: #fde047;       /* Dragon Ball Amber/Gold */
  --color-warning-bg: rgba(253, 224, 71, 0.16);
  --color-danger: #f87171;        /* Dragon Ball Star Crimson */
  --color-danger-bg: rgba(248, 113, 113, 0.16);
  --color-info: #38bdf8;          /* Capsule Corp Soft Cyan */
  --color-info-bg: rgba(56, 189, 248, 0.16);
  --color-purple: #c084fc;        /* Lilac accent */

  --font-pixel: "Press Start 2P", monospace, cursive;
  --font-retro: "Silkscreen", monospace, cursive;
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 8px -1px rgba(0, 0, 0, 0.35), 0 2px 4px -2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 20px -3px rgba(0, 0, 0, 0.45), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

  --header-height: 54px;
  --banner-height: 52px;
  --mobile-nav-height: 56px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  background-image: 
    radial-gradient(rgba(244, 140, 66, 0.06) 1px, transparent 1px),
    radial-gradient(rgba(247, 208, 80, 0.04) 1px, transparent 1px);
  background-size: 24px 24px, 48px 48px;
  background-position: 0 0, 12px 12px;
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessible focus visible rings */
:focus-visible {
  outline: 2px solid var(--accent-highlight);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   2. BUTTONS, BADGES & CONTROLS
   ========================================================================== */

button, input, select, textarea {
  font-family: inherit;
  font-size: 0.9rem;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
  user-select: none;
}

button:active {
  transform: scale(0.98);
}

.btn {
  padding: 6px 14px;
  font-size: 0.875rem;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #121524;
  font-family: var(--font-retro);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 2px solid var(--accent-highlight);
  border-radius: 4px;
  box-shadow: 0 3px 0 #9a4811, 0 4px 0 #000;
}
.btn-primary:hover {
  background-color: var(--accent-primary-hover);
  transform: translateY(1px);
  box-shadow: 0 2px 0 #9a4811, 0 3px 0 #000;
}
.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 transparent;
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-family: var(--font-retro);
  font-size: 0.78rem;
  font-weight: 600;
  border: 2px solid var(--border-default);
  border-radius: 4px;
  box-shadow: 0 3px 0 #101322, 0 4px 0 #000;
}
.btn-secondary:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent-highlight);
  transform: translateY(1px);
  box-shadow: 0 2px 0 #101322, 0 3px 0 #000;
}
.btn-secondary:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 transparent;
}

.btn-subtle {
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-retro);
  font-size: 0.74rem;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  box-shadow: 0 2px 0 #101322;
}
.btn-subtle:hover {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--accent-highlight);
  transform: translateY(1px);
}

.btn-danger {
  background-color: var(--color-danger);
  color: white;
  border-radius: 4px;
  box-shadow: 0 3px 0 #991b1b, 0 4px 0 #000;
}
.btn-danger:hover {
  filter: brightness(0.9);
  transform: translateY(1px);
}

.btn-run {
  background-color: #f48c42;
  color: #121524;
  padding: 7px 16px;
  font-weight: 700;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  border: 2px solid #f7d050;
  border-radius: 4px;
  box-shadow: 0 4px 0 #9a4811, 0 5px 0 #000;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.1s ease;
}
.btn-run:hover {
  background-color: #ff9e58;
  transform: translateY(2px);
  box-shadow: 0 2px 0 #9a4811, 0 3px 0 #000;
}
.btn-run:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 transparent;
}

.btn-audit {
  background-color: #16a34a;
  color: #ffffff;
  padding: 7px 16px;
  font-weight: 700;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  border: 2px solid #4ade80;
  border-radius: 4px;
  box-shadow: 0 4px 0 #0f5132, 0 5px 0 #000;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.1s ease;
}
.btn-audit:hover {
  background-color: #22c55e;
  transform: translateY(2px);
  box-shadow: 0 2px 0 #0f5132, 0 3px 0 #000;
}
.btn-audit:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 transparent;
}

.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-xs { padding: 2px 8px; font-size: 0.72rem; }
.btn-block { width: 100%; }

.btn-icon-square {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 1rem;
}
.btn-icon-square:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-icon-small {
  padding: 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.btn-icon-small:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

/* Badges */
/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 0.65rem;
  font-family: var(--font-retro);
  font-weight: 700;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid currentColor;
}

.badge-cat {
  background-color: var(--color-info-bg);
  color: var(--color-info);
  border-color: rgba(103, 232, 249, 0.4);
}

.badge-diff {
  background-color: var(--color-warning-bg);
  color: var(--color-warning);
  border-color: rgba(247, 208, 80, 0.4);
}

.badge-status {
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.badge-status.solved {
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border-color: rgba(74, 222, 128, 0.4);
}

.count-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  font-size: 0.65rem;
  font-family: var(--font-pixel);
  border-radius: 3px;
  background-color: var(--bg-surface-hover);
  color: var(--accent-highlight);
  border: 1px solid var(--border-default);
  text-align: center;
  margin-left: 4px;
  box-shadow: 0 1px 0 #000;
}
.count-badge.danger { background-color: var(--color-danger); color: white; border-color: var(--color-danger); }
.count-badge.warning { background-color: var(--color-warning); color: #121524; border-color: var(--color-warning); }
.count-badge.info { background-color: var(--accent-primary); color: #121524; border-color: var(--accent-highlight); }

kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 1px 4px;
  border-radius: 3px;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}

/* ==========================================================================
   3. APP SHELL & HEADER
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.app-header {
  height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 2px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.header-branding {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}
.brand-logo {
  font-family: var(--font-pixel);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--accent-primary);
  background-color: #121524;
  padding: 4px 8px;
  border-radius: 4px;
  border: 2px solid var(--accent-highlight);
  box-shadow: 0 2px 0 #000;
}
.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-title {
  font-family: var(--font-pixel);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--accent-highlight);
  text-shadow: 2px 2px 0px #000;
  display: flex;
  align-items: center;
  gap: 6px;
}
.db-star {
  color: #ef4444;
  font-size: 1.15rem;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.7);
  display: inline-block;
}
.brand-badge {
  font-family: var(--font-retro);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent-highlight);
  background: rgba(244, 140, 66, 0.12);
  border: 1px solid var(--accent-primary);
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.header-challenge-nav {
  flex: 1;
  max-width: 460px;
}

.challenge-dropdown {
  width: 100%;
  padding: 6px 12px;
  border-radius: 4px;
  background-color: var(--bg-surface-elevated);
  border: 2px solid var(--border-default);
  color: var(--text-primary);
  font-family: var(--font-retro);
  font-size: 0.72rem;
  cursor: pointer;
  outline: none;
  box-shadow: 0 2px 0 #000;
}
.challenge-dropdown:focus {
  border-color: var(--accent-highlight);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-divider {
  width: 1px;
  height: 22px;
  background-color: var(--border-default);
  margin: 0 4px;
}

/* Challenge Goal Banner */
.challenge-banner {
  min-height: var(--banner-height);
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 16px;
  flex-shrink: 0;
}
.challenge-banner-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.challenge-banner-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}
.challenge-banner-goal {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.challenge-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ==========================================================================
   4. DESKTOP WORKSPACE (3-REGION FLEX LAYOUT)
   ========================================================================== */

.app-workspace {
  flex: 1;
  display: flex;
  position: relative;
  gap: 8px;
  padding: 8px;
  height: calc(100dvh - var(--header-height) - var(--banner-height));
  overflow: hidden;
  background-color: var(--bg-app);
}

/* LEFT SECTION: CODE EDITOR & CONSOLE DRAWER */
.workspace-side-left {
  width: 480px;
  flex-shrink: 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: width 0.28s cubic-bezier(0.16, 1, 0.3, 1), margin 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-workspace.editor-collapsed .workspace-side-left {
  width: 0;
  min-width: 0;
  max-width: 0;
  margin-right: -8px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: translateX(-30px);
}

/* Top Toolbar Side Toggle Buttons */
.btn-side-toggle {
  font-family: var(--font-retro);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  box-shadow: 0 2px 0 #000;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-side-toggle:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--accent-highlight);
  transform: translateY(1px);
}
.btn-side-toggle.active {
  background-color: rgba(244, 140, 66, 0.18);
  color: var(--accent-highlight);
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Left Floating Rail Tab (When Editor is Collapsed) */
.editor-rail-tab {
  display: none;
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 60;
  background: var(--bg-surface-elevated);
  color: var(--accent-highlight);
  border: 2px solid var(--accent-highlight);
  border-left: none;
  border-radius: 0 8px 8px 0;
  padding: 16px 10px;
  min-width: 48px;
  min-height: 120px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.6), 0 0 12px var(--accent-glow);
  transition: all 0.15s ease;
}

.app-workspace.editor-collapsed .editor-rail-tab {
  display: flex;
}

.editor-rail-tab:hover {
  background-color: var(--bg-surface-hover);
  color: #ffffff;
  padding-left: 16px;
  transform: translateY(-50%) scale(1.05);
  box-shadow: 6px 0 24px rgba(244, 140, 66, 0.6), 0 0 16px var(--accent-highlight);
}

.editor-rail-tab .rail-chevron {
  font-size: 0.85rem;
  color: var(--accent-primary);
  writing-mode: horizontal-tb;
  animation: pulse-right 1.2s infinite ease-in-out;
}
@keyframes pulse-right {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(3px); }
}

.editor-rail-tab .rail-icon {
  font-size: 1.1rem;
  writing-mode: horizontal-tb;
}

.editor-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-collapse-side {
  font-family: var(--font-retro);
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text-secondary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  padding: 3px 8px;
  box-shadow: 0 2px 0 #000;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-collapse-side:hover {
  color: var(--accent-highlight);
  border-color: var(--accent-highlight);
  background-color: var(--bg-surface-hover);
  transform: translateY(1px);
}

.editor-inspector-wrapper {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-default);
  background-color: var(--bg-surface);
}

.panel-editor {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

/* CENTER SECTION: PREVIEW CANVAS & DOCKED BOTTOM INSPECTOR */
.panel-preview {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-default);
  background-color: var(--bg-surface);
}

.preview-viewport-container {
  flex: 1;
  position: relative;
  background-color: var(--bg-app);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-bottom: 48px; /* Clearance for docked bottom inspector tab bar */
  transition: all var(--transition-normal);
}

/* COLLAPSIBLE BOTTOM INSPECTOR: 50% CANVAS OVERLAY */
.panel-inspector {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  max-height: 50%;
  z-index: 30;
  border-radius: 0;
  border: none;
  border-top: 3px solid var(--accent-highlight);
  background-color: var(--bg-surface-elevated);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  transition: height 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.panel-inspector.collapsed {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
  border-top: 2px solid var(--border-default);
  background-color: var(--bg-surface);
}

.panel-inspector.collapsed .inspector-body {
  display: none;
}

/* Mobile View Mode: Centered Phone Frame */
.preview-viewport-container.mode-mobile .device-frame {
  width: 390px;
  max-width: 100%;
  height: 100%;
  max-height: 844px;
  background-color: #ffffff;
  border-radius: 28px;
  border: 4px solid var(--border-default);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.3s cubic-bezier(0.16, 1, 0.3, 1), border-radius 0.3s ease;
}

.device-notch {
  height: 22px;
  background-color: #171b2b;
  border-radius: 0 0 12px 12px;
  width: 120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 10;
  flex-shrink: 0;
}
.device-speaker {
  width: 38px;
  height: 4px;
  background-color: #2f3750;
  border-radius: 2px;
}
.device-camera {
  width: 8px;
  height: 8px;
  background-color: #0d101a;
  border-radius: 50%;
  border: 1px solid #2f3750;
}

/* Desktop View Mode: Full Bleed Widescreen */
.preview-viewport-container.mode-desktop {
  padding: 0;
}
.preview-viewport-container.mode-desktop .device-frame {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.preview-viewport-container.mode-desktop .device-notch {
  display: none;
}

.preview-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background-color: #ffffff;
  display: block;
}

.btn-mode-toggle {
  font-family: var(--font-retro);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--accent-highlight);
  border-color: rgba(255, 140, 74, 0.25);
}
.btn-mode-toggle:hover {
  border-color: var(--accent-highlight);
  background-color: rgba(255, 140, 74, 0.1);
}

/* RIGHT SECTION: AI TUTOR PANEL (COLLAPSIBLE SIDEBAR) */
.panel-tutor {
  width: 380px;
  flex-shrink: 0;
  height: 100%;
  transition: width 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), margin 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-workspace.tutor-collapsed .panel-tutor {
  width: 0;
  min-width: 0;
  max-width: 0;
  margin-left: -8px;
  opacity: 0;
  pointer-events: none;
  border: none;
  overflow: hidden;
  transform: translateX(30px);
}

/* Floating rail tab on right edge when AI Mentor is collapsed */
.tutor-rail-tab {
  display: none;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 60;
  background: var(--bg-surface-elevated);
  color: var(--accent-highlight);
  border: 2px solid var(--accent-highlight);
  border-right: none;
  border-radius: 8px 0 0 8px;
  padding: 16px 10px;
  min-width: 48px;
  min-height: 120px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6), 0 0 12px var(--accent-glow);
  transition: all 0.15s ease;
}

.app-workspace.tutor-collapsed .tutor-rail-tab {
  display: flex;
}

.tutor-rail-tab:hover {
  background-color: var(--bg-surface-hover);
  color: #ffffff;
  padding-right: 16px;
  transform: translateY(-50%) scale(1.05);
  box-shadow: -6px 0 26px rgba(244, 140, 66, 0.6), 0 0 16px var(--accent-highlight);
}

.tutor-rail-tab .rail-chevron {
  font-size: 0.85rem;
  color: var(--accent-primary);
  writing-mode: horizontal-tb;
  animation: pulse-left 1.2s infinite ease-in-out;
}
@keyframes pulse-left {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-3px); }
}

.tutor-rail-tab .rail-icon {
  font-size: 1.1rem;
  writing-mode: horizontal-tb;
}

.tutor-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-collapse-tutor {
  font-family: var(--font-retro);
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text-secondary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  padding: 3px 8px;
  box-shadow: 0 2px 0 #000;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-collapse-tutor:hover {
  color: var(--accent-highlight);
  border-color: var(--accent-highlight);
  background-color: var(--bg-surface-hover);
  transform: translateY(1px);
}

.btn-toggle-drawer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--accent-highlight);
  border-color: rgba(255, 140, 74, 0.25);
}
.btn-toggle-drawer:hover {
  background-color: rgba(255, 140, 74, 0.1);
  color: #ffffff;
  border-color: var(--accent-highlight);
}

.workspace-panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  height: 38px;
  padding: 0 12px;
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-icon {
  font-size: 0.95rem;
}
.panel-title {
  font-family: var(--font-retro);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.04em;
}
.panel-subtitle {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.preview-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  padding: 24px;
  text-align: center;
  z-index: 2;
}
.empty-state-graphic {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: var(--accent-highlight);
}
.preview-empty-state h4 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.preview-empty-state p {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 400px;
  margin-bottom: 16px;
}

/* ==========================================================================
   6. MULTI-TAB CODE EDITOR
   ========================================================================== */

.editor-tabs {
  display: flex;
  align-items: stretch;
  height: 100%;
}
.editor-tab {
  padding: 0 16px;
  height: 100%;
  border-right: 1px solid var(--border-subtle);
  border-radius: 0;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  background: transparent;
}
.editor-tab:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}
.editor-tab.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-top: 2px solid var(--accent-highlight);
}

.tab-badge {
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
}
.html-badge { color: #f97316; }
.css-badge { color: #38bdf8; }
.js-badge { color: #facc15; }

.editor-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.editor-workspace {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-app);
}

.editor-gutter {
  width: 44px;
  padding: 8px 6px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
  text-align: right;
  user-select: none;
  overflow: hidden;
  white-space: pre-wrap;
}

.code-textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 8px 12px;
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  outline: none;
}

.editor-footer {
  height: 24px;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   7. AI TUTOR PANEL
   ========================================================================== */

.tutor-mode-switcher {
  display: flex;
  background-color: var(--bg-surface);
  border-radius: var(--radius-full);
  padding: 2px;
  border: 1px solid var(--border-subtle);
}
.mode-pill {
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.mode-pill.active {
  background-color: var(--accent-primary);
  color: white;
}

/* Hint Ladder Stepper */
.hint-ladder-container {
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 14px;
}
.ladder-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 8px;
}
.ladder-title {
  font-weight: 600;
  color: var(--text-primary);
}
.ladder-step-name {
  color: var(--accent-highlight);
}

.ladder-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 8px;
}
.step-indicator {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  border: 2px solid var(--border-default);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  font-weight: 700;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 0 #000;
}
.step-indicator.active {
  border-color: #f7d050;
  background: radial-gradient(circle at 35% 35%, #ffd066, #e76f18);
  color: #ef4444;
  text-shadow: 0 1px 1px #000;
  box-shadow: 0 0 12px rgba(247, 208, 80, 0.6), 0 2px 0 #000;
}
.step-indicator.completed {
  border-color: #4ade80;
  background: radial-gradient(circle at 35% 35%, #86efac, #15803d);
  color: #ffffff;
  text-shadow: 0 1px 1px #000;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4), 0 2px 0 #000;
}
.step-line {
  flex: 1;
  height: 3px;
  background-color: var(--border-default);
  margin: 0 4px;
}

.ladder-actions {
  display: flex;
  gap: 8px;
}

/* API Key Banner */
.api-key-banner {
  background-color: var(--color-warning-bg);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--color-warning);
  padding: 8px 12px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Chat Log */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.45;
  word-break: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background-color: var(--accent-primary);
  color: white;
  border-bottom-right-radius: 2px;
}
.chat-bubble.tutor {
  align-self: flex-start;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}
.chat-bubble.system {
  align-self: center;
  background-color: var(--bg-surface-hover);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: var(--radius-full);
}

.chat-bubble code {
  font-family: var(--font-mono);
  background-color: rgba(0, 0, 0, 0.25);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 0.85em;
}

.chat-bubble pre {
  margin: 8px 0;
  background-color: var(--bg-app);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 8px;
  overflow-x: auto;
  position: relative;
}
.chat-bubble pre code {
  background: transparent;
  padding: 0;
}

.chat-code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}

.chat-form {
  padding: 10px 12px;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-textarea {
  flex: 1;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 0.85rem;
  resize: none;
  outline: none;
}
.chat-textarea:focus {
  border-color: var(--accent-highlight);
}
.btn-send {
  height: 38px;
  width: 38px;
  border-radius: var(--radius-sm);
  padding: 0;
}
.chat-context-indicator {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.context-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-success);
}

/* ==========================================================================
   8. INSPECTOR PANEL (CONSOLE & AUDITS)
   ========================================================================== */

.inspector-header {
  height: 42px;
  padding: 0 10px;
  background-color: var(--bg-surface);
  border-bottom: 2px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.inspector-tabs {
  display: flex;
  height: 100%;
  align-items: stretch;
}
.inspector-tab {
  padding: 0 12px;
  height: 100%;
  border-right: 1px solid var(--border-subtle);
  font-family: var(--font-retro);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  background: transparent;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.inspector-tab:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface-hover);
}
.inspector-tab.active {
  color: var(--accent-highlight);
  background-color: var(--bg-surface-elevated);
  border-top: 3px solid var(--accent-highlight);
}

.inspector-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-toggle-drawer {
  font-family: var(--font-retro);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-highlight);
  border: 1px solid var(--accent-primary);
  background-color: rgba(244, 140, 66, 0.1);
  box-shadow: 0 2px 0 #000;
}
.btn-toggle-drawer:hover {
  background-color: rgba(244, 140, 66, 0.2);
  transform: translateY(1px);
  box-shadow: 0 1px 0 #000;
}

.inspector-body {
  flex: 1;
  overflow-y: auto;
  background-color: var(--bg-app);
  background-image: 
    linear-gradient(rgba(18, 21, 36, 0.97), rgba(18, 21, 36, 0.97)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.2) 0px, rgba(0, 0, 0, 0.2) 1px, transparent 1px, transparent 2px);
}

.inspector-pane {
  display: none;
  padding: 8px 12px;
  min-height: 100%;
}
.inspector-pane.active {
  display: block;
}

.inspector-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-retro);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

/* Console Entries */
.console-output {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.console-row {
  display: flex;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 3px;
  align-items: flex-start;
  border-left: 3px solid transparent;
  background-color: rgba(24, 29, 50, 0.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.console-row.log {
  border-left-color: var(--border-default);
}
.console-row.warn {
  background-color: var(--color-warning-bg);
  border-left-color: var(--color-warning);
  color: var(--color-warning);
}
.console-row.error, .console-row.runtime-error {
  background-color: var(--color-danger-bg);
  border-left-color: var(--color-danger);
  color: var(--color-danger);
}

.console-time {
  color: var(--text-muted);
  font-size: 0.72rem;
  user-select: none;
}
.console-badge {
  font-size: 0.65rem;
  font-family: var(--font-pixel);
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 2px;
  text-transform: uppercase;
}
.console-badge.log { background-color: var(--bg-surface-hover); color: var(--text-secondary); }
.console-badge.warn { background-color: var(--color-warning); color: #000; }
.console-badge.error { background-color: var(--color-danger); color: #fff; }

.console-msg {
  flex: 1;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Audit Cards */
.audit-output {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audit-card {
  background-color: var(--bg-surface);
  border: 2px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border-left: 5px solid var(--border-default);
  box-shadow: 0 2px 0 #000;
}
.audit-card.error { border-left-color: var(--color-danger); }
.audit-card.warning { border-left-color: var(--color-warning); }
.audit-card.info { border-left-color: var(--color-info); }
.audit-card.pass { border-left-color: var(--color-success); }

.audit-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.audit-rule-title {
  font-family: var(--font-retro);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}
.audit-wcag-tag {
  font-size: 0.68rem;
  color: var(--accent-highlight);
  font-family: var(--font-pixel);
}

.audit-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.audit-target {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background-color: var(--bg-surface-hover);
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-block;
  color: var(--accent-highlight);
  margin-bottom: 6px;
}
.audit-fix {
  font-size: 0.8rem;
  color: var(--color-success);
  background-color: var(--color-success-bg);
  padding: 4px 8px;
  border-radius: 3px;
}

/* ==========================================================================
   9. PASSCODE GATE & MODALS
   ========================================================================== */

.gate-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(9, 13, 22, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.gate-card {
  background-color: var(--bg-surface);
  border: 3px solid var(--accent-highlight);
  border-radius: var(--radius-sm);
  padding: 32px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 8px 0 #000, 0 16px 32px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.gate-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}
.gate-title {
  font-family: var(--font-pixel);
  font-size: 0.95rem;
  color: var(--accent-highlight);
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}
.gate-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.form-group input {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  text-align: center;
  outline: none;
}
.form-group input:focus {
  border-color: var(--accent-highlight);
}

.form-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  min-height: 18px;
  text-align: center;
}

.gate-notice {
  margin-top: 20px;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
  border-top: 1px solid var(--border-subtle);
  padding-top: 14px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 3px solid var(--border-default);
  border-radius: var(--radius-sm);
  max-width: 580px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 0 #000, 0 16px 32px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.modal-card.modal-sm {
  max-width: 400px;
}

.modal-header {
  padding: 14px 18px;
  background-color: var(--bg-surface-elevated);
  border-bottom: 2px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  color: var(--accent-highlight);
  letter-spacing: 0.03em;
}
.btn-close-modal {
  font-size: 1.4rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}
.btn-close-modal:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 0.9rem;
}

.modal-footer {
  padding: 12px 18px;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-section h4 {
  font-size: 0.95rem;
  font-weight: 600;
}
.settings-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.modal-divider {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 16px 0;
}

.input-with-toggle {
  display: flex;
  gap: 6px;
}
.input-with-toggle input {
  flex: 1;
  font-size: 0.9rem;
  letter-spacing: normal;
  text-align: left;
}

.settings-status-note {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.settings-actions-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.callout {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.4;
  margin-top: 10px;
}
.callout-info {
  background-color: var(--color-info-bg);
  border-left: 3px solid var(--accent-highlight);
  color: var(--text-secondary);
}

/* ==========================================================================
   10. MOBILE BOTTOM NAVIGATION & RESPONSIVE BREAKPOINTS
   ========================================================================== */

.mobile-bottom-nav {
  display: none;
}

@media (max-width: 900px) {
  .app-workspace {
    display: block;
    padding: 0;
    height: calc(100dvh - var(--header-height) - var(--mobile-nav-height));
  }

  .workspace-side-left,
  .editor-inspector-wrapper {
    display: contents;
  }

  .tutor-rail-tab,
  .editor-rail-tab,
  .btn-collapse-side,
  .btn-collapse-tutor,
  .btn-collapse-editor,
  .btn-toggle-drawer,
  .btn-mode-toggle {
    display: none !important;
  }

  .workspace-panel {
    display: none;
    height: 100%;
    border-radius: 0;
    border: none;
  }

  /* Show panel matching mobile view */
  [data-mobile-view="canvas"] .panel-preview { display: flex; }
  [data-mobile-view="editor"] .panel-editor {
    display: flex;
    width: 100% !important;
    max-width: 100% !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
    margin: 0 !important;
  }
  [data-mobile-view="tutor"] .panel-tutor {
    display: flex;
    width: 100% !important;
    max-width: 100% !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
    margin: 0 !important;
  }
  [data-mobile-view="inspector"] .panel-inspector {
    display: flex;
    position: static;
    height: 100%;
  }
  [data-mobile-view="inspector"] .panel-inspector.collapsed .inspector-body {
    display: block;
  }

  .challenge-banner {
    display: none; /* Hide top banner on small screens to prioritize workspace */
  }

  .header-branding .brand-text {
    display: none;
  }

  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    z-index: 100;
  }

  .mob-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 100%;
    color: var(--text-muted);
    border-radius: 0;
    min-height: 48px;
  }
  .mob-nav-btn.active {
    color: var(--accent-highlight);
    background-color: var(--bg-surface-elevated);
    border-top: 2px solid var(--accent-highlight);
  }
  .mob-icon { font-size: 1.1rem; }
  .mob-label { font-size: 0.7rem; font-weight: 600; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
