/**
 * Eduplayify Game Template: math_expression (Modern Scientific Calculator Aesthetic)
 * يدعم المتصفحات القديمة والحديثة والأجهزة الضعيفة
 */

:root {
  --calc-chassis-bg: #0f172a;
  --calc-chassis-border: #334155;
  --calc-screen-bg: #020617;
  --calc-screen-border: #1e293b;
  --calc-glow: rgba(56, 189, 248, 0.28);
  --calc-text-primary: #38bdf8;
  --calc-text-secondary: #94a3b8;
  --calc-key-bg: #1e293b;
  --calc-key-border: #334155;
  --calc-key-hover: #334155;
}

/* ============================================================
   Chassis & Main Calculator Frame
   ============================================================ */
.math-calc-wrapper {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 14px;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

.math-calc-chassis {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid #334155;
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 12px 30px -6px rgba(0, 0, 0, 0.45), 0 4px 10px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}

/* Top bar: Brand + Solar Cells */
.math-calc-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.math-calc-brand-title {
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 1px;
  font-family: 'Courier New', Courier, monospace;
  display: flex;
  align-items: center;
  gap: 6px;
}

.math-calc-solar-array {
  display: flex;
  gap: 3px;
  background: #020617;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 3px 5px;
}

.math-calc-solar-cell {
  width: 14px;
  height: 12px;
  background: linear-gradient(135deg, #374151 0%, #111827 100%);
  border-radius: 1px;
}

/* ============================================================
   Digital LCD/OLED Screen
   ============================================================ */
.math-calc-screen {
  background: #020617;
  border: 2px solid #1e293b;
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.8), 0 0 20px var(--calc-glow);
  position: relative;
  overflow: hidden;
}

/* Screen scanline / subtle texture */
.math-calc-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.015) 0px, rgba(255, 255, 255, 0.015) 1px, transparent 1px, transparent 3px);
  pointer-events: none;
  opacity: 0.8;
}

.math-calc-screen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.math-calc-screen-mode {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Main Expression Typography */
.math-calc-expression-row {
  direction: ltr;
  text-align: left;
  font-family: 'Courier New', Courier, monospace, sans-serif;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 800;
  color: #f1f5f9;
  line-height: 1.4;
  word-break: break-word;
  text-shadow: 0 0 10px rgba(241, 245, 249, 0.35);
  margin-bottom: 6px;
}

/* Mathematical Symbols inside screen */
.calc-math-radical {
  display: inline-flex;
  align-items: flex-end;
  vertical-align: baseline;
  position: relative;
  color: #38bdf8;
  margin: 0 2px;
}

.calc-math-rad-sym {
  font-size: 1.15em;
  line-height: 1;
  color: #38bdf8;
  margin-inline-end: 1px;
}

.calc-math-radicand {
  border-top: 2.5px solid #38bdf8;
  padding: 0 4px;
  margin-top: -3px;
  display: inline-block;
  color: #f1f5f9;
}

.calc-math-exp {
  font-size: 0.65em;
  vertical-align: 0.55em;
  line-height: 0;
  font-weight: 800;
  color: #a5b4fc;
  margin-inline-start: 1px;
}

.calc-math-op {
  color: #38bdf8;
  padding: 0 4px;
}

.calc-math-paren {
  color: #94a3b8;
}

.math-calc-blank-token {
  display: inline-block;
  background: rgba(56, 189, 248, 0.2);
  border-bottom: 3px solid #38bdf8;
  border-radius: 4px;
  padding: 0 12px;
  min-width: 48px;
  text-align: center;
  color: #38bdf8;
  font-weight: 900;
  animation: mathPulseBlank 1.5s infinite;
}

@keyframes mathPulseBlank {
  0%, 100% { opacity: 0.8; box-shadow: 0 0 4px rgba(56, 189, 248, 0.2); }
  50% { opacity: 1; box-shadow: 0 0 12px rgba(56, 189, 248, 0.6); }
}

/* ============================================================
   Style 1: Multiple Choice Options
   ============================================================ */
.math-choices-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

@media (max-width: 560px) {
  .math-choices-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

.math-choice-key {
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  outline: none;
}

.math-choice-key:hover:not(:disabled) {
  background: #334155;
  border-color: #475569;
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.math-choice-key:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.math-choice-badge {
  width: 32px;
  height: 32px;
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-weight: 800;
  font-size: 0.95rem;
  font-family: 'Courier New', Courier, monospace;
}

.math-choice-value {
  direction: ltr;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.5px;
}

.math-choice-key.is-correct {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%) !important;
  border-color: #34d399 !important;
  box-shadow: 0 0 16px rgba(52, 211, 153, 0.5) !important;
}

.math-choice-key.is-correct .math-choice-value {
  color: #ecfdf5 !important;
  text-shadow: 0 0 8px #34d399;
}

.math-choice-key.is-incorrect {
  background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%) !important;
  border-color: #f87171 !important;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.5) !important;
  opacity: 0.8;
}

.math-choice-key:disabled {
  cursor: default;
}

/* ============================================================
   Style 2: True / False Buttons
   ============================================================ */
.math-tf-buttons-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}

.math-tf-action-btn {
  border-radius: 14px;
  padding: 16px 20px;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  direction: rtl;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  outline: none;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
}

.math-tf-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.math-tf-lbl {
  font-size: 1.25rem;
  font-weight: 800;
}

.math-tf-sub {
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0.9;
  direction: ltr;
  unicode-bidi: isolate;
}

.math-tf-true-btn {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border: 2px solid #34d399;
  color: #fff;
}

.math-tf-true-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(52, 211, 153, 0.4);
}

.math-tf-false-btn {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  border: 2px solid #f87171;
  color: #fff;
}

.math-tf-false-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(248, 113, 113, 0.4);
}

.math-tf-action-btn:active:not(:disabled) {
  transform: translateY(1px);
}

/* ============================================================
   Style 3: Matching Pairs (توصيل)
   ============================================================ */
.math-matching-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}

@media (max-width: 480px) {
  .math-matching-container {
    gap: 10px;
  }
}

.math-match-col {
  display: grid;
  grid-auto-rows: 1fr;
  gap: 12px;
}

.math-match-card {
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 12px;
  padding: 12px 14px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 800;
  font-size: 1.15rem;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.25);
  min-height: 56px;
  text-align: center;
  position: relative;
  user-select: none;
  box-sizing: border-box;
}

.math-match-card:hover:not(.is-matched) {
  border-color: #38bdf8;
  background: #334155;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
}

.math-match-card.is-selected {
  border-color: #38bdf8 !important;
  background: #0369a1 !important;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.7) !important;
  z-index: 5;
}

.math-match-card.is-incorrect {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.2) !important;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.6) !important;
  animation: mathShake 0.4s ease;
}

@keyframes mathShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.math-match-card.is-matched {
  cursor: default;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  animation: mathPop 0.35s ease;
}

@keyframes mathPop {
  0% { transform: scale(0.96); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* 8 Distinct, High-Contrast Harmonious Pair Color Themes */
/* Pair 0: Vibrant Emerald */
.math-match-card.pair-color-0 {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%) !important;
  border-color: #10b981 !important;
  color: #ecfdf5 !important;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.5) !important;
}
.math-match-card.pair-color-0 .calc-math-op,
.math-match-card.pair-color-0 .calc-math-rad-sym,
.math-match-card.pair-color-0 .calc-math-radicand {
  color: #a7f3d0 !important;
  border-color: #a7f3d0 !important;
}

/* Pair 1: Royal Blue / Sapphire */
.math-match-card.pair-color-1 {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%) !important;
  border-color: #60a5fa !important;
  color: #eff6ff !important;
  box-shadow: 0 0 14px rgba(96, 165, 250, 0.5) !important;
}
.math-match-card.pair-color-1 .calc-math-op,
.math-match-card.pair-color-1 .calc-math-rad-sym,
.math-match-card.pair-color-1 .calc-math-radicand {
  color: #bfdbfe !important;
  border-color: #bfdbfe !important;
}

/* Pair 2: Golden Amber */
.math-match-card.pair-color-2 {
  background: linear-gradient(135deg, #78350f 0%, #b45309 100%) !important;
  border-color: #fbbf24 !important;
  color: #fffbeb !important;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.5) !important;
}
.math-match-card.pair-color-2 .calc-math-op,
.math-match-card.pair-color-2 .calc-math-rad-sym,
.math-match-card.pair-color-2 .calc-math-radicand {
  color: #fde68a !important;
  border-color: #fde68a !important;
}

/* Pair 3: Crimson Rose */
.math-match-card.pair-color-3 {
  background: linear-gradient(135deg, #881337 0%, #be123c 100%) !important;
  border-color: #fb7185 !important;
  color: #fff1f2 !important;
  box-shadow: 0 0 14px rgba(251, 113, 133, 0.5) !important;
}
.math-match-card.pair-color-3 .calc-math-op,
.math-match-card.pair-color-3 .calc-math-rad-sym,
.math-match-card.pair-color-3 .calc-math-radicand {
  color: #fecdd3 !important;
  border-color: #fecdd3 !important;
}

/* Pair 4: Royal Purple */
.math-match-card.pair-color-4 {
  background: linear-gradient(135deg, #581c87 0%, #7e22ce 100%) !important;
  border-color: #c084fc !important;
  color: #faf5ff !important;
  box-shadow: 0 0 14px rgba(192, 132, 252, 0.5) !important;
}
.math-match-card.pair-color-4 .calc-math-op,
.math-match-card.pair-color-4 .calc-math-rad-sym,
.math-match-card.pair-color-4 .calc-math-radicand {
  color: #e9d5ff !important;
  border-color: #e9d5ff !important;
}

/* Pair 5: Electric Cyan */
.math-match-card.pair-color-5 {
  background: linear-gradient(135deg, #155e75 0%, #0891b2 100%) !important;
  border-color: #22d3ee !important;
  color: #ecfeff !important;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.5) !important;
}
.math-match-card.pair-color-5 .calc-math-op,
.math-match-card.pair-color-5 .calc-math-rad-sym,
.math-match-card.pair-color-5 .calc-math-radicand {
  color: #a5f3fc !important;
  border-color: #a5f3fc !important;
}

/* Pair 6: Sunset Orange */
.math-match-card.pair-color-6 {
  background: linear-gradient(135deg, #7c2d12 0%, #c2410c 100%) !important;
  border-color: #fb923c !important;
  color: #fff7ed !important;
  box-shadow: 0 0 14px rgba(251, 146, 60, 0.5) !important;
}
.math-match-card.pair-color-6 .calc-math-op,
.math-match-card.pair-color-6 .calc-math-rad-sym,
.math-match-card.pair-color-6 .calc-math-radicand {
  color: #fed7aa !important;
  border-color: #fed7aa !important;
}

/* Pair 7: Radiant Fuchsia */
.math-match-card.pair-color-7 {
  background: linear-gradient(135deg, #701a75 0%, #a21caf 100%) !important;
  border-color: #f472b6 !important;
  color: #fdf4ff !important;
  box-shadow: 0 0 14px rgba(244, 114, 182, 0.5) !important;
}
.math-match-card.pair-color-7 .calc-math-op,
.math-match-card.pair-color-7 .calc-math-rad-sym,
.math-match-card.pair-color-7 .calc-math-radicand {
  color: #fbcfe8 !important;
  border-color: #fbcfe8 !important;
}

/* ============================================================
   Style 4: Fill in Blank with Calculator Numpad
   ============================================================ */
.math-fill-keypad-wrap {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.math-fill-display-bar {
  width: 100%;
  max-width: 380px;
  background: #020617;
  border: 2px solid #334155;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

.math-fill-live-input {
  direction: ltr;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.6rem;
  font-weight: 900;
  color: #38bdf8;
  letter-spacing: 1px;
}

.math-numpad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 380px;
}

.math-np-btn {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 10px;
  color: #f8fafc;
  padding: 12px 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
  outline: none;
}

.math-np-btn:hover {
  background: #334155;
  border-color: #64748b;
  transform: translateY(-1px);
}

.math-np-btn:active {
  transform: translateY(1px);
}

.math-np-btn.btn-submit {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border-color: #38bdf8;
  color: #fff;
  grid-column: span 2;
  font-size: 1.05rem;
  font-weight: 800;
}

.math-np-btn.btn-submit:hover {
  background: #0284c7;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.math-np-btn.btn-danger {
  background: #991b1b;
  border-color: #ef4444;
}

/* ============================================================
   Feedback Banner inside Chassis
   ============================================================ */
.math-feedback-box {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  display: none;
  animation: mathFadeIn 0.25s ease;
}

.math-feedback-box.correct {
  display: block;
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid #10b981;
  color: #34d399;
}

.math-feedback-box.incorrect {
  display: block;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #f87171;
}

@keyframes mathFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* مصيدة غير بديهية: grid/flex-gap غائبان في القديم — بديل فقط عند الغياب */
@supports not (display: grid) {
  .math-choices-grid, .math-numpad-grid { display: block; }
  .math-choice-key, .math-np-btn { display: inline-block; width: 46%; margin: 2%; vertical-align: top; }
  .math-matching-container { display: block; }
  .math-match-col { display: inline-block; width: 46%; margin: 0 1%; vertical-align: top; }
}
@supports not (gap: 8px) {
  .math-match-col > *, .math-tf-buttons-wrap > * { margin: 4px; }
}
