/* ==========================================================================
   CYE-MathVerse — Design System & Stylesheet
   Subject: Form 4 Additional Mathematics
   Chapter 1: Functions — Lesson 03: Inverse Functions (Fungsi Songsang)
   ========================================================================== */

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);

  --secondary: #0ea5e9;
  --secondary-hover: #0284c7;
  --secondary-light: #e0f2fe;

  --accent: #8b5cf6;
  --accent-light: #ede9fe;

  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #ef4444;
  --danger-bg: #fee2e2;

  --bg: #f8fafc;
  --surface: #ffffff;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --border-focus: #a5b4fc;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-math: 'Cambria Math', 'Times New Roman', STIXGeneral, serif;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------------------------------
   Reset & Base Styles
   -------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   STRICT PROPER MATHEMATICS FORM DIRECTIVE (Zero Raw LaTeX Leakage)
   -------------------------------------------------------------------------- */
.katex {
  font-size: 1.06em !important;
  text-rendering: geometricPrecision;
}

.katex-display {
  margin: 0.6em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex-html {
  white-space: normal;
}

/* Fallback pure-CSS math typography */
.math-fallback {
  font-family: var(--font-math), 'Times New Roman', 'Cambria Math', serif;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  font-style: normal;
  line-height: 1.2;
  vertical-align: baseline;
}

.math-fallback sup,
sup {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.5em;
}

.math-fallback sub,
sub {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  bottom: -0.25em;
}

.math-var, em.math-var {
  font-family: var(--font-math), 'Times New Roman', 'Cambria Math', serif;
  font-style: italic;
  font-weight: 600;
  padding: 0 1px;
}

.math-sym {
  font-family: var(--font-math), system-ui, sans-serif;
  font-style: normal;
  font-weight: 700;
  padding: 0 2px;
}

.math-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  padding: 0 4px;
  font-style: normal;
  align-self: center;
}

.math-num {
  border-bottom: 1.5px solid currentColor;
  padding-bottom: 1px;
  font-size: 0.85em;
  line-height: 1.1;
}

.math-den {
  padding-top: 1px;
  font-size: 0.85em;
  line-height: 1.1;
}

.math-radicand {
  border-top: 1.5px solid currentColor;
  padding-top: 1px;
  margin-left: 1px;
}

.math-eq {
  background: rgba(79, 70, 229, 0.05);
  border-left: 3px solid var(--primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 10px 0;
  font-family: var(--font-math);
  overflow-x: auto;
}

/* --------------------------------------------------------------------------
   Layout & Container
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.nav-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.logo-text h1 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.logo-text p {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stage-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 0;
}

.stage-nav::-webkit-scrollbar {
  display: none;
}

.stage-btn {
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.stage-btn:hover {
  background: var(--bg);
  color: var(--text-main);
}

.stage-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(79, 70, 229, 0.2);
}

.stage-btn.completed {
  color: var(--success);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  text-decoration: none;
  min-height: 40px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  min-height: 34px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}
.btn-secondary:hover {
  background: var(--secondary-hover);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--bg);
  border-color: var(--border-focus);
}

/* --------------------------------------------------------------------------
   Main Content Layout
   -------------------------------------------------------------------------- */
main.main-content {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 80px 20px;
}

.stage-panel {
  display: none;
  animation: fadeIn 200ms ease;
}

.stage-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  margin-bottom: 24px;
}

.section-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.section-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Stage A: Mission Brief & Dilemma
   -------------------------------------------------------------------------- */
.brief-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  margin-top: 20px;
}

.dilemma-card {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dilemma-tag {
  background: rgba(255, 255, 255, 0.15);
  color: #a5f3fc;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-bottom: 12px;
}

.dilemma-title {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 12px;
}

.dilemma-desc {
  font-size: 0.92rem;
  color: #cbd5e1;
  line-height: 1.6;
  margin-bottom: 16px;
}

.standards-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.standards-box h4 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-main);
}

.standards-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.standards-list li {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding-left: 24px;
  position: relative;
  display: block;
}

.standards-list li::before {
  content: "✔";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--primary);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   Stage B: Discovery Lab & Manipulatives
   -------------------------------------------------------------------------- */
.lab-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.lab-tab-btn {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.lab-tab-btn:hover {
  color: var(--text-main);
}

.lab-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.lab-view {
  display: none;
}
.lab-view.active {
  display: block;
}

.manipulative-container {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.canvas-zone {
  position: relative;
  background: #fdfefe;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* SVG Proportional Scaling */
.interactive-svg {
  width: 100%;
  max-width: 650px;
  aspect-ratio: 16 / 10;
  height: auto;
}

.controls-zone {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.control-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-main);
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.slider-input {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Stage C: Worked Examples Scaffolding
   -------------------------------------------------------------------------- */
.example-nav-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.example-card-full {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.example-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.step-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 14px;
  transition: all var(--transition-fast);
}

.step-card.locked {
  opacity: 0.55;
  pointer-events: none;
}

.step-number {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 4px;
  display: block;
}

.step-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.step-feedback {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Stage D & E: Question Cards & Grader
   -------------------------------------------------------------------------- */
.practice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 20px;
}

.practice-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.practice-card:hover {
  border-color: var(--border-focus);
}

.q-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.q-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.q-badge.foundation { background: #e0f2fe; color: #0284c7; }
.q-badge.intermediate { background: #fef3c7; color: #d97706; }
.q-badge.advanced { background: #fee2e2; color: #dc2626; }

.q-content {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.6;
  margin-bottom: 16px;
}

.q-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.q-option-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--bg);
  transition: all var(--transition-fast);
  font-size: 0.9rem;
}

.q-option-label:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.q-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.q-input-row input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  outline: none;
  min-width: 200px;
}
.q-input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.hint-box {
  background: #fdf6b2;
  border-left: 3px solid #e3a008;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 8px;
  color: #723b13;
}

.q-feedback-zone {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  display: none;
}
.q-feedback-zone.correct {
  display: block;
  background: var(--success-bg);
  color: #065f46;
  border: 1px solid #6ee7b7;
}
.q-feedback-zone.incorrect {
  display: block;
  background: var(--danger-bg);
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* --------------------------------------------------------------------------
   Stage F: Exit Diagnostic & Verified Print Certificate
   -------------------------------------------------------------------------- */
.certificate-preview-card {
  background: #ffffff;
  border: 4px double #4f46e5;
  border-radius: var(--radius-lg);
  padding: 36px 30px;
  max-width: 760px;
  margin: 30px auto;
  box-shadow: var(--shadow-xl);
  text-align: center;
  position: relative;
}

.cert-header h3 {
  font-size: 1.6rem;
  font-weight: 800;
  color: #1e1b4b;
  letter-spacing: -0.01em;
}

.cert-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.cert-recipient {
  margin: 20px 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 2px dashed #c7d2fe;
  display: inline-block;
  padding: 0 24px 6px;
}

.cert-body {
  font-size: 0.95rem;
  color: #334155;
  line-height: 1.6;
  max-width: 600px;
  margin: 0 auto 20px;
}

.cert-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Mobile Teacher Remote Modal
   -------------------------------------------------------------------------- */
.remote-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.remote-modal.active {
  display: flex;
}

.remote-modal-box {
  background: #1e293b;
  color: white;
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-xl);
  border: 1px solid #334155;
}

.remote-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.btn-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.btn-close:hover {
  color: white;
}

.remote-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}

/* Laser Pointer & Annotations */
#remoteLaserPointer {
  position: fixed;
  width: 18px;
  height: 18px;
  background: radial-gradient(circle, #ef4444 40%, rgba(239, 68, 68, 0.2) 100%);
  border-radius: 50%;
  box-shadow: 0 0 12px #ef4444;
  pointer-events: none;
  z-index: 9999;
  display: none;
  transform: translate(-50%, -50%);
}

#annotationOverlayCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
}

/* --------------------------------------------------------------------------
   Responsive & Print Stylesheet
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .brief-grid,
  .manipulative-container {
    grid-template-columns: 1fr;
  }
}

@media print {
  header.navbar,
  .stage-nav,
  .nav-actions,
  .remote-modal,
  .btn,
  .no-print {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .certificate-preview-card {
    border: 3px solid #000 !important;
    box-shadow: none !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}
