:root {
  --bg-app: #f0f4ff;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-light: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  --accent-teal: #0d9488;
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 14px 32px rgba(79, 70, 229, 0.16);
  --radius-md: 14px;
  --radius-lg: 20px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: radial-gradient(circle at top left, #e0e7ff 0%, #f0fdf4 55%, #fef3c7 100%);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* =========================================================================
   ГОРЕН НАВИГАЦИОНЕН ПАНЕЛ (КОМПАКТЕН ЗА ТАБЛЕТ)
   ========================================================================= */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid #dbeafe;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 30;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.jude-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.brand-titles h1 {
  font-size: 16px;
  font-weight: 800;
  color: #1e1b4b;
  line-height: 1.15;
}

.brand-titles p {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.problem-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.problem-select {
  appearance: none;
  background: #f8fafc url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 10px center;
  border: 2px solid #c7d2fe;
  border-radius: 12px;
  padding: 7px 32px 7px 12px;
  font-size: 13.5px;
  font-weight: 700;
  color: #1e1b4b;
  cursor: pointer;
  max-width: 280px;
  transition: all 0.15s ease;
}

.problem-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}

.btn-tool:active {
  transform: scale(0.96);
}

.btn-dice {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  box-shadow: 0 3px 8px rgba(234, 88, 12, 0.25);
}

.btn-scratchpad {
  background: #eef2ff;
  color: #4338ca;
  border-color: #c7d2fe;
}

.btn-blocks {
  background: #f0fdf4;
  color: #047857;
  border-color: #a7f3d0;
}

.btn-custom {
  background: #fdf2f8;
  color: #be185d;
  border-color: #fbcfe8;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.phase-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 12px;
}

.phase-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 9px;
  font-size: 11.5px;
  font-weight: 700;
  color: #64748b;
  transition: all 0.2s ease;
}

.phase-pill.active {
  background: #4f46e5;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.phase-pill.done {
  background: #d1fae5;
  color: #065f46;
}

.score-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fffbeb;
  border: 2px solid #fde68a;
  padding: 5px 11px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 800;
  color: #b45309;
}

/* =========================================================================
   3-ЗОННА РЕШЕТКА ЗА ТАБЛЕТ (ПЕЙЗАЖЕН РЕЖИМ - LANDSCAPE)
   ========================================================================= */
.tablet-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 295px 1fr;
  grid-template-rows: minmax(195px, 34%) 1fr;
  grid-template-areas:
    "top-zone top-zone"
    "left-zone right-zone";
  gap: 10px;
  padding: 10px 14px;
  overflow: hidden;
  min-height: 0;
}

/* =========================================================================
   ГОРНА ЗОНА: Фаза 1 (Ловец на факти) + Фаза 2 (Динамични ленти / Bar Model)
   ========================================================================= */
.top-zone {
  grid-area: top-zone;
  display: grid;
  grid-template-columns: 1.08fr 1fr;
  gap: 10px;
  min-height: 0;
}

.panel-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 2px solid #e0e7ff;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: linear-gradient(90deg, #f8fafc 0%, #eef2ff 100%);
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
  color: #1e1b4b;
}

.phase-tag {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
  background: #4f46e5;
  color: #fff;
  letter-spacing: 0.4px;
}

.phase-tag.phase-2 { background: #0d9488; }
.phase-tag.phase-3 { background: #7c3aed; }
.phase-tag.phase-4 { background: #059669; }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-mini {
  padding: 4px 9px;
  border-radius: 8px;
  border: 1.5px solid #cbd5e1;
  background: #fff;
  font-size: 11.5px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-mini:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef2ff;
}

.btn-mini.active {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

/* ФАЗА 1: ИНТЕРАКТИВЕН ЧЕТЕЦ */
.story-reader-body {
  padding: 10px 14px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.story-text {
  font-size: 15.5px;
  line-height: 1.68;
  color: #1e293b;
  font-weight: 500;
  user-select: none;
}

.story-token {
  display: inline-block;
  padding: 1px 7px;
  margin: 0 1px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 2.5px dashed #6366f1;
  background: rgba(99, 102, 241, 0.08);
  color: #312e81;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.story-token:hover {
  transform: translateY(-2px) scale(1.03);
  background: rgba(99, 102, 241, 0.18);
}

.story-token.extracted {
  background: #dcfce7;
  border: 2px solid #22c55e;
  color: #14532d;
  padding: 1px 8px;
}

.story-token.extracted::after {
  content: ' ✓';
  font-size: 12px;
  font-weight: 900;
  color: #15803d;
}

.story-token.trap-glow {
  animation: trapFlash 0.8s ease-in-out infinite alternate;
  background: #fef08a !important;
  border: 2.5px solid #dc2626 !important;
  color: #991b1b !important;
  font-weight: 900;
}

@keyframes trapFlash {
  from { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  to { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.reader-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  background: #f8fafc;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.fact-progress-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #4338ca;
}

/* ФАЗА 2: ВИЗУАЛНО МОДЕЛИРАНЕ (BAR MODEL SVG) */
.bar-model-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 10px;
  overflow: hidden;
  position: relative;
  background: #fcfdff;
}

.bar-step-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
  overflow-x: auto;
  flex-shrink: 0;
}

.bar-tab {
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 700;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
}

.bar-tab.active {
  background: #0d9488;
  color: #fff;
  border-color: #0d9488;
}

.bar-svg-container {
  flex: 1;
  width: 100%;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bar-svg-container svg {
  width: 100%;
  height: 100%;
  max-height: 145px;
  overflow: visible;
}

.pulse-segment {
  animation: segmentPulse 1.5s ease-in-out infinite;
}

@keyframes segmentPulse {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 2px rgba(245, 158, 11, 0.4)); }
  50% { opacity: 0.78; filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.85)); }
}

/* =========================================================================
   ЛЯВА ЗОНА: ИНВЕНТАР С ЧИПОВЕ И УЛОВЕНИ ФАКТИ
   ========================================================================= */
.left-zone {
  grid-area: left-zone;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inventory-body {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inventory-section-title {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  color: #475569;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chips-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.empty-inventory-hint {
  padding: 12px;
  border-radius: 12px;
  border: 2px dashed #cbd5e1;
  background: #f8fafc;
  color: #64748b;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  line-height: 1.45;
}

/* ИНТЕРАКТИВЕН ЧИП (ЖЕТОН) */
.math-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 12px;
  font-weight: 800;
  cursor: grab;
  border: 2px solid transparent;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.08);
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
  touch-action: none;
  position: relative;
  background: #fff;
}

.math-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.13);
}

.math-chip:active {
  cursor: grabbing;
  transform: scale(0.97);
}

.math-chip.selected-chip {
  outline: 3px solid #4f46e5;
  outline-offset: 2px;
  transform: scale(1.03);
  box-shadow: 0 0 0 5px rgba(79, 70, 229, 0.2);
}

.chip-num {
  font-size: 17px;
  font-weight: 900;
  padding: 3px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  min-width: 36px;
  text-align: center;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chip-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
}

.chip-label {
  font-size: 12.5px;
  font-weight: 800;
}

.chip-unit {
  font-size: 10.5px;
  opacity: 0.85;
  font-weight: 700;
}

.chip-step-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.75);
  font-weight: 900;
}

/* Цветови теми на чиповете */
.chip-blue { background: #dbeafe; border-color: #60a5fa; color: #1e3a8a; }
.chip-blue .chip-num { color: #1d4ed8; }

.chip-teal { background: #ccfbf1; border-color: #2dd4bf; color: #134e4a; }
.chip-teal .chip-num { color: #0f766e; }

.chip-amber { background: #fef3c7; border-color: #fbbf24; color: #78350f; }
.chip-amber .chip-num { color: #b45309; }

.chip-purple { background: #ede9fe; border-color: #a78bfa; color: #4c1d95; }
.chip-purple .chip-num { color: #6d28d9; }

.chip-emerald { background: #d1fae5; border-color: #34d399; color: #064e3b; }
.chip-emerald .chip-num { color: #047857; }

.chip-pink { background: #fce7f3; border-color: #f472b6; color: #831843; }
.chip-pink .chip-num { color: #be185d; }

.chip-indigo { background: #e0e7ff; border-color: #818cf8; color: #1e1b4b; }
.chip-indigo .chip-num { color: #4338ca; }

/* Списък с уловени ключови подсказки */
.clues-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.clue-item {
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 9px;
  border-radius: 9px;
  background: #f8fafc;
  border-left: 4px solid #6366f1;
  color: #334155;
}

/* =========================================================================
   ЦЕНТРАЛНА / ДЯСНА ЗОНА: ФАЗА 3 (РАБОТНА ВЕРИГА) И ФАЗА 4 (КРАЕН ОТГОВОР)
   ========================================================================= */
.right-zone {
  grid-area: right-zone;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chain-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* SVG слой за видимите свързващи нишки между стъпките */
.chain-connections-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.connection-thread {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 7 5;
  animation: threadFlow 1.2s linear infinite;
  opacity: 0.55;
}

@keyframes threadFlow {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

/* КАРТА ЗА СТЪПКА */
.step-card {
  position: relative;
  z-index: 5;
  background: #ffffff;
  border-radius: 16px;
  border: 2px solid #e2e8f0;
  padding: 11px 14px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05);
  transition: all 0.2s ease;
}

.step-card.active-step {
  border-color: #6366f1;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.12);
  background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
}

.step-card.solved-step {
  border-color: #34d399;
  background: linear-gradient(90deg, #ffffff 0%, #f0fdf4 100%);
}

.step-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.step-question-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.step-num-badge {
  background: #4f46e5;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 9px;
  border-radius: 8px;
  white-space: nowrap;
}

.step-card.solved-step .step-num-badge {
  background: #059669;
}

.step-block-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 7px;
}

.step-question-text {
  font-size: 14px;
  font-weight: 800;
  color: #0f172a;
}

/* ФОРМУЛА ОТ СЛОТОВЕ */
.step-formula-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-slot {
  min-width: 148px;
  min-height: 48px;
  border: 2.5px dashed #94a3b8;
  border-radius: 12px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  transition: all 0.16s ease;
  cursor: pointer;
  position: relative;
}

.chip-slot.drag-over,
.chip-slot.ready-for-tap {
  border-color: #4f46e5;
  background: #eef2ff;
  transform: scale(1.03);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

.chip-slot.filled {
  border-style: solid;
  border-color: transparent;
  background: transparent;
  padding: 0;
}

.slot-placeholder {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  text-align: center;
  padding: 0 8px;
}

.slot-clear-btn {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: 2px solid #fff;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
}

/* БУТОНИ ЗА ОПЕРАЦИЯ (+ - × :) */
.op-selector {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 4px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 11px;
  border: 1.5px solid #cbd5e1;
}

.op-btn {
  height: 34px;
  border-radius: 8px;
  border: none;
  background: #ffffff;
  color: #334155;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.12s ease;
}

.op-btn:hover {
  background: #e0e7ff;
  color: #4338ca;
}

.op-btn.active {
  background: #4f46e5;
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.35);
}

.equals-sign {
  font-size: 20px;
  font-weight: 900;
  color: #475569;
  padding: 0 2px;
}

/* ПОЛЕ ЗА РЕЗУЛТАТ И БУТОН ЗА ЧЕРНОВА В КОЛОНКА */
.result-input-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-result-input {
  width: 82px;
  height: 44px;
  border-radius: 12px;
  border: 2.5px solid #cbd5e1;
  background: #fff;
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  color: #0f172a;
  cursor: pointer;
}

.step-result-input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.btn-step-scratch {
  height: 44px;
  padding: 0 10px;
  border-radius: 11px;
  border: 2px solid #c7d2fe;
  background: #eef2ff;
  color: #4338ca;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-check-step {
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
  transition: transform 0.12s ease;
}

.btn-check-step:active {
  transform: scale(0.96);
}

/* ГЕНЕРИРАН РЕЗУЛТАТЕН ЧИП В КРАЯ НА СТЪПКАТА */
.step-output-zone {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.output-arrow-label {
  font-size: 11.5px;
  font-weight: 800;
  color: #059669;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* БАЛОН ЗА УМНИ ПОДСКАЗКИ (SCAFFOLDING FEEDBACK) */
.scaffolding-bubble {
  margin-top: 9px;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: popIn 0.22s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.scaffolding-bubble.hint-info {
  background: #eff6ff;
  border: 2px solid #93c5fd;
  color: #1e3a8a;
}

.scaffolding-bubble.hint-trap {
  background: #fffbeb;
  border: 2px solid #f59e0b;
  color: #78350f;
}

.scaffolding-bubble.hint-dep {
  background: #fef2f2;
  border: 2px solid #f87171;
  color: #7f1d1d;
}

.scaffolding-bubble.hint-success {
  background: #ecfdf5;
  border: 2px solid #34d399;
  color: #065f46;
}

.bubble-icon {
  font-size: 20px;
  flex-shrink: 0;
}

/* =========================================================================
   ФАЗА 4: СГЛОБЯВАНЕ НА ОТГОВОРА И ОБРАТНА ПРОВЕРКА
   ========================================================================= */
.phase4-card {
  background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
  border: 2.5px solid #6ee7b7;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-md);
  z-index: 5;
}

.phase4-card.locked {
  opacity: 0.65;
  background: #f8fafc;
  border-color: #cbd5e1;
}

.final-questions-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.final-q-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.85);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1.5px solid #d1fae5;
}

.final-q-label {
  font-size: 13.5px;
  font-weight: 800;
  color: #064e3b;
}

.final-q-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit-select {
  height: 44px;
  padding: 0 12px;
  border-radius: 11px;
  border: 2px solid #6ee7b7;
  background: #fff;
  font-size: 14px;
  font-weight: 800;
  color: #065f46;
  cursor: pointer;
}

.backcheck-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #d1fae5;
  border: 2px solid #10b981;
  color: #064e3b;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.5;
}

/* =========================================================================
   МОДАЛНИ ПРОЗОРЦИ: СМЕТАЛО В КОЛОНКА, 6 БЛОКА, СЪЗДАЙ ЗАДАЧА, ЦИФРОВА КЛАВИАТУРА
   ========================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-window {
  background: #fff;
  border-radius: 22px;
  border: 3px solid #c7d2fe;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn 0.2s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: linear-gradient(90deg, #eef2ff, #f5f3ff);
  border-bottom: 2px solid #e0e7ff;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 900;
  color: #1e1b4b;
}

.btn-close-modal {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: #e2e8f0;
  color: #334155;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

/* СМЕТАЛО В КОЛОНКА (СТОТИЦИ, ДЕСЕТКИ, ЕДИНИЦИ) + СВОБОДНО ЧЕРТАНЕ */
.scratchpad-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.column-math-box {
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  border-radius: 16px;
  padding: 14px;
}

.col-grid {
  display: grid;
  grid-template-columns: 42px repeat(3, 62px);
  gap: 6px;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}

.col-header {
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  padding: 4px;
  border-radius: 7px;
}

.col-h { background: #dbeafe; color: #1e40af; }
.col-t { background: #fef3c7; color: #92400e; }
.col-u { background: #dcfce7; color: #166534; }

.carry-btn {
  height: 30px;
  border-radius: 8px;
  border: 1.5px dashed #94a3b8;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
  cursor: pointer;
}

.carry-btn.active {
  background: #fef3c7;
  border-style: solid;
  border-color: #f59e0b;
  color: #b45309;
}

.digit-cell {
  height: 50px;
  border-radius: 11px;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 900;
  color: #0f172a;
}

.digit-input {
  width: 100%;
  height: 52px;
  border-radius: 11px;
  border: 2.5px solid #6366f1;
  background: #eef2ff;
  font-size: 24px;
  font-weight: 900;
  text-align: center;
  color: #1e1b4b;
}

.col-divider {
  grid-column: 1 / -1;
  height: 4px;
  background: #1e293b;
  border-radius: 2px;
  margin: 2px 0;
}

/* Платно за писане с пръст или стилус */
.drawing-pad-box {
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scratch-canvas {
  width: 100%;
  height: 210px;
  background:
    linear-gradient(to right, #f1f5f9 1px, transparent 1px),
    linear-gradient(to bottom, #f1f5f9 1px, transparent 1px);
  background-size: 22px 22px;
  border-radius: 10px;
  border: 1.5px solid #e2e8f0;
  touch-action: none;
  cursor: crosshair;
}

/* ПЛАВАЩА ТАБЛЕТНА ЦИФРОВА КЛАВИАТУРА (NUMPAD) */
.tablet-numpad-popover {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: #ffffff;
  border: 3px solid #4f46e5;
  border-radius: 20px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 85;
  display: none;
  width: 245px;
}

.tablet-numpad-popover.open {
  display: block;
  animation: popIn 0.16s ease-out;
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.numpad-key {
  height: 44px;
  border-radius: 11px;
  border: 1.5px solid #cbd5e1;
  background: #f8fafc;
  font-size: 19px;
  font-weight: 900;
  color: #0f172a;
  cursor: pointer;
}

.numpad-key:active {
  background: #e0e7ff;
  transform: scale(0.95);
}

.numpad-key.key-ok {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

/* Таблица на 6-те релационни блока */
.blocks-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.block-ref-card {
  padding: 11px;
  border-radius: 14px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
}

.block-ref-card h4 {
  font-size: 13.5px;
  font-weight: 900;
  margin-bottom: 4px;
}

.block-ref-card p {
  font-size: 12px;
  color: #475569;
  line-height: 1.4;
}

/* Празнични конфети при верен краен отговор */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 14px;
  top: -20px;
  z-index: 200;
  pointer-events: none;
  animation: confettiFall 2.4s linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(105vh) rotate(540deg);
    opacity: 0;
  }
}

/* Адаптивност за по-малки екрани / портретен режим на таблет */
@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .app-header {
    flex-wrap: wrap;
  }
  .tablet-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "top-zone"
      "left-zone"
      "right-zone";
    overflow: visible;
  }
  .top-zone {
    grid-template-columns: 1fr;
  }
  .scratchpad-layout,
  .blocks-grid {
    grid-template-columns: 1fr;
  }
}
