/* ============================================
   PixieCode — Mobile-First Kid-Friendly UI
   ============================================ */

:root {
  --color-primary: #8B5CF6;
  --color-primary-dark: #7C3AED;
  --color-primary-light: #A78BFA;
  --color-accent: #EC4899;
  --color-success: #10B981;
  --color-danger: #EF4444;
  --color-purple: #8B5CF6;
  --color-purple-dark: #6D28D9;
  --color-purple-light: #C4B5FD;
  --color-lavender: #EDE9FE;
  --color-lavender-light: #F5F3FF;
  --color-bg: #F5F3FF;
  --color-surface: #FFFFFF;
  --color-dark: #0F172A;
  --color-dark-surface: #1E293B;
  --color-dark-border: #334155;
  --color-text: #1E1B4B;
  --color-text-muted: #6B7280;
  --color-border: #DDD6FE;
  --shadow-sm: 0 1px 3px rgba(139,92,246,0.1);
  --shadow-md: 0 4px 12px rgba(139,92,246,0.15);
  --shadow-lg: 0 8px 24px rgba(139,92,246,0.2);
  --radius: 16px;
  --radius-sm: 10px;
  --topbar-h: 56px;
  --sidebar-w: 240px;
}

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

html, body {
  height: 100%;
  font-family: 'Comic Sans MS', 'Baloo 2', 'Nunito', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body { display: flex; flex-direction: column; }

/* ===== Top Bar ===== */
.topbar {
  height: var(--topbar-h);
  background: linear-gradient(135deg, #8B5CF6, #6D28D9, #5B21B6);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(139,92,246,0.4);
  flex-shrink: 0;
}

.nav-toggle {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.nav-toggle:hover { background: rgba(255,255,255,0.35); }

.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 1.2rem;
  flex: 1;
}
.logo-icon { font-size: 1.5rem; }

.topbar-actions { display: flex; gap: 6px; }

.xp-display {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 1rem;
  margin-right: 8px;
  transition: transform .2s;
}
.xp-display.pop { animation: xpPop .4s ease; }
@keyframes xpPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); background: #FFD700; color: #333; }
  100% { transform: scale(1); }
}
.xp-icon { font-size: 1.2rem; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform .1s, box-shadow .2s;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn:active { transform: scale(0.96); }

.btn-run {
  background: var(--color-success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(92,219,149,0.5);
}
.btn-run:hover { box-shadow: 0 4px 12px rgba(92,219,149,0.6); }

.btn-stop {
  background: var(--color-danger);
  color: #fff;
}
.btn-save { background: rgba(255,255,255,0.25); color: #fff; }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  padding: 10px 20px;
}
.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.icon-btn {
  background: rgba(255,255,255,0.2);
  border: none; color: #fff;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 1rem;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform .3s ease;
  z-index: 90;
  padding: 16px 0;
}
.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
  position: fixed; inset: var(--topbar-h) 0 0 0;
  background: rgba(0,0,0,0.4);
  z-index: 80;
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

.nav-menu { display: flex; flex-direction: column; gap: 4px; padding: 0 12px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: all .2s;
}
.nav-item:hover { background: var(--color-bg); color: var(--color-text); }
.nav-item.active {
  background: var(--color-primary);
  color: #fff;
}
.nav-item span { flex: 1; }

/* ===== Main / Views ===== */
.main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 12px;
  display: none;
}
.view.active { display: block; }

/* ===== Editor Split — three column desktop layout ===== */
.editor-split {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.stage-container {
  background: linear-gradient(135deg, #2D1B4E, #1E1B4B);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.stage-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(135deg, #1E1B4B, #312E81);
  color: #C4B5FD;
}
.stage-title { font-weight: 700; font-size: 0.95rem; }
.stage-controls { display: flex; gap: 4px; }
.stage-run { background: rgba(16,185,129,0.3) !important; }
.stage-stop { background: rgba(239,68,68,0.3) !important; }
.stage-reset { background: rgba(249,115,22,0.3) !important; }
.stage-avatar { background: rgba(139,92,246,0.3) !important; }

.stage {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #1E1B4B;
  position: relative;
}

.blocks-container {
  flex: 1;
  background: var(--color-dark);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 300px;
  position: relative;
}
.blockly-div {
  width: 100%; height: 100%;
  position: absolute; inset: 0;
}

/* ===== Panels (Tasks, Examples, Code) ===== */
.panel {
  max-width: 800px;
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.panel-title { font-size: 1.6rem; margin-bottom: 4px; }
.panel-subtitle { color: var(--color-text-muted); margin-bottom: 16px; }

/* Difficulty filter chips */
.difficulty-filter {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
}
.chip {
  padding: 6px 14px;
  border: 2px solid var(--color-border);
  background: #fff;
  border-radius: 20px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all .2s;
}
.chip.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* Task / Example cards */
.task-list, .example-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: all .2s;
}
.card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.card:active { transform: translateY(0); }
.card.solved {
  border-color: var(--color-success);
  background: #F0FFF4;
}
.card.solved .card-icon { background: #D4EDDA; }
.card-solved-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--color-success);
  color: #fff;
  border-radius: 50%;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
}
.card { position: relative; }

.card-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}
.card-body { flex: 1; }
.card-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 2px; }
.card-desc { color: var(--color-text-muted); font-size: 0.9rem; }
.card-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-anfaenger { background: #D4EDDA; color: #155724; }
.badge-fortgeschritten { background: #FFF3CD; color: #856404; }
.badge-profi { background: #F8D7DA; color: #721C24; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 500px; width: 100%;
  max-height: 85vh; overflow-y: auto;
  padding: 24px;
  position: relative;
  animation: modalIn .3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--color-bg);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

.task-modal-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.task-modal-icon { font-size: 2.5rem; }
.task-modal-title { font-size: 1.4rem; font-weight: 800; }
.task-modal-desc { color: var(--color-text-muted); margin-bottom: 16px; }

.instructions { margin: 16px 0; }
.instructions h3 { margin-bottom: 8px; }
.instructions ol { padding-left: 20px; line-height: 1.7; }
.instructions li { margin-bottom: 6px; }

.hint-box {
  background: #FFF9E6;
  border-left: 4px solid var(--color-accent);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
}
.hint-box strong { color: var(--color-accent); }

.modal-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 20px;
}

/* ===== Code Output ===== */
.code-output {
  background: #1A1A2E;
  color: #A5D6FF;
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-top: 12px;
  min-height: 200px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-weight: 600;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  transition: transform .3s ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.hidden { display: none; }

/* ===== Responsive: Tablet ===== */
@media (min-width: 768px) {
  :root { --topbar-h: 64px; }
  .topbar { padding: 0 20px; }
  .logo-text { font-size: 1.4rem; }
  .nav-toggle { display: none; }

  /* Persistent sidebar on larger screens */
  .sidebar {
    transform: translateX(0);
    box-shadow: none;
    border-right: 1px solid var(--color-border);
  }
  .sidebar-overlay { display: none; }
  .main { margin-left: var(--sidebar-w); }

  .view { padding: 20px; }
  .task-list, .example-list { grid-template-columns: 1fr 1fr; }
}

/* ===== Responsive: Desktop — three column editor (stage | blocks | categories) ===== */
@media (min-width: 1024px) {
  .editor-split {
    flex-direction: row;
  }
  .stage-container {
    width: 380px;
    flex-shrink: 0;
  }
  .blocks-container { flex: 1; }
}

/* ===== Fullscreen stage ===== */
.stage-container.fullscreen {
  position: fixed; inset: 0;
  z-index: 250;
  border-radius: 0;
}
.stage-container.fullscreen .stage { aspect-ratio: auto; height: calc(100% - 40px); }

/* ===== Keyboard styling ===== */
kbd {
  display: inline-block;
  padding: 2px 8px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 0 #ccc;
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  margin: 0 2px;
}

/* ===== New Project Button ===== */
.btn-new {
  background: var(--color-purple);
  color: #fff;
}

/* ===== Game Template Grid ===== */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.template-card {
  padding: 16px;
  border: 3px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: all .2s;
  text-align: center;
}
.template-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.template-card-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}
.template-card-title {
  font-weight: 800;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.template-card-desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* ===== Avatar Editor ===== */
.avatar-preview-section {
  display: flex;
  gap: 20px;
  align-items: center;
  background: var(--color-bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
}
.avatar-preview-box {
  font-size: 4rem;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius);
  border: 3px dashed var(--color-primary);
  flex-shrink: 0;
}
.avatar-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.form-input {
  padding: 8px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
}
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
}
.form-range {
  width: 100%;
  accent-color: var(--color-primary);
}

.emoji-palette {
  max-height: 200px;
  overflow-y: auto;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.emoji-category {
  margin-bottom: 12px;
}
.emoji-category-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.emoji-grid-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.emoji-item {
  font-size: 1.8rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: #fff;
  border: 2px solid transparent;
}
.emoji-item:hover {
  background: var(--color-bg);
  transform: scale(1.15);
}
.emoji-item.selected {
  border-color: var(--color-primary);
  background: #E3F0FF;
}
