/*
 * Sam Kido - 🧩 Phòng Tư Duy Logic (logic-lab.js)
 * Mọi lớp mới đều có tiền tố lg-
 */

/* ================= KHUNG CHUNG ================= */
.game-card.lg-card {
  overflow: hidden;
  max-width: 100%;
}

.lg-card .section-instruction small {
  display: block;
  margin-top: 4px;
  font-size: 0.92rem;
  color: #718096;
}

.lg-card .feedback-msg.lg-info {
  background: #E8F7FF;
  color: #075985;
  border: 2px solid #90E0EF;
}

.lg-btn {
  min-height: 52px;
  padding: 10px 20px;
  border-radius: 20px;
  border: 3px solid #CBD5E0;
  background: white;
  color: #2D3748;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px 0 #A0AEC0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}

.lg-btn:hover:not(:disabled) { transform: translateY(-2px); }
.lg-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #A0AEC0; }
.lg-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.lg-btn-soft { background: #F7FAFC; }

.lg-btn-go {
  background: linear-gradient(180deg, #4ADE80, #22C55E);
  border-color: #16A34A;
  color: white;
  box-shadow: 0 5px 0 #15803D;
}
.lg-btn-go:active:not(:disabled) { box-shadow: 0 2px 0 #15803D; }

.lg-btn-next {
  margin-top: 12px;
  background: linear-gradient(180deg, #60C5FF, var(--primary-blue));
  border-color: #1E88D8;
  color: white;
  box-shadow: 0 5px 0 #1569A8;
}

.lg-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.lg-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 16px auto 0;
  padding: 10px;
  background: #F8FAFF;
  border: 3px dashed #D6E4FF;
  border-radius: 24px;
  max-width: 520px;
}

.lg-pal-btn {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 3px solid #CBD5E0;
  background: white;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 #A0AEC0;
  transition: transform 0.15s ease;
  touch-action: manipulation;
}
.lg-pal-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #A0AEC0; }
.lg-pal-btn.lg-selected {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 4px rgba(58, 168, 247, 0.35), 0 4px 0 #1E88D8;
  transform: scale(1.08);
}

.lg-shake { animation: lgShake 0.5s ease; }

@keyframes lgShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-2deg); }
  40% { transform: translateX(8px) rotate(2deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes lgPop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes lgWave {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.08); }
}

@keyframes lgPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(58, 168, 247, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(58, 168, 247, 0); }
}

.lg-win-wave { animation: lgWave 0.6s ease; }

/* ================= 1. LẬP TRÌNH ROBOT ================= */
.lg-robot-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
}

.lg-rb-board {
  --n: 4;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: min(100%, calc(var(--n) * 66px));
  flex: 0 1 auto;
  border: 4px solid #A7D8FF;
  border-radius: 22px;
  background: #EAF6FF;
  overflow: hidden;
  box-shadow: var(--clay-shadow);
}

.lg-rb-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F4FBFF;
  box-shadow: inset 0 0 0 1px #CFE8FA;
  font-size: clamp(1.2rem, 6vw, 2rem);
}
.lg-rb-cell:nth-child(odd) { background: #FFFFFF; }
.lg-rb-obst { background: #EDE7DF !important; }
.lg-rb-goal .lg-rb-icon { animation: lgWave 1.6s ease-in-out infinite; }
.lg-rb-start { box-shadow: inset 0 0 0 3px #FFD13B; }
.lg-rb-star .lg-rb-icon { animation: lgWave 1.2s ease-in-out infinite; }
.lg-rb-star.lg-collected .lg-rb-icon {
  animation: none;
  opacity: 0;
  transform: scale(2);
  transition: all 0.4s ease;
}

.lg-rb-bot {
  --r: 0;
  --c: 0;
  position: absolute;
  top: calc(var(--r) * 100% / var(--n));
  left: calc(var(--c) * 100% / var(--n));
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 7vw, 2.3rem);
  transition: top 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), left 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.2));
  pointer-events: none;
  z-index: 2;
}
.lg-rb-bot.lg-bump { animation: lgBump 0.45s ease; }
.lg-rb-bot.lg-dance { animation: lgDance 0.8s ease 2; }

@keyframes lgBump {
  0%, 100% { transform: translate(0, 0); }
  45% { transform: translate(var(--bx, 0), var(--by, 0)) rotate(10deg); }
  70% { transform: translate(0, 0) rotate(-8deg); }
}

@keyframes lgDance {
  0%, 100% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-15deg) scale(1.2); }
  75% { transform: rotate(15deg) scale(1.2); }
}

.lg-robot-side {
  flex: 1 1 280px;
  max-width: 440px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lg-program-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  color: #2D3748;
}

.lg-block-count {
  background: #E8F7FF;
  color: #0077B6;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.9rem;
}
.lg-block-count.lg-count-full { background: #FFF3CD; color: #9A6700; }

.lg-program-strip {
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
  padding: 10px;
  background: #FFFDF3;
  border: 3px dashed #FFE08A;
  border-radius: 20px;
}

.lg-program-empty {
  color: #A0AEC0;
  font-size: 0.92rem;
  align-self: center;
}

.lg-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  background: white;
  border: 3px solid #90E0EF;
  border-radius: 14px;
  font-size: 1.35rem;
  box-shadow: 0 3px 0 #7CC7DB;
  animation: lgPop 0.3s ease-out;
}
.lg-chip-loop { border-color: #C4A5FF; box-shadow: 0 3px 0 #9D65FF; background: #F6F0FF; }
.lg-chip-rep { font-size: 0.85rem; font-weight: 900; color: #6B3FD6; font-family: var(--font-display); }
.lg-chip-pending { animation: lgPulse 1.2s ease-in-out infinite; }
.lg-chip-active {
  background: #FFD13B;
  border-color: #E6A700;
  transform: translateY(-4px) scale(1.08);
}
.lg-chip-num {
  position: absolute;
  top: -8px;
  left: -6px;
  background: #3AA8F7;
  color: white;
  font-size: 0.7rem;
  font-weight: 900;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  text-align: center;
  padding: 0 3px;
}

.lg-cmd-pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.lg-cmd-btn {
  min-width: 60px;
  height: 60px;
  padding: 0 10px;
  border-radius: 18px;
  border: 3px solid #90E0EF;
  background: white;
  font-size: 1.8rem;
  cursor: pointer;
  box-shadow: 0 5px 0 #7CC7DB;
  transition: transform 0.12s ease;
  touch-action: manipulation;
}
.lg-cmd-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #7CC7DB; }
.lg-cmd-btn:disabled { opacity: 0.5; }
.lg-loop-btn {
  font-size: 1.15rem;
  font-weight: 900;
  font-family: var(--font-display);
  color: #6B3FD6;
  border-color: #C4A5FF;
  background: #F6F0FF;
  box-shadow: 0 5px 0 #9D65FF;
}
.lg-loop-btn.lg-selected { background: #9D65FF; color: white; animation: lgPulse 1.2s infinite; }

.lg-robot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.lg-robot-actions .lg-btn { flex: 1 1 90px; padding: 8px 10px; }

/* ================= 2. SUDOKU CON VẬT ================= */
.lg-sudoku {
  --n: 4;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: min(100%, calc(var(--n) * 74px));
  margin: 0 auto;
  border: 4px solid #4A5568;
  border-radius: 18px;
  overflow: hidden;
  background: #4A5568;
  gap: 2px;
  box-shadow: var(--clay-shadow);
}

.lg-sd-cell {
  aspect-ratio: 1 / 1;
  min-height: 48px;
  border: none;
  background: white;
  font-size: clamp(1.4rem, 7vw, 2.2rem);
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
  touch-action: manipulation;
}
.lg-sd-cell.lg-box-r { border-right: 3px solid #4A5568; }
.lg-sd-cell.lg-box-b { border-bottom: 3px solid #4A5568; }
.lg-sd-cell.lg-given { background: #EEF2F7; cursor: default; }
.lg-sd-cell.lg-hinted { background: #FFF8DB; }
.lg-sd-cell.lg-peer { background: #F0F8FF; }
.lg-sd-cell.lg-selected {
  background: #D6EEFF;
  outline: 4px solid var(--primary-blue);
  outline-offset: -4px;
}
.lg-sd-cell.lg-conflict { background: #FFE4E6 !important; color: inherit; outline: 3px solid #F87171; outline-offset: -3px; }
.lg-sd-cell.pop-in { animation: lgPop 0.3s ease-out; }

/* ================= 3. CÂN THĂNG BẰNG ================= */
.lg-scales {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin: 0 auto 22px;
}

.lg-scale {
  --tilt: 0deg;
  position: relative;
  width: min(100%, 300px);
  height: 190px;
}
.lg-scales .lg-scale + .lg-scale { width: min(100%, 270px); }

.lg-scale-beam {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 36px;
  height: 10px;
  background: linear-gradient(180deg, #B08968, #8D6E63);
  border-radius: 6px;
  transform-origin: 50% 50%;
  transform: rotate(var(--tilt));
  animation: lgTilt 1.1s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

@keyframes lgTilt {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(var(--tilt)); }
}
@keyframes lgPanTilt {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(calc(var(--tilt) * -1)); }
}

.lg-pan {
  position: absolute;
  top: 5px;
  width: 53%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 0;
  transform: rotate(calc(var(--tilt) * -1));
  animation: lgPanTilt 1.1s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.lg-pan-left { left: -26.5%; }
.lg-pan-right { right: -26.5%; }
.lg-pan::before {
  content: '';
  width: 70%;
  height: 22px;
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), #A0AEC0 50%, transparent calc(50% + 1px)) left / 50% 100% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 1px), #A0AEC0 50%, transparent calc(50% + 1px)) right / 50% 100% no-repeat;
}

.lg-pan-load {
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: center;
  align-items: flex-end;
  gap: 0 2px;
  min-height: 44px;
  width: 100%;
  font-size: 1.9rem;
  line-height: 1.05;
}
.lg-pan-load.lg-some { font-size: 1.35rem; }
.lg-pan-load.lg-many { font-size: 1.05rem; }

.lg-pan-dish {
  width: 100%;
  height: 12px;
  background: linear-gradient(180deg, #FFD13B, #F4A900);
  border-radius: 0 0 40px 40px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.lg-scale-pivot {
  position: absolute;
  left: 50%;
  top: 29px;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  background: #FF5E7E;
  border: 3px solid white;
  border-radius: 50%;
  z-index: 3;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.lg-scale-post {
  position: absolute;
  left: 50%;
  top: 40px;
  bottom: 12px;
  width: 12px;
  margin-left: -6px;
  background: linear-gradient(90deg, #8D6E63, #B08968);
  border-radius: 6px;
}
.lg-scale-base {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 110px;
  height: 16px;
  margin-left: -55px;
  background: #8D6E63;
  border-radius: 12px 12px 6px 6px;
}
.lg-scale.lg-level .lg-scale-pivot { background: #38D39F; }

.lg-bal-options .game-opt-btn {
  min-height: 60px;
  font-size: 1.35rem;
}

/* ================= 4. SẮP XẾP CÂU CHUYỆN ================= */
.lg-story-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  max-width: 720px;
  margin: 0 auto 18px;
}

.lg-slot {
  position: relative;
  min-height: 112px;
  border: 3px dashed #B8C4D6;
  border-radius: 20px;
  background: #F8FAFC;
  cursor: pointer;
  padding: 18px 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  touch-action: manipulation;
}
.lg-slot-num {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-purple);
  color: white;
  font-family: var(--font-display);
  font-weight: 900;
  width: 28px;
  height: 28px;
  line-height: 28px;
  border-radius: 50%;
  font-size: 0.95rem;
  box-shadow: 0 3px 0 #6B3FD6;
}
.lg-slot-body { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lg-slot.lg-filled { border-style: solid; border-color: #C4A5FF; background: #FBF8FF; }
.lg-slot.lg-filled .lg-slot-body { animation: lgPop 0.3s ease-out; }
.lg-slot.lg-right { border-color: #38D39F; background: #E9FBF3; }
.lg-slot.lg-right .lg-slot-num { background: #38D39F; box-shadow: 0 3px 0 #1F9D72; }
.lg-slot.lg-wrong { border-color: #F87171; background: #FFF1F2; }
.lg-slot.lg-locked { cursor: default; }

.lg-story-pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  background: #FFFDF3;
  border: 3px solid #FFEEBA;
  border-radius: 24px;
  max-width: 720px;
  margin: 0 auto;
  min-height: 90px;
}

.lg-story-card {
  width: 112px;
  min-height: 112px;
  padding: 8px 6px;
  border: 3px solid #FFD13B;
  border-radius: 20px;
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 5px 0 #E6B800;
  transition: transform 0.15s ease, opacity 0.2s ease;
  touch-action: manipulation;
}
.lg-story-card:hover { transform: translateY(-3px) rotate(-1deg); }
.lg-story-card.lg-used { display: none; }
.lg-sc-emoji { font-size: 2.2rem; line-height: 1.1; }
.lg-sc-cap {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 800;
  color: #4A5568;
  line-height: 1.25;
  text-align: center;
}

/* ================= 5. THÁP HÀ NỘI ================= */
.lg-hanoi-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.lg-stat {
  background: #F0F8FF;
  border: 2px solid #BEE3F8;
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  color: #2C5282;
  font-size: 0.95rem;
}
.lg-stat-limit { background: #FFF8E1; border-color: #FFE08A; color: #8A5A00; }

.lg-hanoi {
  --discs: 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
}

.lg-peg {
  position: relative;
  height: calc(90px + var(--discs) * 38px);
  border: 3px solid transparent;
  border-radius: 22px;
  background: linear-gradient(180deg, #F5FBFF 0%, #EAF4FF 100%);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 4px 34px;
  min-width: 0;
  transition: border-color 0.2s ease, background 0.2s ease;
  touch-action: manipulation;
}
.lg-peg.lg-selected { border-color: var(--primary-blue); background: #DDF0FF; }
.lg-peg-target { background: linear-gradient(180deg, #FFFBEA 0%, #FFF3C4 100%); }
.lg-peg-flag { position: absolute; top: 6px; right: 10px; font-size: 1.4rem; animation: lgWave 1.8s ease-in-out infinite; }
.lg-peg-rod {
  position: absolute;
  bottom: 34px;
  left: 50%;
  width: 12px;
  margin-left: -6px;
  height: calc(40px + var(--discs) * 38px);
  background: linear-gradient(90deg, #8D6E63, #B08968);
  border-radius: 6px 6px 0 0;
}
.lg-peg-foot {
  position: absolute;
  bottom: 6px;
  left: 8%;
  right: 8%;
  height: 24px;
  line-height: 24px;
  background: #8D6E63;
  color: white;
  font-family: var(--font-display);
  font-weight: 900;
  border-radius: 10px;
  font-size: 0.9rem;
}
.lg-peg-stack {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 3px;
  z-index: 1;
}
.lg-disc {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  background: var(--disc);
  border-radius: 17px;
  font-size: 1.25rem;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.15), 0 3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.lg-disc.lg-lifted { transform: translateY(-26px); box-shadow: 0 10px 12px rgba(0, 0, 0, 0.2); }
.lg-disc.lg-drop { animation: lgDrop 0.35s ease-out; }
.lg-disc.lg-disc-dance { animation: lgWave 0.6s ease 2; }

@keyframes lgDrop {
  0% { transform: translateY(-30px); }
  70% { transform: translateY(4px); }
  100% { transform: translateY(0); }
}

/* ================= 6. PHÂN LOẠI THÔNG MINH ================= */
.lg-sort-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  margin: 0 auto 18px;
  max-width: 640px;
  min-height: 84px;
  background: #F8FAFF;
  border: 3px dashed #D6E4FF;
  border-radius: 24px;
}
.lg-sort-item {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  border: 3px solid #E2E8F0;
  background: white;
  font-size: 2.1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #CBD5E0;
  transition: transform 0.2s ease;
  touch-action: manipulation;
}
.lg-sort-item.lg-selected {
  border-color: var(--primary-orange);
  transform: translateY(-6px) scale(1.12);
  box-shadow: 0 0 0 4px rgba(255, 159, 28, 0.3), 0 8px 0 #E08600;
}
.lg-sort-item.lg-gone { display: none; }

.lg-baskets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  max-width: 680px;
  margin: 0 auto;
}
.lg-basket {
  position: relative;
  min-height: 150px;
  border: 3px solid #FFB86B;
  border-radius: 26px 26px 34px 34px;
  background: linear-gradient(180deg, #FFF8EE 0%, #FFE9CC 100%);
  cursor: pointer;
  padding: 10px 8px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 6px 0 #E8964A;
  transition: transform 0.15s ease;
  touch-action: manipulation;
}
.lg-basket:active { transform: translateY(3px); }
.lg-basket-label {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.98rem;
  color: #7A4A12;
  line-height: 1.3;
}
.lg-basket-items { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; font-size: 1.6rem; }
.lg-basket-rim { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); font-size: 1.5rem; opacity: 0.8; }
.lg-basket.lg-happy { animation: lgWave 0.45s ease; }
.lg-in-basket { display: inline-block; }

.lg-sort-table {
  display: grid;
  grid-template-columns: minmax(64px, 0.7fr) 1fr 1fr;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
}
.lg-st-corner,
.lg-st-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #EEF4FF;
  border-radius: 16px;
  padding: 6px;
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
}
.lg-st-corner { font-size: 1rem; color: #718096; }
.lg-st-head small { font-size: 0.78rem; color: #4A5568; font-family: var(--font-display); line-height: 1.2; }
.lg-st-cell { min-height: 104px; padding: 8px; border-radius: 20px; }

/* ================= 7. ĐỐI XỨNG GƯƠNG ================= */
.lg-mirror {
  --cols: 2;
  --rows: 4;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 6px;
  margin: 0 auto;
  width: min(100%, calc(var(--cols) * 2 * 60px + 50px));
}
.lg-mr-grid {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 4px;
  padding: 6px;
  border-radius: 18px;
  background: #EEF4FF;
}
.lg-mr-right { background: #F0FFF7; }
.lg-mr-cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 2px solid #D5DEEA;
  background: white;
  padding: 0;
  min-width: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
.lg-mr-cell.lg-on {
  background: var(--cell);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
}
.lg-mr-tap { cursor: pointer; touch-action: manipulation; }
.lg-mr-tap:active { transform: scale(0.92); }
.lg-mr-tap.lg-wrong { outline: 4px solid #F87171; outline-offset: -2px; }
.lg-mr-tap.lg-missing { border: 3px dashed #F87171; background: #FFF1F2; }
.lg-mr-line {
  flex: 0 0 14px;
  position: relative;
  border-radius: 8px;
  background: linear-gradient(90deg, #BEE3F8, #FFFFFF 50%, #BEE3F8);
  box-shadow: 0 0 10px rgba(58, 168, 247, 0.5);
}
.lg-mr-line span {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.3rem;
}
.lg-mode-mirror .lg-mirror { margin-top: 18px; }
.lg-color-swatch { background: var(--swatch); border-color: rgba(0, 0, 0, 0.1); }

/* ================= ĐIỆN THOẠI NHỎ ================= */
@media (max-width: 600px) {
  .lg-robot-wrap { gap: 14px; }
  .lg-robot-side { flex-basis: 100%; }
  .lg-cmd-btn { min-width: 56px; height: 56px; font-size: 1.6rem; }
  .lg-story-slots { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
  .lg-story-card { width: 96px; min-height: 100px; }
  .lg-sc-emoji { font-size: 1.9rem; }
  .lg-sc-cap { font-size: 0.76rem; }
  .lg-scale { height: 176px; }
  .lg-pan-load { font-size: 1.6rem; }
  .lg-baskets { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
  .lg-basket { min-height: 128px; padding: 8px 4px 32px; }
  .lg-basket-label { font-size: 0.85rem; }
  .lg-sort-item { width: 56px; height: 56px; font-size: 1.8rem; }
  .lg-peg { padding-bottom: 30px; }
  .lg-disc { height: 30px; font-size: 1.05rem; }
  .lg-mr-grid { gap: 3px; padding: 4px; }
  .lg-mr-line { flex-basis: 10px; }
}

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