/* ============================================
   CODE QUEST - Medieval Fantasy Theme
   ============================================ */

:root {
  --forest-dark: #0d1f0d;
  --forest-mid: #1a3a1a;
  --forest-light: #2d5a2d;
  --parchment: #f4e8c1;
  --parchment-dark: #e8d49a;
  --stone: #6b7280;
  --stone-light: #9ca3af;
  --amber: #f59e0b;
  --amber-light: #fcd34d;
  --gold: #ffd700;
  --ruby: #dc2626;
  --sapphire: #2563eb;
  --emerald: #059669;
  --purple: #7c3aed;
  --castle-brown: #78350f;
  --castle-gray: #374151;
  --text-light: #f9fafb;
  --text-muted: #9ca3af;
  --editor-bg: #282a36;
  --success-green: #10b981;
  --error-red: #ef4444;
  --warning-yellow: #f59e0b;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--forest-dark);
  color: var(--text-light);
  height: 100vh;
  overflow: hidden;
}

#app { width: 100vw; height: 100vh; position: relative; }

/* ============================================
   SCREENS
   ============================================ */

.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  overflow-y: auto;
}
.screen.active { display: flex; flex-direction: column; }

/* ============================================
   START SCREEN
   ============================================ */

#screen-start {
  background: linear-gradient(180deg, #0a0e1a 0%, #0d1f0d 40%, #1a2f0d 100%);
  justify-content: center;
  align-items: center;
}

.start-bg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 600px;
}

.castle-silhouette {
  font-size: 8rem;
  filter: drop-shadow(0 0 30px rgba(255, 215, 0, 0.5));
  animation: float 3s ease-in-out infinite;
  margin-bottom: 1rem;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-15px); }
}

.game-title {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #ffd700, #ff8c00, #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin-bottom: 0.5rem;
}

.game-tagline {
  font-size: 1.2rem;
  color: var(--parchment);
  opacity: 0.9;
  margin-bottom: 1.5rem;
}

.start-features {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.feature-badge {
  background: rgba(255,215,0,0.15);
  border: 1px solid rgba(255,215,0,0.4);
  color: var(--gold);
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn-primary {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: #1a0a00;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(245,158,11,0.4);
  letter-spacing: 0.03em;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(245,158,11,0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-large { padding: 1rem 2.5rem; font-size: 1.15rem; border-radius: 10px; }

.btn-secondary {
  background: transparent;
  color: var(--parchment);
  border: 1px solid rgba(244,232,193,0.3);
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(244,232,193,0.1); border-color: rgba(244,232,193,0.6); }

.btn-back {
  background: rgba(255,255,255,0.08);
  color: var(--text-light);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover { background: rgba(255,255,255,0.15); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,0.2); color: var(--text-muted); padding: 0.3rem 0.7rem; border-radius: 5px; cursor: pointer; font-size: 0.8rem; transition: all 0.15s; }
.btn-ghost:hover { border-color: rgba(255,255,255,0.4); color: var(--text-light); }

/* ============================================
   SETUP SCREEN
   ============================================ */

#screen-setup {
  background: linear-gradient(135deg, #0d1f0d, #1a1a2e);
  overflow-y: auto;
  flex-direction: column;
  align-items: center;
}

.setup-container {
  max-width: 900px;
  width: 100%;
  padding: 2rem 1.5rem;
}

.setup-header {
  text-align: center;
  margin-bottom: 2rem;
}
.setup-header h2 {
  font-size: 2rem;
  background: linear-gradient(135deg, #ffd700, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.setup-header p { color: var(--text-muted); margin-top: 0.3rem; }

.setup-section { margin-bottom: 2rem; }
.setup-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--parchment);
  margin-bottom: 1rem;
  padding-left: 0.5rem;
  border-left: 3px solid var(--amber);
}

.card-grid {
  display: grid;
  gap: 0.75rem;
}
.age-cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.lang-cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.sel-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem 0.75rem;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 0.3rem;
  position: relative;
}
.sel-card:hover { background: rgba(255,255,255,0.1); border-color: rgba(245,158,11,0.4); transform: translateY(-2px); }
.sel-card.selected {
  background: rgba(245,158,11,0.15);
  border-color: var(--amber);
  box-shadow: 0 0 15px rgba(245,158,11,0.3);
}

.card-icon { font-size: 2rem; }
.card-title { font-weight: 700; font-size: 0.95rem; color: var(--text-light); }
.card-sub { font-size: 0.75rem; color: var(--amber); font-weight: 600; }
.card-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.card-tag { font-size: 0.65rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; margin-top: 0.2rem; }
.card-tag.recommended { background: var(--emerald); color: white; }

.setup-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* ============================================
   WORLD MAP
   ============================================ */

#screen-worldmap {
  background: linear-gradient(180deg, #0a1628 0%, #0d1f0d 100%);
  flex-direction: column;
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(0,0,0,0.4);
  border-bottom: 1px solid rgba(255,215,0,0.2);
  flex-shrink: 0;
}
.map-header-left { display: flex; align-items: center; gap: 0.75rem; }
.map-lang-name { font-weight: 700; font-size: 1rem; }
.map-age-label { font-size: 0.75rem; color: var(--amber); }
.map-title { font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.map-header-right { display: flex; align-items: center; gap: 0.75rem; }
.big-icon { font-size: 2rem; }

.xp-pill {
  background: rgba(255,215,0,0.15);
  border: 1px solid rgba(255,215,0,0.3);
  color: var(--gold);
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.world-scroll { flex: 1; overflow-y: auto; padding: 2rem 1.5rem; }

.world-map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
}

.castle-card {
  background: linear-gradient(135deg, rgba(30,40,20,0.9), rgba(20,30,40,0.9));
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.castle-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--card-color, #ffd700), transparent);
}
.castle-card:hover:not(.locked) { transform: translateY(-4px); border-color: rgba(255,215,0,0.3); box-shadow: 0 8px 25px rgba(0,0,0,0.4); }
.castle-card.locked { opacity: 0.45; cursor: not-allowed; }
.castle-card.completed { border-color: rgba(16,185,129,0.4); }
.castle-card.active { border-color: rgba(245,158,11,0.5); box-shadow: 0 0 20px rgba(245,158,11,0.2); }
.castle-card.challenge-castle { border-color: rgba(220,38,38,0.4); background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(30,20,40,0.9)); }
.castle-card.challenge-castle.active { border-color: rgba(220,38,38,0.7); box-shadow: 0 0 20px rgba(220,38,38,0.25); }

.castle-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.castle-theme-icon { font-size: 2.2rem; }
.castle-status-badge { font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 999px; }
.status-locked { background: rgba(107,114,128,0.3); color: var(--stone-light); }
.status-active { background: rgba(245,158,11,0.2); color: var(--amber); }
.status-completed { background: rgba(16,185,129,0.2); color: var(--success-green); }

.castle-card-title { font-size: 1rem; font-weight: 700; color: var(--text-light); margin-bottom: 0.25rem; }
.castle-card-topic { font-size: 0.75rem; color: var(--amber); font-weight: 600; margin-bottom: 0.5rem; }
.castle-card-desc { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; margin-bottom: 0.75rem; }

.castle-progress-bar {
  height: 5px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}
.castle-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--amber), var(--gold));
  border-radius: 999px;
  transition: width 0.4s ease;
}
.castle-progress-text { font-size: 0.7rem; color: var(--text-muted); }

/* ============================================
   GAME HEADER (shared)
   ============================================ */

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: rgba(0,0,0,0.5);
  border-bottom: 1px solid rgba(255,215,0,0.15);
  flex-shrink: 0;
  gap: 0.5rem;
}
.header-center { display: flex; align-items: center; gap: 0.5rem; flex: 1; justify-content: center; min-width: 0; }
.header-icon { font-size: 1.5rem; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.hint-pill { background: rgba(124,58,237,0.2); border: 1px solid rgba(124,58,237,0.4); color: #a78bfa; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }

/* ============================================
   PATH SCREEN
   ============================================ */

#screen-path {
  background: linear-gradient(180deg, #0a1a0a, #1a2a1a);
  flex-direction: column;
}

.path-scene {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

.path-description {
  text-align: center;
  margin-bottom: 2rem;
}
.path-description h3 { font-size: 1.5rem; color: var(--gold); margin-bottom: 0.5rem; }
.path-description p { color: var(--text-muted); font-size: 0.95rem; }

.path-nodes-container { width: 100%; max-width: 800px; }

.path-nodes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  padding: 1rem;
  position: relative;
}

.path-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: transform 0.2s;
}
.path-node:hover:not(.locked) { transform: scale(1.05); }

.path-node-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  border: 3px solid rgba(255,255,255,0.1);
  position: relative;
  transition: all 0.2s;
}
.path-node.completed .path-node-circle { background: linear-gradient(135deg, #065f46, #059669); border-color: #34d399; color: white; }
.path-node.current .path-node-circle { background: linear-gradient(135deg, #92400e, #d97706); border-color: #fcd34d; color: white; box-shadow: 0 0 15px rgba(253,211,77,0.4); animation: pulse-glow 2s infinite; }
.path-node.locked .path-node-circle { background: rgba(55,65,81,0.5); border-color: rgba(107,114,128,0.3); color: var(--stone); cursor: not-allowed; }
.path-node.final .path-node-circle { font-size: 1.8rem; width: 80px; height: 80px; }
.path-node.final.completed .path-node-circle { background: linear-gradient(135deg, #064e3b, #047857); border-color: #6ee7b7; }
.path-node.final.current .path-node-circle { background: linear-gradient(135deg, #78350f, #b45309); box-shadow: 0 0 25px rgba(253,211,77,0.6); }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 15px rgba(253,211,77,0.4); }
  50% { box-shadow: 0 0 30px rgba(253,211,77,0.7); }
}

.path-node-label {
  font-size: 0.7rem;
  text-align: center;
  color: var(--text-muted);
  max-width: 80px;
  line-height: 1.2;
}
.path-node.current .path-node-label { color: var(--amber); font-weight: 600; }
.path-node.completed .path-node-label { color: var(--success-green); }

/* ============================================
   GAME SCREEN
   ============================================ */

#screen-game {
  flex-direction: column;
  background: #0f1117;
}

.level-badge { background: var(--amber); color: #1a0a00; padding: 0.2rem 0.6rem; border-radius: 5px; font-size: 0.8rem; font-weight: 800; flex-shrink: 0; }
.level-title-text { font-size: 0.95rem; font-weight: 600; color: var(--text-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.game-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* --- LEFT PANEL --- */
.game-left {
  width: 320px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0d1a0d, #0a1228);
  border-right: 1px solid rgba(255,215,0,0.1);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
  overflow-y: auto;
}

.mission-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,215,0,0.15);
  border-radius: 10px;
  padding: 0.9rem;
}
.mission-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.mission-label { font-size: 0.7rem; font-weight: 700; color: var(--amber); text-transform: uppercase; letter-spacing: 0.08em; }
.concept-tag { font-size: 0.65rem; background: rgba(124,58,237,0.2); color: #a78bfa; border: 1px solid rgba(124,58,237,0.3); padding: 0.15rem 0.5rem; border-radius: 999px; }
.mission-text { font-size: 0.9rem; color: var(--parchment); line-height: 1.6; }

.path-progress-mini {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 0.75rem;
}

.mini-path {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.mini-node {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  border: 2px solid rgba(255,255,255,0.1);
  transition: all 0.2s;
}
.mini-node.done { background: #059669; border-color: #34d399; color: white; }
.mini-node.now { background: #d97706; border-color: #fcd34d; color: white; box-shadow: 0 0 8px rgba(253,211,77,0.5); }
.mini-node.todo { background: rgba(55,65,81,0.5); color: var(--stone-light); }
.mini-node.final-node { border-radius: 6px; font-size: 0.9rem; width: 32px; height: 32px; }

.character-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}
.character-sprite {
  font-size: 3.5rem;
  filter: drop-shadow(0 0 10px rgba(255,215,0,0.3));
  animation: walk-idle 2s ease-in-out infinite;
}
@keyframes walk-idle {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-4px) rotate(2deg); }
}

.speech-bubble {
  background: rgba(255,255,255,0.9);
  color: #1a1a1a;
  padding: 0.4rem 0.75rem;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  max-width: 200px;
  text-align: center;
  position: relative;
  line-height: 1.4;
}
.speech-bubble::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: rgba(255,255,255,0.9);
}
.speech-bubble.hidden { display: none; }

.left-actions { margin-top: auto; }

.btn-hint-main {
  width: 100%;
  padding: 0.6rem;
  background: rgba(124,58,237,0.15);
  border: 1px solid rgba(124,58,237,0.4);
  color: #a78bfa;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-hint-main:hover { background: rgba(124,58,237,0.25); }
.btn-hint-main:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- LESSON PANEL --- */
.lesson-panel {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,215,0,0.12);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.lesson-header-bar {
  background: rgba(255,215,0,0.1);
  border-bottom: 1px solid rgba(255,215,0,0.15);
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.lesson-intro-text {
  font-size: 0.82rem;
  color: var(--parchment);
  line-height: 1.6;
  padding: 0.65rem 0.75rem 0.4rem;
}

.lesson-block {
  padding: 0 0.75rem 0.5rem;
}

.lesson-block-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
}

.lesson-code-block {
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  font-size: 0.78rem;
  color: #a5f3fc;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  line-height: 1.55;
}

.lesson-output-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: rgba(16,185,129,0.08);
  border-radius: 5px;
  border: 1px solid rgba(16,185,129,0.2);
}

.lesson-arrow { color: var(--success-green); font-size: 0.7rem; flex-shrink: 0; }

.lesson-output-val {
  font-family: 'Cascadia Code', 'Courier New', monospace;
  font-size: 0.78rem;
  color: #6ee7b7;
}

.lesson-tip {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin: 0 0.75rem 0.6rem;
  background: rgba(124,58,237,0.1);
  border: 1px solid rgba(124,58,237,0.25);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  font-size: 0.78rem;
  color: #c4b5fd;
  line-height: 1.5;
}
.lesson-tip-icon { flex-shrink: 0; }

.lesson-skills-list {
  padding: 0 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.lesson-skill-item {
  display: flex;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--parchment);
  line-height: 1.4;
  padding: 0.25rem 0.4rem;
  background: rgba(255,255,255,0.04);
  border-radius: 5px;
}
.lesson-skill-name {
  color: #a5f3fc;
  font-family: monospace;
  font-weight: 700;
  flex-shrink: 0;
}

/* --- RIGHT PANEL --- */
.game-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #1e1e2e;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.editor-lang-badge { font-size: 0.8rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 5px; background: rgba(255,255,255,0.1); color: var(--text-light); }
.editor-label { font-size: 0.8rem; color: var(--text-muted); font-family: 'Courier New', monospace; flex: 1; }
.btn-reset-sm { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #f87171; padding: 0.2rem 0.6rem; border-radius: 5px; font-size: 0.75rem; cursor: pointer; transition: all 0.15s; }
.btn-reset-sm:hover { background: rgba(239,68,68,0.2); }

.editor-wrapper {
  flex: 1;
  overflow: hidden;
  min-height: 200px;
}

/* CodeMirror overrides */
.editor-wrapper .CodeMirror {
  height: 100%;
  font-size: 14px;
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  line-height: 1.6;
}
.CodeMirror-scroll { min-height: 200px; }

.editor-controls {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: #1e1e2e;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.btn-run {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  color: white;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(37,99,235,0.4);
}
.btn-run:hover { background: linear-gradient(135deg, #1e40af, #3b82f6); transform: translateY(-1px); }
.btn-run:active { transform: translateY(0); }

.btn-submit {
  background: linear-gradient(135deg, #065f46, #059669);
  color: white;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(5,150,105,0.4);
}
.btn-submit:hover { background: linear-gradient(135deg, #047857, #10b981); transform: translateY(-1px); }

.output-area {
  height: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0d1117;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.output-tabs {
  display: flex;
  padding: 0.3rem 0.75rem 0;
  gap: 0.25rem;
  flex-shrink: 0;
}
.out-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.out-tab.active { color: var(--amber); border-bottom-color: var(--amber); }

.output-panel, .preview-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.output-text {
  font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text-light);
  white-space: pre-wrap;
  line-height: 1.6;
}
.output-text.has-error { color: #f87171; }
.output-text.has-success { color: #34d399; }

.preview-frame { width: 100%; height: 100%; border: none; background: white; border-radius: 4px; }

/* ============================================
   HINT MODAL
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.modal-box {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 1px solid rgba(124,58,237,0.4);
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 700;
  font-size: 1rem;
  color: #a78bfa;
}
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; }
.modal-close:hover { color: white; }
.hint-text { color: var(--parchment); line-height: 1.7; font-size: 0.95rem; }
.hint-meta { margin-top: 0.75rem; font-size: 0.75rem; color: var(--text-muted); }

/* ============================================
   SUCCESS OVERLAY
   ============================================ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(5px);
}

.success-card {
  background: linear-gradient(135deg, #0d2e0d, #0a1a28);
  border: 2px solid rgba(255,215,0,0.4);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 0 60px rgba(255,215,0,0.2);
  position: relative;
  overflow: hidden;
}

.success-icon { font-size: 4rem; margin-bottom: 0.5rem; animation: bounce-in 0.5s ease; }
@keyframes bounce-in {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.success-card h2 { font-size: 1.8rem; color: var(--gold); margin-bottom: 0.5rem; }
.success-card p { color: var(--parchment); font-size: 1rem; margin-bottom: 1rem; }
.xp-gain-display {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--gold);
  background: rgba(255,215,0,0.1);
  border: 1px solid rgba(255,215,0,0.3);
  display: inline-block;
  padding: 0.3rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.success-confetti { position: absolute; top: 0; left: 0; width: 100%; height: 60px; pointer-events: none; }
.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confetti-fall 2s linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(80px) rotate(360deg); opacity: 0; }
}

/* ============================================
   CASTLE COMPLETE SCREEN
   ============================================ */

#screen-castle-complete {
  background: linear-gradient(180deg, #0a0a1a, #0a1f0a);
  justify-content: center;
  align-items: center;
  overflow-y: auto;
}

.celebration-scene {
  text-align: center;
  padding: 2rem;
  max-width: 550px;
  width: 100%;
}

.castle-big { font-size: 6rem; margin-bottom: 1rem; filter: drop-shadow(0 0 30px rgba(255,215,0,0.6)); animation: float 3s ease-in-out infinite; }

.celebration-scene h1 { font-size: 2.5rem; color: var(--gold); margin-bottom: 0.5rem; }
.celebration-scene h2 { font-size: 1.3rem; color: var(--parchment); margin-bottom: 0.5rem; }
.celebration-scene > p { color: var(--text-muted); margin-bottom: 2rem; }

.cc-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.5rem;
}
.cc-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.cc-stat span { font-size: 2rem; font-weight: 900; color: var(--gold); }
.cc-stat label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.cc-skill-summary {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.celebration-scene .btn-primary { margin-bottom: 0.75rem; display: block; width: 100%; }
.celebration-scene .btn-secondary { display: block; width: 100%; }

/* ============================================
   GAME COMPLETE
   ============================================ */

#screen-game-complete {
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #0a0a0a 100%);
  justify-content: center;
  align-items: center;
}

.game-complete-scene {
  text-align: center;
  padding: 2rem;
  max-width: 500px;
}
.trophy { font-size: 7rem; margin-bottom: 1rem; animation: float 3s ease-in-out infinite; filter: drop-shadow(0 0 30px gold); }
.game-complete-scene h1 { font-size: 2rem; background: linear-gradient(135deg, #ffd700, #ff8c00); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 1rem; }
.game-complete-scene p { color: var(--parchment); margin-bottom: 0.5rem; }
.final-stats { display: flex; justify-content: center; gap: 2rem; margin: 2rem 0; }
.game-complete-scene .btn-primary { display: block; width: 100%; margin-bottom: 0.75rem; }
.game-complete-scene .btn-secondary { display: block; width: 100%; }

/* ============================================
   UTILITIES
   ============================================ */

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* Responsive */
@media (max-width: 768px) {
  .game-layout { flex-direction: column; }
  .game-left { width: 100%; max-height: 200px; flex-direction: row; flex-wrap: wrap; }
  .character-area { display: none; }
  .game-title { font-size: 2.2rem; }
  .world-map-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================
   VERSION FOOTER
   ============================================ */
.version-footer {
  position: fixed;
  bottom: 7px;
  right: 12px;
  font-size: 0.6rem;
  color: rgba(255,255,255,0.2);
  z-index: 9999;
  pointer-events: none;
  font-family: monospace;
  letter-spacing: 0.05em;
}

/* ============================================
   YOUNG BLOCK BUILDER
   ============================================ */
.block-builder {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 0.75rem 0.5rem 0;
  flex: 1;
  overflow-y: auto;
}

.block-builder-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.03em;
}

/* Code display — looks like a code editor but with interactive slots */
.block-code-display {
  background: #1a1b2e;
  border: 2px solid var(--amber);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 1.05rem;
  line-height: 2.1rem;
  color: #cdd6f4;
  white-space: pre-wrap;
  min-height: 70px;
  position: relative;
}

/* Inline slot inside the code display — choice type */
.code-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  padding: 1px 10px;
  border-radius: 7px;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  line-height: 1.6rem;
  vertical-align: middle;
  transition: all 0.18s;
}

.choice-slot {
  background: rgba(255, 215, 0, 0.12);
  border: 2px dashed var(--gold);
  color: var(--amber-light);
  cursor: default;
  animation: pulse-slot 2s ease-in-out infinite;
}

@keyframes pulse-slot {
  0%, 100% { border-color: var(--gold); }
  50%       { border-color: rgba(255,215,0,0.4); }
}

.choice-slot.filled {
  background: rgba(255, 215, 0, 0.25);
  border: 2px solid var(--gold);
  color: #fff;
  animation: none;
}

.choice-slot.drag-over {
  background: rgba(255, 215, 0, 0.45);
  transform: scale(1.08);
  animation: none;
}

/* Inline input slot — text / number */
.input-slot {
  background: rgba(80, 180, 255, 0.15);
  border: 2px solid #3b9edd;
  border-radius: 7px;
  color: #fff;
  padding: 1px 8px;
  min-width: 90px;
  max-width: 160px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: inherit;
  line-height: 1.6rem;
  vertical-align: middle;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.input-slot:focus {
  border-color: #5dade2;
  background: rgba(80, 180, 255, 0.28);
}

/* Choice area below the code block */
.block-choice-area {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.block-choice-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.block-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

/* Individual draggable tile */
.block-tile {
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  cursor: grab;
  user-select: none;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  border: 3px solid transparent;
  word-break: break-word;
}

.block-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 0 rgba(0,0,0,0.35);
}

.block-tile:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.35);
  cursor: grabbing;
}

.block-tile.selected {
  border: 3px solid #fff;
  transform: translateY(-2px);
  box-shadow: 0 5px 0 rgba(0,0,0,0.35);
}

.block-tile.dragging {
  opacity: 0.45;
  cursor: grabbing;
  transform: scale(0.96);
}

/* ============================================
   LOGIN SCREEN
   ============================================ */

#screen-login {
  background: linear-gradient(180deg, #0a0e1a 0%, #0d1f0d 40%, #1a2f0d 100%);
  justify-content: center;
  align-items: center;
}

.login-container {
  background: linear-gradient(135deg, #111827, #1a2740);
  border: 1px solid rgba(255,215,0,0.25);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-logo { font-size: 3rem; margin-bottom: 0.5rem; }
.login-header h2 {
  font-size: 1.6rem;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.3rem;
}
.login-header p { color: var(--text-muted); font-size: 0.85rem; }

.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 4px;
}
.login-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.login-tab.active {
  background: rgba(255,215,0,0.15);
  color: var(--gold);
}

.login-panel { display: flex; flex-direction: column; gap: 1rem; }

.login-field { display: flex; flex-direction: column; gap: 0.4rem; }
.login-field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.login-field input {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 9px;
  padding: 0.65rem 0.9rem;
  color: var(--text-light);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.login-field input:focus {
  border-color: rgba(255,215,0,0.5);
  background: rgba(255,255,255,0.1);
}

.login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  color: #f87171;
  font-size: 0.85rem;
}

.login-footer {
  text-align: center;
  margin-top: 1.25rem;
}

/* ============================================
   WORLD MAP — extra header buttons
   ============================================ */

.map-header-right { flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }

/* ============================================
   LEADERBOARD SCREEN
   ============================================ */

#screen-leaderboard {
  background: linear-gradient(180deg, #0a0a1a, #0a1f0a);
}

.lb-container {
  padding: 1.5rem;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.lb-title-row {
  text-align: center;
  margin-bottom: 1.5rem;
}
.lb-title-row h2 { font-size: 1.6rem; color: var(--gold); }
.lb-sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }

.lb-list { display: flex; flex-direction: column; gap: 0.6rem; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  transition: background 0.15s;
}
.lb-row:hover { background: rgba(255,255,255,0.07); }
.lb-row.lb-me {
  border-color: rgba(255,215,0,0.4);
  background: rgba(255,215,0,0.06);
}

.lb-rank {
  font-size: 1.2rem;
  font-weight: 900;
  width: 2rem;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-muted);
}
.lb-rank.rank-1 { color: #ffd700; font-size: 1.4rem; }
.lb-rank.rank-2 { color: #c0c0c0; font-size: 1.3rem; }
.lb-rank.rank-3 { color: #cd7f32; font-size: 1.2rem; }

.lb-name { flex: 1; font-weight: 700; font-size: 1rem; color: var(--text-light); }
.lb-you-badge { font-size: 0.7rem; background: rgba(255,215,0,0.2); color: var(--gold); border-radius: 5px; padding: 0.1rem 0.4rem; margin-left: 0.4rem; }
.lb-xp { font-size: 1rem; font-weight: 700; color: var(--amber); }
.lb-ach { font-size: 0.78rem; color: var(--text-muted); }
.lb-empty { text-align: center; color: var(--text-muted); padding: 3rem; font-size: 0.95rem; }

/* ============================================
   ACHIEVEMENTS SCREEN
   ============================================ */

#screen-achievements {
  background: linear-gradient(180deg, #0a0a1a, #0a1f0a);
}

.ach-container {
  padding: 1.5rem;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.ach-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 1.25rem 1rem;
  text-align: center;
  transition: all 0.2s;
}
.ach-card.earned {
  border-color: rgba(255,215,0,0.4);
  background: rgba(255,215,0,0.06);
  box-shadow: 0 0 20px rgba(255,215,0,0.1);
}
.ach-card.locked {
  opacity: 0.45;
  filter: grayscale(0.7);
}

.ach-icon { font-size: 2.5rem; margin-bottom: 0.5rem; display: block; }
.ach-name { font-size: 0.9rem; font-weight: 700; color: var(--text-light); margin-bottom: 0.25rem; }
.ach-desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.ach-earned-badge { display: inline-block; margin-top: 0.5rem; font-size: 0.65rem; background: rgba(255,215,0,0.2); color: var(--gold); border-radius: 5px; padding: 0.1rem 0.5rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }

/* ============================================
   SANDBOX SCREEN
   ============================================ */

#screen-sandbox {
  background: linear-gradient(180deg, #0a0a1a, #0d1f0d);
}

.sandbox-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sandbox-editor-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.sandbox-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: #1e1e2e;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.sandbox-templates { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-left: auto; }
.template-btn {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.template-btn:hover { background: rgba(255,255,255,0.14); color: var(--text-light); }

.sandbox-editor-wrapper { min-height: 300px; }

.sandbox-lang-select {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: var(--text-light);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

/* ============================================
   ACHIEVEMENT TOAST
   ============================================ */

.achievement-toast {
  position: fixed;
  bottom: 2rem;
  right: 1.5rem;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 2px solid rgba(255,215,0,0.5);
  border-radius: 14px;
  padding: 0.9rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5), 0 0 20px rgba(255,215,0,0.15);
  z-index: 9000;
  max-width: 300px;
  animation: toast-slide-in 0.4s cubic-bezier(0.175,0.885,0.32,1.275);
}
@keyframes toast-slide-in {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.toast-icon { font-size: 2rem; flex-shrink: 0; }
.toast-label { font-size: 0.65rem; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 0.15rem; }
.toast-name  { font-size: 0.95rem; font-weight: 700; color: var(--text-light); }
.toast-desc  { font-size: 0.75rem; color: var(--text-muted); }

/* Added by decoupledlane.com: studio credit */
.dls-note { margin: 4px 0 0; font-size: 0.7rem; text-align: center; opacity: 0.7; }
.dls-credit { margin: 20px 0 0; font-size: 0.8rem; text-align: center; }
.dls-credit a { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-underline-offset: 2px; }
.dls-credit img { width: 20px; height: 20px; border-radius: 4px; }
