/* ═══════════════════════════════════════════════════════════
   games.css — styles for 5 interactive mini-games + AI Tutor
   ═══════════════════════════════════════════════════════════ */

/* ═══ DECOMPOSITION PUZZLE ═══ */
.decomp-tasks {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.decomp-task-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 100px; padding: 6px 14px;
  font-family: var(--font-sans); font-size: 12px; font-weight: 500;
  color: var(--text); cursor: pointer; transition: all .2s;
}
.decomp-task-btn:hover { background: var(--surface-3); }
.decomp-task-btn.on {
  background: var(--g-blue); color: white; border-color: var(--g-blue);
  font-weight: 600;
}
.decomp-board {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px; background: var(--surface-2);
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  min-height: 240px;
}
.decomp-step {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  cursor: grab; transition: all .25s cubic-bezier(.2,.8,.2,1);
  font-size: 13.5px; box-shadow: var(--shadow-sm);
}
.decomp-step:hover { transform: translateX(4px); box-shadow: var(--shadow-md); }
.decomp-step:active { cursor: grabbing; }
.decomp-step.dragging { opacity: .4; transform: scale(.98); }
.decomp-step.decomp-ok {
  background: rgba(52,168,83,.1); border-color: var(--g-green);
}
.decomp-step.decomp-ok .decomp-num {
  background: var(--g-green); color: white;
}
.decomp-step.decomp-no {
  background: rgba(234,67,53,.06); border-color: rgba(234,67,53,.3);
}
.decomp-handle {
  font-family: var(--mono); color: var(--text-muted);
  cursor: grab; font-weight: 700; font-size: 14px;
  letter-spacing: -2px;
}
.decomp-num {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 12px;
  transition: all .25s;
}
.decomp-txt { flex: 1; }
.decomp-feedback {
  margin-top: 10px; padding: 0;
  font-size: 13px; line-height: 1.5;
}
.decomp-feedback.ok, .decomp-feedback.no {
  padding: 12px 16px; border-radius: 10px;
  animation: revealUp .3s;
}
.decomp-feedback.ok {
  background: rgba(52,168,83,.1); border: 1px solid rgba(52,168,83,.3);
  color: var(--g-green-d);
}
.decomp-feedback.no {
  background: rgba(251,188,4,.1); border: 1px solid rgba(251,188,4,.3);
  color: var(--g-yellow-d);
}

/* ═══ PATTERN RECOGNITION ═══ */
.pattern-game {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
  text-align: center;
}
.pattern-status {
  display: flex; justify-content: space-between;
  margin-bottom: 18px; font-size: 12.5px;
  color: var(--text-dim);
}
.pattern-score strong { color: var(--g-blue-d); font-size: 14px; }
.pattern-streak { color: var(--g-red); font-weight: 700; font-size: 13px; }
.pattern-seq {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; flex-wrap: wrap;
  margin: 24px 0 28px;
}
.pt-cell {
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--g-blue), var(--g-blue-d));
  color: white; font-family: var(--font-display); font-weight: 900;
  font-size: 24px; border-radius: 14px;
  box-shadow: 0 4px 12px rgba(66,133,244,.25);
  animation: ptPop .4s cubic-bezier(.34,1.56,.64,1) backwards;
}
.pt-cell.pt-q {
  background: var(--surface-2); color: var(--g-red);
  border: 2px dashed var(--g-red); box-shadow: none;
  font-size: 32px;
  animation: ptPop .4s cubic-bezier(.34,1.56,.64,1) backwards, ptPulse 1.5s ease-in-out infinite .5s;
}
@keyframes ptPop { from { opacity: 0; transform: scale(.5) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes ptPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.pt-arrow {
  color: var(--text-muted); font-size: 18px; font-weight: 600;
}
.pattern-options {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.pt-opt {
  background: var(--surface-2); border: 2px solid var(--border);
  border-radius: 12px; padding: 14px 22px;
  font-family: var(--font-display); font-weight: 700; font-size: 18px;
  color: var(--text); cursor: pointer; transition: all .2s;
  min-width: 70px;
}
.pt-opt:hover:not(:disabled) {
  border-color: var(--g-blue); transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(66,133,244,.2);
}
.pt-opt:disabled { cursor: default; opacity: .55; }
.pt-opt.correct {
  background: var(--g-green); color: white; border-color: var(--g-green);
  opacity: 1;
}
.pt-opt.wrong {
  background: var(--g-red); color: white; border-color: var(--g-red);
  opacity: 1;
}
.pattern-feedback {
  font-size: 13px; line-height: 1.5; padding: 0;
  min-height: 24px;
}
.pattern-feedback.ok { color: var(--g-green-d); }
.pattern-feedback.no { color: var(--g-red-d); }
.pattern-end {
  text-align: center; padding: 20px;
}
.pattern-end h3 {
  font-family: var(--font-display); font-size: 28px; font-weight: 700;
  color: var(--text); margin-bottom: 8px;
}

/* ═══ BUBBLE SORT GAME ═══ */
.bubble-game {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.bubble-meta {
  display: flex; justify-content: space-around; gap: 14px;
  padding: 10px 14px; background: var(--surface-2);
  border-radius: 10px; margin-bottom: 18px;
  font-size: 12.5px; color: var(--text-dim);
}
.bubble-meta strong {
  color: var(--g-blue-d); font-family: var(--mono); font-size: 14px;
  margin-left: 4px;
}
.bubble-row {
  display: flex; gap: 6px; justify-content: center;
  margin: 18px 0;
  flex-wrap: wrap;
}
.bubble-cell {
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #ffd966, #FBBC04);
  color: #4a3a00; font-family: var(--font-display); font-weight: 900;
  font-size: 22px; border-radius: 12px;
  cursor: pointer; transition: all .25s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 4px 12px rgba(251,188,4,.25);
  animation: ptPop .4s cubic-bezier(.34,1.56,.64,1) backwards;
}
.bubble-cell:hover { transform: translateY(-4px); }
.bubble-cell.bubble-sel {
  background: linear-gradient(135deg, var(--g-red), var(--g-red-d));
  color: white; transform: translateY(-6px);
  box-shadow: 0 8px 20px rgba(234,67,53,.4);
}
.bubble-cell.bubble-flash { animation: bFlash .6s; }
.bubble-cell.bubble-hint { animation: bHint 1.5s; }
@keyframes bFlash {
  0% { transform: scale(1); }
  50% { transform: scale(1.15) translateY(-6px); box-shadow: 0 10px 24px rgba(52,168,83,.4); background: linear-gradient(135deg, #80e09a, #34A853); color: white; }
  100% { transform: scale(1); }
}
@keyframes bHint {
  0%, 100% { box-shadow: 0 4px 12px rgba(251,188,4,.25); }
  50% { box-shadow: 0 0 0 4px rgba(66,133,244,.5), 0 4px 12px rgba(66,133,244,.4); }
}
.bubble-feedback {
  margin: 0; padding: 0; font-size: 13px; min-height: 20px;
}
.bubble-feedback.ok, .bubble-feedback.warn, .bubble-feedback.note {
  padding: 10px 14px; border-radius: 10px;
  animation: revealUp .3s;
}
.bubble-feedback.ok { background: rgba(52,168,83,.1); color: var(--g-green-d); }
.bubble-feedback.warn { background: rgba(234,67,53,.1); color: var(--g-red-d); }
.bubble-feedback.note { background: rgba(66,133,244,.08); color: var(--g-blue-d); }

/* ═══ SCRATCH BUILDER ═══ */
.scratch-builder {
  display: grid;
  grid-template-columns: 270px 1fr 220px;
  gap: 0;
  align-items: stretch;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
  min-height: 380px;
}
[data-theme="dark"] .scratch-builder { background: #1f2336; border-color: #3a4060; }
.scratch-builder h5 {
  font-family: 'Helvetica Neue', sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-muted); margin: 0 0 8px;
}

/* Palette = horizontal split: cat rail | block list */
.sb-palette {
  display: grid;
  grid-template-columns: 70px 1fr;
  background: #f9f9f9;
  border-right: 1px solid #e6e6e6;
  overflow: hidden;
}
[data-theme="dark"] .sb-palette { background: #1c2034; border-right-color: #2a2e44; }

/* Category rail */
.sb-cats {
  display: flex; flex-direction: column;
  background: #fff; padding: 8px 0;
  border-right: 1px solid #e6e6e6;
}
[data-theme="dark"] .sb-cats { background: #181b2a; border-right-color: #2a2e44; }
.sb-cat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; font-family: 'Helvetica Neue', sans-serif;
  font-size: 9.5px; font-weight: 600; color: #575E75;
  cursor: default; user-select: none;
}
[data-theme="dark"] .sb-cat { color: #b8bdd0; }
.sb-cat-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 4px solid;
  box-sizing: border-box;
}
.sb-cat-motion .sb-cat-dot { border-color: #4C97FF; }
.sb-cat-looks  .sb-cat-dot { border-color: #9966FF; }
.sb-cat-sound  .sb-cat-dot { border-color: #CF63CF; }
.sb-cat-event  .sb-cat-dot { border-color: #FFBF00; }
.sb-cat-control .sb-cat-dot { border-color: #FFAB19; }

/* Palette panel */
.sb-palette-list {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 12px 16px;
  overflow-y: auto;
  flex: 1;
}
.sb-pal-head {
  font-family: 'Helvetica Neue', sans-serif;
  font-size: 14px; font-weight: 700;
  color: #575E75;
  margin: 8px 0 -2px;
}
.sb-pal-head:first-child { margin-top: 0; }
[data-theme="dark"] .sb-pal-head { color: #c8cde0; }
.sb-pal-event   { color: #cf9f00; }
.sb-pal-motion  { color: #4C97FF; }
.sb-pal-looks   { color: #9966FF; }
.sb-pal-sound   { color: #CF63CF; }
.sb-pal-control { color: #cf8400; }

.sb-palette-list .sb-block { cursor: grab; }
.sb-palette-list .sb-block:active { cursor: grabbing; }

/* Scratch 3 block — rounded "stack" shape */
.sb-block {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
  color: white; line-height: 1.4;
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
  user-select: none;
  position: relative;
}
.sb-block > span:first-child {
  display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px;
}
.sb-block.sb-motion  { background: #4C97FF; box-shadow: inset 0 -2px 0 #3373CC, 0 1px 0 rgba(0,0,0,.1); }
.sb-block.sb-looks   { background: #9966FF; box-shadow: inset 0 -2px 0 #774DCB, 0 1px 0 rgba(0,0,0,.1); }
.sb-block.sb-sound   { background: #CF63CF; box-shadow: inset 0 -2px 0 #BD42BD, 0 1px 0 rgba(0,0,0,.1); }
.sb-block.sb-event   { background: #FFBF00; box-shadow: inset 0 -2px 0 #CC9900, 0 1px 0 rgba(0,0,0,.1); color: #fff; }
.sb-block.sb-control { background: #FFAB19; box-shadow: inset 0 -2px 0 #CF8B17, 0 1px 0 rgba(0,0,0,.1); color: #fff; }

/* Hat block — curved top, Scratch event shape */
.sb-block.sb-hat {
  border-radius: 16px 16px 4px 4px;
  padding-top: 10px;
}

/* Embedded inputs */
.sb-num, .sb-txt, .sb-drop {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: #575E75;
  font-weight: 600; font-size: 11px;
  padding: 1px 8px; min-width: 22px; height: 18px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.sb-num  { border-radius: 999px; }   /* round number pill */
.sb-txt  { border-radius: 4px; padding: 1px 7px; }  /* rectangular text */
.sb-drop {
  border-radius: 4px; padding: 1px 6px 1px 8px;
  background: rgba(0,0,0,.18); color: #fff;
  box-shadow: none;
  gap: 4px;
}
.sb-caret { font-size: 9px; opacity: .85; }

/* Workspace clones use the same chrome but inputs flip darker */
.sb-workspace .sb-block {
  font-size: 13px; padding: 7px 14px;
}
.sb-workspace .sb-block.sb-hat { padding-top: 11px; }

.sb-block.sb-running {
  outline: 3px solid #fff;
  box-shadow: 0 0 0 5px rgba(76,151,255,.5), 0 4px 12px rgba(0,0,0,.25);
  transform: scale(1.03);
  transition: all .2s;
}
.sb-remove {
  background: rgba(0,0,0,.25); border: none; color: white;
  border-radius: 50%; width: 18px; height: 18px;
  cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Helvetica Neue', sans-serif;
  flex-shrink: 0;
}
.sb-remove:hover { background: rgba(0,0,0,.5); }

.sb-workspace-wrap, .sb-stage-wrap {
  min-width: 0; padding: 12px;
}
.sb-stage-wrap { border-left: 1px solid #e6e6e6; background: #fafafa; }
[data-theme="dark"] .sb-stage-wrap { background: #1c2034; border-left-color: #2a2e44; }
.sb-workspace {
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,.07) 1px, transparent 1px) 0 0 / 14px 14px,
    #f9f9f9;
  border: none;
  border-radius: 6px; padding: 14px; min-height: 300px;
  display: flex; flex-direction: column; gap: 0;
  transition: all .2s;
}
[data-theme="dark"] .sb-workspace {
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / 14px 14px,
    #20253a;
}
.sb-workspace.sb-over {
  background: rgba(76,151,255,.12);
  outline: 2px dashed #4C97FF;
  outline-offset: -4px;
}
.sb-empty {
  color: var(--text-muted); font-size: 12px; font-style: italic;
  text-align: center; padding: 30px 10px;
}
.sb-stage {
  background: white; border: 2px solid var(--border);
  border-radius: 10px; height: 200px; position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #f7f4e8 25%, transparent 25%),
    linear-gradient(-45deg, #f7f4e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f7f4e8 75%),
    linear-gradient(-45deg, transparent 75%, #f7f4e8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, 10px 0px;
}
.sb-sprite {
  position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 48px; transition: transform .35s ease-out;
}
.sb-bubble {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  background: white; border: 2px solid var(--text);
  padding: 6px 12px; border-radius: 16px;
  font-size: 12px; font-weight: 600; color: var(--text);
  opacity: 0; transition: opacity .3s;
}
.sb-log {
  margin-top: 8px; font-family: var(--mono); font-size: 11px;
  background: var(--surface-2); padding: 8px 10px;
  border-radius: 8px; max-height: 100px; overflow-y: auto;
  color: var(--text-dim); line-height: 1.7;
  border: 1px solid var(--border);
}

/* ═══ AI TUTOR (floating chat) ═══ */
.ai-tutor {
  position: fixed; bottom: 70px; right: 18px; z-index: 80;
  pointer-events: none;
}
.ai-tutor > * { pointer-events: auto; }
.ai-tutor-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--g-blue), var(--g-green));
  border: none; cursor: pointer;
  box-shadow: 0 8px 24px rgba(66,133,244,.4);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: all .25s cubic-bezier(.34,1.56,.64,1);
}
.ai-tutor-fab:hover { transform: scale(1.08); box-shadow: 0 10px 28px rgba(66,133,244,.5); }
.ai-tutor-fab.open {
  transform: rotate(180deg);
  background: var(--text);
}
.ai-tutor-emoji {
  font-size: 26px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.2));
}
.ai-tutor-pulse {
  position: absolute; inset: -3px;
  border-radius: 50%; border: 2px solid var(--g-blue);
  opacity: 0; animation: aiPulse 2s ease-out infinite;
}
@keyframes aiPulse {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.4); }
}
.ai-tutor-fab.open .ai-tutor-pulse { display: none; }
.ai-tutor-panel {
  position: absolute; bottom: 70px; right: 0;
  width: 340px; height: 480px; max-height: calc(100vh - 160px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  opacity: 0; transform: translateY(10px) scale(.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition: all .3s cubic-bezier(.34,1.4,.64,1);
  overflow: hidden;
}
.ai-tutor-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.ai-tutor-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(66,133,244,.08), rgba(52,168,83,.08));
  border-bottom: 1px solid var(--border);
}
.ai-tutor-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--g-blue), var(--g-green));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.ai-tutor-id { flex: 1; line-height: 1.2; }
.ai-tutor-id strong { display: block; font-family: var(--font-display); font-weight: 700; font-size: 14px; }
.ai-tutor-id span { font-size: 11px; color: var(--text-muted); font-family: var(--mono); letter-spacing: .5px; }
.ai-tutor-close {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--text-muted); padding: 0;
  width: 28px; height: 28px; line-height: 1;
  border-radius: 50%; transition: all .2s;
}
.ai-tutor-close:hover { background: var(--surface-2); color: var(--text); }
.ai-tutor-body {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.ai-msg { display: flex; }
.ai-msg-bot { justify-content: flex-start; }
.ai-msg-user { justify-content: flex-end; }
.ai-bubble {
  max-width: 85%; padding: 10px 14px;
  border-radius: 16px; font-size: 13px; line-height: 1.5;
  animation: revealUp .25s;
}
.ai-msg-bot .ai-bubble {
  background: var(--surface-2); color: var(--text);
  border-bottom-left-radius: 4px;
}
.ai-msg-user .ai-bubble {
  background: var(--g-blue); color: white;
  border-bottom-right-radius: 4px;
}
.ai-typing { display: flex; gap: 4px; padding: 4px 0; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing {
  0%, 100% { opacity: .3; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1); }
}
.ai-suggestions {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 4px;
}
.ai-suggestions button {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 12px;
  font-family: var(--font-sans); color: var(--text); cursor: pointer;
  text-align: left; transition: all .2s;
}
.ai-suggestions button:hover {
  background: rgba(66,133,244,.08); border-color: var(--g-blue);
  transform: translateX(3px);
}
.ai-tutor-form {
  display: flex; gap: 6px; padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ai-tutor-form input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 100px; padding: 9px 14px;
  font-family: var(--font-sans); font-size: 12.5px; color: var(--text);
  outline: none; transition: all .2s;
}
.ai-tutor-form input:focus { border-color: var(--g-blue); background: var(--surface); }
.ai-tutor-form button {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--g-blue); color: white; border: none;
  cursor: pointer; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.ai-tutor-form button:hover { background: var(--g-blue-d); transform: scale(1.05); }

/* Hide AI tutor on intro */
.intro:not(.gone) ~ .ai-tutor { display: none; }

/* Mobile adjustments */
@media (max-width: 720px) {
  .scratch-builder { grid-template-columns: 1fr; }
  .ai-tutor-panel { width: calc(100vw - 30px); right: 0; }
  .pt-cell, .bubble-cell { width: 48px; height: 48px; font-size: 18px; }
}
