/* =============================================================================
   PRISMS & CYLINDERS (ปริซึมและทรงกระบอก ม.2) - STYLE SYSTEM
   School: Wat Panchathayikawat School, Pathum Thani Primary Educational Service Area Office 2
   Teacher: Mr. Peerapong Niamsisai (ครูหมูเด้ง)
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700;800&family=Kanit:wght@400;500;600;700;800&family=Prompt:wght@300;400;500;600;700;800&family=Sarabun:wght@400;500;600;700&display=swap');

:root {
  --primary: #1e3a8a;
  --primary-light: #eff6ff;
  --secondary: #059669;
  --accent-r: #e11d48;
  --accent-h: #0284c7;
  --accent-pi: #7c3aed;
  --accent-gold: #d97706;
}

body {
  font-family: 'Prompt', 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #1e293b;
  background-color: #f8fafc;
}

h1, h2, h3, h4, .font-heading {
  font-family: 'Kanit', sans-serif;
}

.font-mono-num {
  font-family: 'Chakra Petch', monospace, sans-serif;
}

/* Chapter Nav Scrollable Bar */
.chapter-nav-btn {
  font-family: 'Prompt', sans-serif;
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #64748b;
  background: white;
  border: 1.5px solid #e2e8f0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.chapter-nav-btn:hover {
  background: #f1f5f9;
  color: #1e3a8a;
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.chapter-nav-btn.active {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  border-color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.chapter-nav-btn.active .badge-num {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.chapter-nav-btn .badge-num {
  background: #f1f5f9;
  color: #475569;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 9999px;
  font-family: 'Chakra Petch', monospace;
}

/* Chapter Visibility */
.chapter-section {
  display: none;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Math Typography (KaTeX-like CSS without external dependencies) */
.math-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  padding: 0 4px;
  font-size: 0.95em;
  line-height: 1.1;
}

.math-frac .num {
  border-bottom: 2px solid currentColor;
  padding-bottom: 2px;
}

.math-frac .den {
  padding-top: 2px;
}

.math-cancel {
  position: relative;
  display: inline-block;
  padding: 0 2px;
}

.math-cancel::after {
  content: '';
  position: absolute;
  left: -2px;
  top: 50%;
  width: calc(100% + 4px);
  height: 2.5px;
  background-color: #e11d48;
  transform: rotate(-35deg);
  transform-origin: center;
  border-radius: 1px;
}

.math-overset {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.math-overset .sup-quotient {
  font-size: 0.7em;
  font-weight: 800;
  color: #e11d48;
  margin-bottom: 2px;
  font-family: 'Chakra Petch', monospace;
}

.math-sup {
  vertical-align: super;
  font-size: 0.75em;
  font-weight: 700;
}

.math-sub {
  vertical-align: sub;
  font-size: 0.75em;
}

/* Mathematical Highlight Chips */
.hl-r { color: #e11d48; font-weight: 800; }
.hl-h { color: #0284c7; font-weight: 800; }
.hl-pi { color: #7c3aed; font-weight: 800; }
.hl-base { color: #d97706; font-weight: 800; }
.hl-total { color: #047857; font-weight: 800; }

/* Interactive Step-by-Step Box (MathInWords signature) */
.step-solution-box {
  background: white;
  border: 1.5px solid #cbd5e1;
  border-radius: 1.25rem;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.step-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed #f1f5f9;
  animation: fadeIn 0.4s ease forwards;
}

.step-row:last-child {
  border-bottom: none;
}

.step-label {
  min-width: 140px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #64748b;
  text-align: right;
  flex-shrink: 0;
}

.step-equation {
  font-size: 1.05rem;
  color: #1e293b;
  font-family: 'Prompt', 'Kanit', sans-serif;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* 3D WebGL Canvas Stage */
.canvas-stage-wrapper {
  position: relative;
  width: 100%;
  height: 500px;
  min-height: 480px;
  background: radial-gradient(circle at center, #ffffff 0%, #f1f5f9 100%);
  border-radius: 1.5rem;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04);
}

.canvas-3d-webgl {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.canvas-3d-webgl canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.canvas-3d-webgl:active {
  cursor: grabbing;
}

/* Stage Overlay Badges & Tools */
.stage-tag-badge {
  position: absolute;
  top: 14px;
  left: 16px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid #cbd5e1;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #047857;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  z-index: 10;
  pointer-events: none;
}

.stage-tools-group {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

.stage-tool-btn {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 10px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  cursor: pointer;
}

.stage-tool-btn:hover {
  background: #ffffff;
  color: #047857;
  border-color: #10b981;
  transform: translateY(-1px);
}

.stage-tool-btn.active {
  background: #ecfdf5;
  color: #047857;
  border-color: #059669;
}

/* Fold Bar (Bottom Slider & Play Button style mathinwords) */
.fold-bar-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.play-action-btn {
  background: #059669;
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.play-action-btn:hover {
  background: #047857;
  transform: scale(1.03);
}

/* Interactive Component Selection Card */
.part-pill-btn {
  padding: 8px 14px;
  border-radius: 12px;
  border: 1.5px solid #e2e8f0;
  background: white;
  color: #334155;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.part-pill-btn:hover {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1e40af;
}

.part-pill-btn.active {
  border-color: #2563eb;
  background: #1e3a8a;
  color: white;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.25);
}

/* Arena Quiz Choices (Clean Industrial High-Contrast) */
.quiz-choice-card {
  width: 100%;
  text-align: left;
  padding: 14px 18px;
  border-radius: 16px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
  font-size: 1rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.quiz-choice-card:hover:not(:disabled) {
  background: #f0f9ff;
  border-color: #0284c7;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.18);
}

.quiz-choice-card.correct {
  background: #ecfdf5 !important;
  border-color: #059669 !important;
  color: #065f46 !important;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.3) !important;
}

.quiz-choice-card.wrong {
  background: #fff1f2 !important;
  border-color: #e11d48 !important;
  color: #9f1239 !important;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.3) !important;
}

/* 6 Teams Scoreboard Card (Clean Industrial & Packaging Engineering Style) */
.font-chakra {
  font-family: 'Chakra Petch', monospace, sans-serif;
}
.font-prompt {
  font-family: 'Prompt', sans-serif;
}

/* Clean Industrial Blueprint Theme for Chapter 11 */
.blueprint-canvas {
  background-color: #ffffff;
  background-image: 
    linear-gradient(to right, rgba(2, 132, 199, 0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(2, 132, 199, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  position: relative;
}

.team-score-card {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 16px;
  padding: 8px 6px;
  text-align: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

.team-score-card:hover {
  border-color: #0284c7;
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(2, 132, 199, 0.14);
}

.team-score-card.active-turn {
  border-color: #0284c7 !important;
  background: linear-gradient(180deg, #f0f9ff 0%, #e0f2fe 100%) !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.3) !important;
}

.team-score-card.leader-glow {
  border-color: #f59e0b !important;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%) !important;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.4) !important;
}

/* Quick Score Adjustment Buttons for Teacher */
.score-quick-btn {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.15s;
  cursor: pointer;
  line-height: 1;
}

.score-quick-btn:hover {
  transform: scale(1.08);
}

.btn-plus-5 {
  background: #e0f2fe;
  color: #0369a1;
  border: 1.5px solid #0284c7;
}
.btn-plus-5:hover {
  background: #0284c7;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.btn-plus-10 {
  background: #fef3c7;
  color: #92400e;
  border: 1.5px solid #d97706;
}
.btn-plus-10:hover {
  background: #d97706;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.35);
}

.btn-minus {
  background: #ffe4e6;
  color: #be123c;
  border: 1.5px solid #e11d48;
}
.btn-minus:hover {
  background: #e11d48;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.35);
}

.qc-stamp {
  display: inline-block;
  padding: 2px 8px;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.8px;
  color: #059669;
  border: 2px solid #059669;
  border-radius: 6px;
  background: #ecfdf5;
}

/* Bottom Chapter Navigation Bar (Fixed / Sticky) */
.bottom-chapter-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid #e2e8f0;
  padding: 10px 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Step-by-Step Drawer / Modal */
.solution-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.solution-modal-backdrop.active {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}

.solution-modal-card {
  background: white;
  border-radius: 1.5rem;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  border: 1px solid #e2e8f0;
}

/* Formula Reveal Toggle Buttons */
.formula-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1.5px solid #cbd5e1;
  background-color: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  user-select: none;
}
.formula-toggle-btn:hover {
  border-color: #94a3b8;
  background-color: #f8fafc;
  color: #0f172a;
  transform: translateY(-1px);
}
.formula-toggle-btn.active-peri {
  background-color: #f0fdf4;
  border-color: #16a34a;
  color: #15803d;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.18);
}
.formula-toggle-btn.active-base {
  background-color: #fff1f2;
  border-color: #e11d48;
  color: #be123c;
  box-shadow: 0 2px 6px rgba(225, 29, 72, 0.18);
}
.formula-toggle-btn.active-lat {
  background-color: #f0f9ff;
  border-color: #0284c7;
  color: #0369a1;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.18);
}

/* =============================================================================
   MOBILE RESPONSIVENESS & TOUCH OPTIMIZATION (สมาร์ทโฟน & แท็บเล็ต)
   Designed specifically for mobile viewing by evaluation committees & supervisors
   ============================================================================= */
@media (max-width: 768px) {
  /* 1. Canvas & 3D Stage Height on Mobile */
  .canvas-stage-wrapper {
    height: 300px !important;
    min-height: 270px !important;
    border-radius: 1.25rem !important;
  }
  
  .stage-tag-badge {
    top: 8px !important;
    left: 8px !important;
    padding: 3px 10px !important;
    font-size: 0.68rem !important;
  }
  
  .stage-tools-group {
    top: 8px !important;
    right: 8px !important;
    gap: 3px !important;
  }
  
  .stage-tool-btn {
    padding: 3px 7px !important;
    font-size: 0.65rem !important;
    border-radius: 8px !important;
  }

  .fold-bar-box {
    padding: 8px 10px !important;
    gap: 8px !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .play-action-btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 8px 12px !important;
  }
  
  /* 2. Step-by-Step Solution Rows on Mobile */
  .step-solution-box {
    padding: 1rem 0.85rem !important;
    border-radius: 1rem !important;
  }
  
  .step-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 3px !important;
    padding: 7px 0 !important;
  }
  
  .step-label {
    min-width: auto !important;
    text-align: left !important;
    font-size: 0.75rem !important;
    color: #0284c7 !important;
    font-weight: 800 !important;
  }
  
  .step-equation {
    font-size: 0.92rem !important;
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 3px !important;
  }
  
  /* 3. Team Score Cards in Packaging Arena (6 Teams) */
  .team-score-card {
    padding: 6px 3px !important;
    border-radius: 12px !important;
  }
  
  .score-quick-btn {
    font-size: 9.5px !important;
    padding: 3px 4px !important;
    line-height: 1.1 !important;
  }
  
  /* 4. Bottom Sticky Chapter Bar */
  .bottom-chapter-bar {
    padding: 8px 10px !important;
    gap: 6px !important;
  }
  
  .bottom-chapter-bar button {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
  
  #lblBottomChapterTitle {
    font-size: 11px !important;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
  }
  
  /* 5. Top Chapter Nav Ribbon */
  .chapter-nav-btn {
    padding: 6px 10px !important;
    font-size: 0.72rem !important;
  }

  /* 6. Question choices in Arena */
  .quiz-choice-card {
    padding: 10px 12px !important;
    min-height: 48px !important;
  }
  
  /* 7. Range Sliders Touch UX */
  input[type="range"] {
    touch-action: pan-y;
  }
  
  /* 8. Solution Modal on Mobile */
  .solution-modal-card {
    margin: 8px !important;
    max-height: 85vh !important;
    padding: 1rem !important;
    border-radius: 1.25rem !important;
  }
}

@media (max-width: 480px) {
  .canvas-stage-wrapper {
    height: 270px !important;
    min-height: 240px !important;
  }
  
  .team-score-card .text-2xl {
    font-size: 1.35rem !important;
  }

  .team-score-card .text-\[10px\] {
    font-size: 9px !important;
  }
}


