/* ============================================
   CodePetit - Mobile-First Styles
   ============================================ */

:root {
  /* Colors */
  --bg: #f0f4f8;
  --bg-dark: #e2e8f0;
  --text: #2d3748;
  --text-light: #718096;
  --white: #ffffff;
  --shadow: rgba(0,0,0,0.1);

  /* World colors */
  --w1: #68d391; --w1-light: #c6f6d5; --w1-dark: #38a169;
  --w2: #63b3ed; --w2-light: #bee3f8; --w2-dark: #3182ce;
  --w3: #f6ad55; --w3-light: #feebc8; --w3-dark: #dd6b20;
  --w4: #fc8181; --w4-light: #fed7d7; --w4-dark: #e53e3e;
  --w5: #d69e2e; --w5-light: #fefcbf; --w5-dark: #b7791f;
  --w6: #4fd1c5; --w6-light: #b2f5ea; --w6-dark: #319795;
  --w7: #b794f4; --w7-light: #e9d8fd; --w7-dark: #805ad5;
  --w8: #f687b3; --w8-light: #fed7e2; --w8-dark: #d53f8c;

  /* Current world (set by JS) */
  --world-color: var(--w1);
  --world-light: var(--w1-light);
  --world-dark: var(--w1-dark);

  /* Sizes */
  --header-h: 50px;
  --btn-size: 56px;
  --cell-size: 48px;
  --palette-btn: 52px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Screens ---- */
.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.screen.active {
  display: flex;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  min-height: 48px;
  min-width: 48px;
}
.btn:active {
  transform: scale(0.95);
}
.btn-play {
  background: var(--world-color, var(--w1));
  color: white;
  box-shadow: 0 4px 0 var(--world-dark, var(--w1-dark));
}
.btn-play:active {
  box-shadow: 0 2px 0 var(--world-dark, var(--w1-dark));
  transform: translateY(2px);
}
.btn-secondary {
  background: var(--bg-dark);
  color: var(--text);
  box-shadow: 0 3px 0 #cbd5e0;
}
.btn-small {
  padding: 8px 16px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-dark);
  color: var(--text);
  border: none;
  cursor: pointer;
}

.btn-back {
  background: none;
  border: none;
  font-size: 24px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   HOME
   ============================================ */
#screen-home {
  background: linear-gradient(160deg, #e6fffa 0%, #ebf8ff 55%, #faf5ff 100%);
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ---- Header ---- */
.home-header {
  width: 100%;
  padding: 20px 20px 10px;
}
.home-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.home-title-group {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.home-title {
  font-size: 32px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--w2) 0%, var(--w7) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  line-height: 1.1;
}
.home-tagline {
  font-size: 12px;
  color: var(--text-light);
  margin: 1px 0 0;
}

.home-worlds-section {
  width: 100%;
  padding: 8px 0 6px;
}

.home-worlds-title {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: rgba(45, 55, 72, 0.75);
}

/* ---- Horizontal sinuous worlds strip ---- */
.home-worlds-strip {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding: 10px 0 10px;
  position: relative;
  display: flex;
  justify-content: center;
}
.home-worlds-strip::-webkit-scrollbar { display: none; }
/* Right fade — hints at more content to scroll */
.home-worlds-strip::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 48px;
  background: linear-gradient(to right, transparent, rgba(235,248,255,0.92));
  pointer-events: none;
}

.worlds-nodes-row {
  position: relative;
  display: flex;
  /* width + height set by JS */
  margin: 0 auto;
}

.worlds-path-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* Flex node — width + padding-top set per-node in JS */
.worlds-node {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  scroll-snap-align: center;
  pointer-events: none;
}

.home-world-circle {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 2px solid rgba(255,255,255,0.7);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.4);
}

.home-world-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  max-width: 64px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-hero-float {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.map-hero-float svg {
  width: 38px;
  height: 38px;
  display: block;
}

/* ---- Home buttons ---- */
.home-buttons {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 16px;
}
.home-buttons .btn {
  width: 100%;
}

/* ---- LEGACY — kept for hero select screen ---- */
.hero-showcase {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 420px;
  padding: 12px 8px 0;
  flex: 1;
  min-height: 200px;
}

.showcase-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 20px;
  border: 3px solid transparent;
  transition: border-color 0.2s, background 0.2s;
  flex: 1;
  max-width: 130px;
}
.showcase-slot.active {
  border-color: var(--w2);
  background: rgba(99,179,237,0.12);
}
.showcase-slot:active { transform: scale(0.96); }

.showcase-hero-wrap {
  /* The hero element that receives animation CSS */
  position: relative;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1);
}
.showcase-slot:not(.active) .showcase-hero-wrap {
  transform: scale(0.72);
  opacity: 0.65;
  transform-origin: bottom center;
}
.showcase-slot.active .showcase-hero-wrap {
  transform: scale(1);
  transform-origin: bottom center;
}

/* Force all 4 hero SVGs to show only the front one in showcase */
.showcase-hero-wrap .hero-svg { display: none; }
.showcase-hero-wrap .hero-svg[data-dir-svg="2"] { display: block; }

.showcase-hero-wrap .hero-svg {
  width: 90px;
  height: 90px;
}

.showcase-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-light);
  margin-top: 2px;
}
.showcase-slot.active .showcase-name {
  color: var(--w2);
}

/* Color dots */
.showcase-colors {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 10px 0 4px;
  min-height: 44px;
}
.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid white;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.color-dot.active::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--w2);
}
.color-dot:active { transform: scale(0.88); }

/* (path scene CSS removed — replaced by world map) */
.home-path-scene {
  flex: 1;
  width: 100%;
  position: relative;
  overflow: hidden;
  min-height: 260px;
}

.path-grid {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  box-sizing: border-box;
  gap: 0;
  justify-content: space-between;
}

.path-row {
  display: flex;
  gap: 4px;
  position: relative;
  flex: 1;
}
.path-row.reverse { flex-direction: row-reverse; }

.path-tile {
  flex: 1;
  border-radius: 12px;
  background: var(--tile-bg);
  border-bottom: 4px solid var(--tile-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s;
  min-height: 0;
}
.path-tile {
  cursor: default;
}
.path-tile.tile-locked {
  opacity: 0.42;
  filter: grayscale(0.4);
}

/* Subtle texture overlay per world via ::after */
.path-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
}
.path-tile[data-world="1"]::after { background: repeating-linear-gradient(0deg, transparent 0, transparent 6px, rgba(255,255,255,0.18) 6px, rgba(255,255,255,0.18) 7px); }
.path-tile[data-world="2"]::after { background: repeating-linear-gradient(45deg, transparent 0, transparent 5px, rgba(255,255,255,0.12) 5px, rgba(255,255,255,0.12) 6px); }
.path-tile[data-world="3"]::after { background: repeating-linear-gradient(135deg, transparent 0, transparent 6px, rgba(255,255,255,0.15) 6px, rgba(255,255,255,0.15) 8px); }
.path-tile[data-world="6"]::after { background: repeating-linear-gradient(0deg, transparent 0, transparent 4px, rgba(255,255,255,0.2) 4px, rgba(255,255,255,0.2) 5px); }
.path-tile[data-world="7"]::after { background: radial-gradient(circle, rgba(255,255,255,0.55) 1px, transparent 1px) 0 0 / 9px 9px; }

.path-tile-icon {
  font-size: 22px;
  position: relative;
  z-index: 1;
  line-height: 1;
}
.path-tile-stars {
  position: relative;
  z-index: 1;
  font-size: 10px;
  letter-spacing: 0;
  line-height: 1;
}
.path-ts-on  { color: #ecc94b; }
.path-ts-off { color: rgba(0,0,0,0.18); }

/* Bend connector between rows */
.path-bend-h {
  height: 14px;
  flex-shrink: 0;
  position: relative;
}
.path-bend-h.bend-right-h {
  border-right: 5px solid rgba(0,0,0,0.1);
  border-bottom: 5px solid rgba(0,0,0,0.1);
  border-radius: 0 0 10px 0;
  margin-right: 12px;
}
.path-bend-h.bend-left-h {
  border-left: 5px solid rgba(0,0,0,0.1);
  border-bottom: 5px solid rgba(0,0,0,0.1);
  border-radius: 0 0 0 10px;
  margin-left: 12px;
}

/* Walking heroes on path */
.path-walker-outer {
  position: absolute;
  top: 0; bottom: 0;
  width: 58px;
  display: flex;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}
.path-walker .hero-svg { display: none !important; }
.path-walker .hero-svg[data-dir-svg="1"] { display: block !important; width: 54px; height: 54px; }

/* Individual wander animations */
.path-walker-outer-0 { animation: wander-lr  10s ease-in-out infinite; }
.path-walker-outer-1 { animation: wander-rl   8s ease-in-out infinite 1.8s; }
.path-walker-outer-2 { animation: wander-rl  13s ease-in-out infinite 5s; }

@keyframes wander-lr {
  0%   { left: 4px;              transform: scaleX(1); }
  43%  { left: calc(100% - 62px); transform: scaleX(1); }
  46%  { left: calc(100% - 62px); transform: scaleX(-1); }
  98%  { left: 4px;              transform: scaleX(-1); }
  100% { left: 4px;              transform: scaleX(1); }
}
@keyframes wander-rl {
  0%   { left: calc(100% - 62px); transform: scaleX(-1); }
  43%  { left: 4px;               transform: scaleX(-1); }
  46%  { left: 4px;               transform: scaleX(1); }
  98%  { left: calc(100% - 62px); transform: scaleX(1); }
  100% { left: calc(100% - 62px); transform: scaleX(-1); }
}

/* Bob on the inner walker */
.path-walker { animation: path-bob 0.85s ease-in-out infinite; }
.path-walker-outer-1 .path-walker { animation-delay: 0.28s; }
.path-walker-outer-2 .path-walker { animation-delay: 0.56s; }
@keyframes path-bob {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

/* World progression strip (home — legacy, unused) */
.world-strip {
  display: flex;
  align-items: center;
  overflow-x: auto;
  width: 100%;
  padding: 14px 20px 6px;
  gap: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.world-strip::-webkit-scrollbar { display: none; }

.world-strip-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  gap: 4px;
  cursor: pointer;
  position: relative;
}
.world-strip-node.locked { cursor: default; }

.world-strip-connector {
  width: 18px;
  height: 4px;
  flex-shrink: 0;
  background: repeating-linear-gradient(
    90deg,
    rgba(0,0,0,0.15) 0, rgba(0,0,0,0.15) 4px,
    transparent 4px, transparent 8px
  );
  border-radius: 2px;
  align-self: center;
  margin-bottom: 18px; /* align with circle center */
}

.world-strip-circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 3px solid white;
  box-shadow: 0 3px 8px rgba(0,0,0,0.18);
  background: var(--node-color, #cbd5e0);
  transition: transform 0.15s;
}
.world-strip-node:not(.locked):active .world-strip-circle {
  transform: scale(0.9);
}
.world-strip-node.locked .world-strip-circle {
  background: #e2e8f0;
  filter: grayscale(0.6);
  opacity: 0.55;
}
.world-strip-node.current .world-strip-circle {
  box-shadow: 0 0 0 3px white, 0 0 0 6px var(--node-color, #68d391),
              0 4px 12px rgba(0,0,0,0.2);
  animation: strip-pulse 1.8s ease-in-out infinite;
}
@keyframes strip-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.08); }
}

.world-strip-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  max-width: 58px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.world-strip-node.locked .world-strip-label { opacity: 0.45; }

.world-strip-stars {
  font-size: 10px;
  letter-spacing: 1px;
  line-height: 1;
}
.world-strip-star-on  { color: #ecc94b; }
.world-strip-star-off { color: #e2e8f0; }



/* ---- MAP SCREEN ---- */
.map-header {
  display: flex;
  align-items: center;
  padding: 8px;
  background: var(--white);
  box-shadow: 0 2px 8px var(--shadow);
  min-height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.map-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* World section */
.map-world {
  --wc: var(--w1);
  --wl: var(--w1-light);
  --wd: var(--w1-dark);
}

.map-world-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--wc);
  color: white;
  position: sticky;
  top: var(--header-h);
  z-index: 5;
}
.map-world-icon {
  font-size: 28px;
  line-height: 1;
}
.map-world-info { flex: 1; }
.map-world-name { font-weight: 800; font-size: 16px; }
.map-world-desc { font-size: 12px; opacity: 0.85; }
.map-world-progress {
  font-size: 13px;
  font-weight: 700;
  background: rgba(255,255,255,0.25);
  padding: 3px 8px;
  border-radius: 20px;
}
.map-world-locked {
  font-size: 20px;
  opacity: 0.5;
}

/* Path area */
.map-path {
  background: var(--wl);
  padding: 20px 12px 8px;
}

/* One row of 4 nodes */
.map-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
}
.map-row.reverse { flex-direction: row-reverse; }

/* Connector line between nodes in the same row */
.map-connector {
  flex: 1;
  height: 4px;
  border-top: 3px dashed var(--wc);
  opacity: 0.4;
  margin: 0 -2px;
}

/* Level node */
.map-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: transform 0.1s;
  min-width: 52px;
}
.map-node:not(.locked):active { transform: scale(0.9); }

.map-node-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--wc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: var(--wc);
  box-shadow: 0 4px 0 var(--wd);
  transition: background 0.2s, color 0.2s;
}
.map-node.done .map-node-circle {
  background: var(--wc);
  color: white;
}
.map-node.current .map-node-circle {
  background: var(--wc);
  color: white;
  animation: map-pulse 2s ease-in-out infinite;
  box-shadow: 0 4px 0 var(--wd), 0 0 0 5px rgba(255,255,255,0.8);
}
.map-node.locked .map-node-circle {
  background: #e8edf2;
  border-color: #c8d0da;
  color: #a0aec0;
  box-shadow: 0 3px 0 #c8d0da;
  cursor: default;
}
@keyframes map-pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--wd), 0 0 0 5px rgba(255,255,255,0.8); }
  50%       { box-shadow: 0 4px 0 var(--wd), 0 0 0 9px rgba(255,255,255,0.4); }
}

.map-node-stars {
  display: flex;
  gap: 1px;
  font-size: 11px;
  height: 14px;
}
.map-star-on  { color: #ecc94b; }
.map-star-off { color: #d0d8e4; }

/* Bend connector between rows */
.map-bend {
  height: 28px;
  margin: -4px 0;
}
.map-bend.bend-right {
  border-right: 3px dashed var(--wc);
  border-bottom: 3px dashed var(--wc);
  border-bottom-right-radius: 26px;
  margin-left: 30px;
  opacity: 0.4;
}
.map-bend.bend-left {
  border-left: 3px dashed var(--wc);
  border-bottom: 3px dashed var(--wc);
  border-bottom-left-radius: 26px;
  margin-right: 30px;
  opacity: 0.4;
}

/* World locked overlay */
.map-world.world-locked .map-path {
  opacity: 0.45;
  pointer-events: none;
}
.map-world.world-locked .map-world-header {
  opacity: 0.6;
}

/* ---- Language switcher ---- */
.lang-switcher {
  display: flex;
  gap: 6px;
}
.lang-btn {
  padding: 5px 12px;
  border: 2px solid var(--bg-dark);
  background: var(--white);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.15s;
}
.lang-btn.active {
  border-color: var(--w2);
  color: var(--w2);
  background: var(--w2-light, #bee3f8);
}
.lang-btn:active {
  transform: scale(0.92);
}

/* Change hero button */
.btn-hero-change {
  background: none;
  border: 2px solid var(--world-color, var(--w2));
  color: var(--world-color, var(--w2));
  font-size: 14px;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* Reset progress button */
.btn-reset-progress {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 8px;
}

/* ---- Screen Header ---- */
.screen-header {
  display: flex;
  align-items: center;
  padding: 8px;
  background: var(--white);
  box-shadow: 0 2px 8px var(--shadow);
  min-height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 10;
}
.screen-title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}
.spacer {
  width: 48px;
}

/* ---- WORLDS GRID ---- */
.worlds-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}
.world-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
  min-height: 72px;
  border-left: 6px solid var(--card-color);
}
.world-card:active {
  transform: scale(0.97);
}
.world-card.locked {
  opacity: 0.45;
  pointer-events: none;
}
.world-card-icon {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-light);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.world-card-info {
  flex: 1;
}
.world-card-name {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 2px;
}
.world-card-desc {
  font-size: 13px;
  color: var(--text-light);
}
.world-card-progress {
  font-size: 13px;
  color: var(--text-light);
}
.world-card-lock {
  font-size: 20px;
  opacity: 0.4;
}

/* ---- LEVELS GRID ---- */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 16px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}
.level-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s;
  min-height: 60px;
  background: var(--white);
  color: var(--text);
  box-shadow: 0 2px 6px var(--shadow);
}
.level-btn:active {
  transform: scale(0.93);
}
.level-btn.completed {
  background: var(--world-light);
  color: var(--world-dark);
}
.level-btn.current {
  background: var(--world-color);
  color: white;
  box-shadow: 0 3px 0 var(--world-dark), 0 0 0 3px var(--world-light);
  animation: pulse 2s ease-in-out infinite;
}
.level-btn.locked {
  opacity: 0.3;
  pointer-events: none;
  background: var(--bg-dark);
}
.level-stars {
  display: flex;
  gap: 1px;
  font-size: 10px;
  margin-top: 2px;
  line-height: 1;
}
.level-star {
  color: #e2e8f0;
}
.level-star.earned {
  color: #ecc94b;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 3px 0 var(--world-dark), 0 0 0 3px var(--world-light); }
  50% { box-shadow: 0 3px 0 var(--world-dark), 0 0 0 6px var(--world-light); }
}

/* ---- GAME SCREEN ---- */
.game-header {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  background: var(--white);
  box-shadow: 0 2px 8px var(--shadow);
  min-height: 44px;
  z-index: 10;
}
.game-level-info {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
}
.game-stars-display {
  font-size: 14px;
  padding-right: 8px;
  min-width: 48px;
  text-align: right;
}

/* Game Area */
.game-area {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  position: relative;
  min-height: 200px;
}
.grid-container {
  display: grid;
  gap: 2px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
  position: relative;
}
.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  position: relative;
  transition: background 0.2s;
}
.grid-cell.path {
  background: var(--white);
}
.grid-cell.wall {
  background: #a0aec0;
  box-shadow: inset 0 -3px 0 #718096;
  border-radius: 4px;
}

/* ============================================
   World-themed path & wall cells
   ============================================ */

/* World 1 - La Prairie (grass) */
.grid-container[data-world="1"] .grid-cell.path,
.grid-container[data-world="1"] .grid-cell.goal,
.grid-container[data-world="1"] .grid-cell.star {
  background:
    radial-gradient(circle at 30% 30%, #9ae6b4 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, #9ae6b4 0 2px, transparent 3px),
    linear-gradient(135deg, #d8f5c4 0%, #b4e89a 100%);
}
.grid-container[data-world="1"] .grid-cell.wall {
  background:
    radial-gradient(circle at 50% 40%, #48bb78 0 6px, transparent 7px),
    linear-gradient(135deg, #2f855a 0%, #276749 100%);
  box-shadow: inset 0 -3px 0 #22543d;
}

/* World 2 - La Foret (forest floor + trees) */
.grid-container[data-world="2"] .grid-cell.path,
.grid-container[data-world="2"] .grid-cell.goal,
.grid-container[data-world="2"] .grid-cell.star {
  background:
    radial-gradient(circle at 25% 25%, rgba(120, 80, 40, 0.25) 0 2px, transparent 3px),
    radial-gradient(circle at 75% 75%, rgba(120, 80, 40, 0.25) 0 1.5px, transparent 2.5px),
    linear-gradient(135deg, #c6f0d4 0%, #8fd6a3 100%);
}
.grid-container[data-world="2"] .grid-cell.wall {
  background:
    radial-gradient(ellipse at 50% 35%, #276749 0 40%, #1c4532 41%, #1c4532 100%);
  box-shadow: inset 0 -3px 0 #14331f;
}

/* World 3 - La Plage (sand + water) */
.grid-container[data-world="3"] .grid-cell.path,
.grid-container[data-world="3"] .grid-cell.goal,
.grid-container[data-world="3"] .grid-cell.star {
  background:
    radial-gradient(circle at 20% 30%, #f6e05e 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 60% 70%, #f6e05e 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 80% 20%, #ecc94b 0 1px, transparent 2px),
    linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}
.grid-container[data-world="3"] .grid-cell.wall {
  background:
    linear-gradient(180deg, #4fd1c5 0%, #319795 50%, #2c7a7b 100%);
  box-shadow: inset 0 -3px 0 #234e52, inset 0 3px 0 rgba(255,255,255,0.35);
}

/* World 4 - La Montagne (rock + snow) */
.grid-container[data-world="4"] .grid-cell.path,
.grid-container[data-world="4"] .grid-cell.goal,
.grid-container[data-world="4"] .grid-cell.star {
  background:
    radial-gradient(circle at 40% 40%, rgba(160, 174, 192, 0.4) 0 2px, transparent 3px),
    linear-gradient(135deg, #f7fafc 0%, #e2e8f0 100%);
}
.grid-container[data-world="4"] .grid-cell.wall {
  background:
    linear-gradient(135deg, #718096 0%, #4a5568 60%, #2d3748 100%);
  box-shadow: inset 0 -3px 0 #1a202c, inset 0 4px 0 rgba(255,255,255,0.2);
}

/* World 5 - Le Desert (dunes) */
.grid-container[data-world="5"] .grid-cell.path,
.grid-container[data-world="5"] .grid-cell.goal,
.grid-container[data-world="5"] .grid-cell.star {
  background:
    radial-gradient(circle at 30% 40%, #ecc94b 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 70% 60%, #ecc94b 0 1px, transparent 2px),
    linear-gradient(135deg, #fef9c3 0%, #fde68a 50%, #f6ad55 100%);
}
.grid-container[data-world="5"] .grid-cell.wall {
  background:
    linear-gradient(135deg, #b7791f 0%, #975a16 60%, #744210 100%);
  box-shadow: inset 0 -3px 0 #4a2509;
}

/* World 6 - L'Ocean (water) */
.grid-container[data-world="6"] .grid-cell.path,
.grid-container[data-world="6"] .grid-cell.goal,
.grid-container[data-world="6"] .grid-cell.star {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255,255,255,0.5) 0 30%, transparent 35%),
    linear-gradient(135deg, #bee3f8 0%, #90cdf4 50%, #4fd1c5 100%);
  animation: ocean-shimmer 4s ease-in-out infinite;
}
@keyframes ocean-shimmer {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.06); }
}
.grid-container[data-world="6"] .grid-cell.wall {
  background:
    radial-gradient(circle at 50% 40%, #2b6cb0 0 30%, #1a365d 31%, #1a365d 100%);
  box-shadow: inset 0 -3px 0 #12285a;
}

/* World 7 - L'Espace (stars + dark) */
.grid-container[data-world="7"] .grid-cell.path,
.grid-container[data-world="7"] .grid-cell.goal,
.grid-container[data-world="7"] .grid-cell.star {
  background:
    radial-gradient(circle at 20% 30%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 80% 60%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 60% 20%, rgba(255,255,255,0.7) 0 0.8px, transparent 1.8px),
    linear-gradient(135deg, #2d3748 0%, #1a202c 50%, #2a1a4e 100%);
}
.grid-container[data-world="7"] .grid-cell.wall {
  background:
    radial-gradient(circle at 35% 30%, #b794f4 0 30%, #6b46c1 31%, #44337a 100%);
  box-shadow: inset 0 -3px 0 #322659, inset 0 2px 0 rgba(255,255,255,0.2);
}

/* World 8 - Le Chateau (stone floor) */
.grid-container[data-world="8"] .grid-cell.path,
.grid-container[data-world="8"] .grid-cell.goal,
.grid-container[data-world="8"] .grid-cell.star {
  background:
    linear-gradient(90deg, transparent 48%, rgba(0,0,0,0.08) 49%, rgba(0,0,0,0.08) 51%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(0,0,0,0.08) 49%, rgba(0,0,0,0.08) 51%, transparent 52%),
    linear-gradient(135deg, #fbd38d 0%, #f6ad55 100%);
}
.grid-container[data-world="8"] .grid-cell.wall {
  background:
    linear-gradient(0deg,  transparent 48%, rgba(0,0,0,0.3) 49%, rgba(0,0,0,0.3) 51%, transparent 52%),
    linear-gradient(90deg, transparent 48%, rgba(0,0,0,0.3) 49%, rgba(0,0,0,0.3) 51%, transparent 52%),
    linear-gradient(135deg, #a0aec0 0%, #718096 60%, #4a5568 100%);
  box-shadow: inset 0 -3px 0 #2d3748;
}
.grid-cell.goal {
  background: var(--white);
  position: relative;
}
.grid-cell.goal::after {
  content: '';
  position: absolute;
  inset: 3px;
  background-image: var(--goal-sprite);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  animation: chest-bob 1.8s ease-in-out infinite;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25));
  transform-origin: center bottom;
}
@keyframes chest-bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-2px) scale(1.03); }
}
.grid-cell.star {
  background: var(--white);
}
.grid-cell.star::after {
  content: '';
  width: 22px;
  height: 22px;
  background: #ecc94b;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.grid-cell.star.collected::after {
  opacity: 0.2;
  transform: scale(0.5);
  transition: all 0.3s;
}
.grid-cell.switch-off {
  background: var(--white);
}
.grid-cell.switch-off::after {
  content: '';
  width: 20px;
  height: 20px;
  background: #e53e3e;
  border-radius: 50%;
  box-shadow: 0 2px 0 #c53030;
}
.grid-cell.switch-on::after {
  content: '';
  width: 20px;
  height: 20px;
  background: #38a169;
  border-radius: 50%;
  box-shadow: 0 2px 0 #276749;
}
.grid-cell.door-closed {
  background: #e53e3e;
  box-shadow: inset 0 -3px 0 #c53030;
}
.grid-cell.door-open {
  background: var(--white);
  border: 2px dashed #c6f6d5;
}

/* Hero (smooth SVG) */
.hero {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  transition: left 0.3s ease, top 0.3s ease;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.22));
}
.hero .hero-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  overflow: visible;
}
/* Show the SVG matching the current direction */
.hero[data-dir="0"] .hero-svg[data-dir-svg="0"],
.hero[data-dir="1"] .hero-svg[data-dir-svg="1"],
.hero[data-dir="2"] .hero-svg[data-dir-svg="2"],
.hero[data-dir="3"] .hero-svg[data-dir-svg="3"] {
  display: block;
}

/* ---- Idle animations (always running) ---- */
.hero .hero-body {
  transform-origin: 24px 28px;
  animation: breathe 2.6s ease-in-out infinite;
}
.hero .hero-eyes {
  transform-origin: 24px 22px;
  animation: blink 4s ease-in-out infinite;
}
.hero .hero-crest {
  transform-origin: 24px 11px;
  animation: crest-sway 3.2s ease-in-out infinite;
}
.hero .hero-wing-l {
  transform-origin: 10px 26px;
  animation: wing-idle-l 2.6s ease-in-out infinite;
}
.hero .hero-wing-r {
  transform-origin: 38px 26px;
  animation: wing-idle-r 2.6s ease-in-out infinite;
}
.hero .hero-tail {
  transform-origin: 24px 25px;
  animation: tail-wag 2s ease-in-out infinite;
}
.hero .hero-shadow {
  transform-origin: 24px 43px;
  animation: shadow-pulse 2.6s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scaleY(1) translateY(0); }
  50%      { transform: scaleY(1.04) translateY(-0.6px); }
}
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(0.1); }
}
@keyframes crest-sway {
  0%, 100% { transform: rotate(-3deg); }
  50%      { transform: rotate(3deg); }
}
@keyframes wing-idle-l {
  0%, 100% { transform: rotate(-12deg) scale(1); }
  50%      { transform: rotate(-18deg) scale(1.02); }
}
@keyframes wing-idle-r {
  0%, 100% { transform: rotate(12deg) scale(1); }
  50%      { transform: rotate(18deg) scale(1.02); }
}
@keyframes tail-wag {
  0%, 100% { transform: rotate(-4deg); }
  50%      { transform: rotate(4deg); }
}
@keyframes shadow-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(0.92); opacity: 0.85; }
}

/* ---- Walking animations (while program executes) ---- */
.hero.walking .hero-main {
  animation: walk-bounce 0.35s ease-in-out infinite;
}
.hero.walking .hero-wing-l {
  animation: wing-walk-l 0.25s ease-in-out infinite;
}
.hero.walking .hero-wing-r {
  animation: wing-walk-r 0.25s ease-in-out infinite;
}
.hero.walking .hero-feet * {
  animation: feet-walk 0.25s ease-in-out infinite;
}
@keyframes walk-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.5px); }
}
@keyframes wing-walk-l {
  0%, 100% { transform: rotate(-10deg) scaleY(1); }
  50%      { transform: rotate(-26deg) scaleY(0.75); }
}
@keyframes wing-walk-r {
  0%, 100% { transform: rotate(10deg) scaleY(1); }
  50%      { transform: rotate(26deg) scaleY(0.75); }
}
@keyframes feet-walk {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-1px); }
}

.hero.bump {
  animation: bump 0.3s ease;
}
@keyframes bump {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(var(--bump-x, 0), var(--bump-y, 0)); }
}

/* Game hint */
.game-hint {
  text-align: center;
  padding: 6px 16px;
  font-size: 14px;
  color: var(--text-light);
  background: var(--world-light);
  border-radius: var(--radius-sm);
  margin: 4px 12px;
}

/* ---- Program Area ---- */
.program-area {
  padding: 6px 12px;
  flex-shrink: 0;
}
.program-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
}
.program-slots {
  display: flex;
  gap: 4px;
  padding: 8px;
  min-height: 52px;
  background: var(--white);
  border-radius: var(--radius-sm);
  border: 2px dashed var(--bg-dark);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
  flex-wrap: nowrap;
}
.program-empty {
  color: var(--text-light);
  font-size: 13px;
  padding: 4px 8px;
  white-space: nowrap;
}
.program-block {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 38px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
  transition: transform 0.1s, opacity 0.2s;
  position: relative;
}
.program-block:active {
  transform: scale(0.9);
}
.program-block.executing {
  box-shadow: 0 0 0 3px var(--world-color);
  animation: exec-pulse 0.5s ease;
}
@keyframes exec-pulse {
  0% { box-shadow: 0 0 0 3px var(--world-color); }
  100% { box-shadow: 0 0 0 0px var(--world-color); }
}
.program-block.forward { background: #bee3f8; color: #2b6cb0; }
.program-block.turn_left { background: #feebc8; color: #c05621; font-size: 24px; font-weight: 900; }
.program-block.turn_right { background: #feebc8; color: #c05621; font-size: 24px; font-weight: 900; }
.program-block.loop-start { background: #c6f6d5; color: #276749; border-radius: 6px 2px 2px 6px; }
.program-block.loop-end { background: #c6f6d5; color: #276749; border-radius: 2px 6px 6px 2px; min-width: 20px; font-size: 14px; }
.program-block.loop-body { border-top: 3px solid #68d391; border-bottom: 3px solid #68d391; }
.program-block.call-f1 { background: #e9d8fd; color: #6b46c1; }
.program-block.call-f2 { background: #fed7e2; color: #b83280; }

.program-block .block-remove {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: #e53e3e;
  color: white;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.program-slots:not(.running) .program-block .block-remove {
  display: block;
}

/* Function tabs */
.function-area {
  padding: 0 12px;
}
.function-tabs {
  display: flex;
  gap: 4px;
}
.func-tab {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--bg-dark);
  background: var(--white);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-light);
  border-bottom: none;
}
.func-tab.active {
  background: var(--world-light);
  color: var(--world-dark);
  border-color: var(--world-color);
}

/* Loop config popup */
.loop-config {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loop-config-inner {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.loop-label {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
  display: block;
}
.loop-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
}
.loop-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--bg-dark);
  background: var(--white);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s;
}
.loop-btn:active, .loop-btn:hover {
  background: #c6f6d5;
  border-color: #68d391;
}

/* ---- Palette ---- */
.palette {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.palette-btn {
  width: var(--palette-btn);
  height: var(--palette-btn);
  border-radius: var(--radius-sm);
  border: none;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  position: relative;
}
.palette-btn:active {
  transform: scale(0.92) translateY(2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
}
.palette-btn.forward { background: #bee3f8; color: #2b6cb0; }
.palette-btn.turn_left { background: #feebc8; color: #c05621; font-size: 30px; font-weight: 900; }
.palette-btn.turn_right { background: #feebc8; color: #c05621; font-size: 30px; font-weight: 900; }
.palette-btn.loop { background: #c6f6d5; color: #276749; }
.palette-btn.call-f1 { background: #e9d8fd; color: #6b46c1; }
.palette-btn.call-f2 { background: #fed7e2; color: #b83280; }

.palette-btn .palette-label {
  position: absolute;
  bottom: -14px;
  font-size: 9px;
  color: var(--text-light);
  white-space: nowrap;
}

/* ---- Controls ---- */
.controls {
  display: flex;
  gap: 8px;
  padding: 8px 12px 12px;
  justify-content: center;
  flex-shrink: 0;
}
.btn-control {
  width: var(--btn-size);
  height: var(--btn-size);
  border-radius: 50%;
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  padding: 0;
}
.btn-control:active {
  transform: scale(0.9);
}
.btn-run {
  background: #48bb78;
  color: white;
  box-shadow: 0 4px 0 #2f855a;
  width: 64px;
  height: 64px;
  font-size: 26px;
}
.btn-run:active {
  box-shadow: 0 2px 0 #2f855a;
  transform: translateY(2px);
}
.btn-stop {
  background: #e53e3e;
  color: white;
  box-shadow: 0 4px 0 #c53030;
  width: 64px;
  height: 64px;
  font-size: 26px;
}
.btn-reset {
  background: var(--bg-dark);
  color: var(--text);
  box-shadow: 0 3px 0 #cbd5e0;
}
.btn-clear {
  background: #fed7d7;
  color: #e53e3e;
  box-shadow: 0 3px 0 #feb2b2;
}
.btn-speed {
  background: var(--bg-dark);
  color: var(--text);
  box-shadow: 0 3px 0 #cbd5e0;
  font-size: 14px;
  font-weight: 700;
}
.control-icon {
  line-height: 1;
}

/* ---- Modals ---- */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-content {
  background: var(--white);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  animation: scaleIn 0.3s ease;
}
@keyframes scaleIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.victory-stars {
  font-size: 42px;
  margin-bottom: 8px;
  display: flex;
  gap: 4px;
  justify-content: center;
}
.victory-star {
  display: inline-block;
  transition: transform 0.3s ease;
}
.victory-star.earned {
  color: #ecc94b;
  animation: starPop 0.4s ease backwards;
}
.victory-star.empty {
  color: #e2e8f0;
}
.victory-star:nth-child(1) { animation-delay: 0.1s; }
.victory-star:nth-child(2) { animation-delay: 0.3s; }
.victory-star:nth-child(3) { animation-delay: 0.5s; }
@keyframes starPop {
  0% { transform: scale(0) rotate(-30deg); }
  70% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}
.victory-title {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--world-dark);
}
.victory-msg {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 20px;
}
.victory-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.fail-icon {
  font-size: 48px;
  margin-bottom: 8px;
}
.fail-title {
  font-size: 24px;
  color: #e53e3e;
  margin-bottom: 8px;
}
.fail-msg {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 20px;
}

/* ---- HERO SELECT SCREEN ---- */
.hero-select-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 20px;
  gap: 20px;
  overflow-y: auto;
  background: linear-gradient(160deg, #e6fffa 0%, #ebf8ff 50%, #faf5ff 100%);
}

.hero-select-title {
  font-size: 28px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--w2) 0%, var(--w7) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin: 0;
}

.hero-select-sub {
  font-size: 15px;
  color: var(--text-light);
  text-align: center;
  margin: -8px 0 0;
}

.hero-cards {
  display: flex;
  gap: 12px;
  justify-content: center;
  width: 100%;
  max-width: 420px;
}

.hero-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 12px;
  background: white;
  border-radius: 16px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 12px rgba(0,0,0,0.08);
  max-width: 120px;
}

.hero-card:active {
  transform: scale(0.95);
}

.hero-card.selected {
  border-color: var(--w2);
  box-shadow: 0 4px 16px rgba(99,179,237,0.35);
}

.hero-card-preview {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-card-preview svg {
  width: 72px;
  height: 72px;
}

.hero-card-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.hero-card-emoji {
  font-size: 12px;
}

/* Color swatches */
.hero-colors-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.hero-colors-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  margin: 0;
}

.hero-color-swatches {
  display: flex;
  gap: 14px;
  justify-content: center;
}

.hero-color-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 6px;
  border-radius: 12px;
  border: 3px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.hero-color-swatch:active {
  transform: scale(0.9);
}

.hero-color-swatch.selected {
  border-color: var(--w2);
}

.swatch-preview {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(0,0,0,0.03);
}

.swatch-preview svg {
  width: 56px;
  height: 56px;
}

.swatch-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
}

.hero-confirm-btn {
  padding: 16px 48px;
  font-size: 20px;
  margin-top: 4px;
}

/* ---- Responsive ---- */
@media (min-width: 480px) {
  .worlds-grid {
    grid-template-columns: 1fr 1fr;
  }
  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    max-width: 500px;
  }
  :root {
    --cell-size: 56px;
  }
}

@media (min-width: 768px) {
  :root {
    --cell-size: 60px;
    --palette-btn: 60px;
    --btn-size: 60px;
  }
  .home-title {
    font-size: 56px;
  }
  .worlds-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 600px;
  }
  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    max-width: 500px;
  }
}

@media (max-height: 600px) {
  :root {
    --cell-size: 36px;
    --palette-btn: 44px;
  }
  .game-header {
    min-height: 36px;
    padding: 2px 8px;
  }
  .program-area {
    padding: 4px 8px;
  }
  .program-slots {
    min-height: 40px;
    padding: 4px;
  }
  .controls {
    padding: 4px 8px 8px;
  }
  .palette {
    padding: 4px 8px;
  }
}

/* Small screens (iPhone SE etc) */
@media (max-height: 570px) {
  :root {
    --cell-size: 32px;
    --palette-btn: 40px;
    --btn-size: 44px;
  }
  .btn-run, .btn-stop {
    width: 52px;
    height: 52px;
    font-size: 22px;
  }
  .program-block {
    min-width: 32px;
    height: 32px;
    font-size: 15px;
  }
}

/* Landscape */
@media (orientation: landscape) and (max-height: 500px) {
  #screen-game {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .game-header {
    width: 100%;
  }
  .game-area {
    width: 50%;
    padding: 4px;
  }
  .program-area, .palette, .controls, .function-area {
    width: 50%;
  }
  :root {
    --cell-size: 32px;
  }
}
