/* مختبر هجرة الأيونات - أنماط عربية RTL */
:root {
  --bg: #0B1220;
  --card: #131C2F;
  --text: #E8EEF9;
  --accent: #2DD4BF;
  --pos: #EF4444;
  --neg: #64748B;
  --purple: #A855F7;
  --blue: #3B82F6;
  --orange: #F97316;
  --gray-ion: #CBD5E1;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.45);
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --base: 17px;
  --line: 1.8;
}

[data-theme="light"] {
  --bg: #F0F4FA;
  --card: #FFFFFF;
  --text: #0F172A;
  --accent: #0D9488;
  --shadow: 0 8px 32px rgba(0,0,0,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--base);
  line-height: var(--line);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  width: 100%;
  touch-action: manipulation;
  letter-spacing: 0;
}

/* ===== بوابة الدخول ===== */
.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: opacity 0.6s ease;
}
.gate.hidden { opacity: 0; pointer-events: none; }

.gate-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0B1220 0%, #131C2F 100%);
  transform: translateY(0);
  transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 2;
}
.gate-top.open { transform: translateY(-100%); }

.gate-greeting {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.4rem;
  color: var(--text);
}
.gate-hint {
  font-size: 0.95rem;
  opacity: 0.75;
  text-align: center;
}

.gate-bottom {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: linear-gradient(0deg, #0B1220 0%, #131C2F 100%);
  transform: translateY(0);
  transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 2;
  padding: 1rem;
}
.gate-bottom.open { transform: translateY(100%); }

.gate-track {
  width: min(280px, 80vw);
  height: 56px;
  background: #1a2438;
  border-radius: 28px;
  border: 2px solid #2a3a55;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}
.gate-handle {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, #94a3b8, #475569);
  box-shadow: 0 0 12px rgba(45, 212, 191, 0.6), inset 0 1px 2px rgba(255,255,255,0.3);
  cursor: grab;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s;
}
.gate-handle:active { cursor: grabbing; }
.gate-handle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.handle-glow {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse-glow 1.5s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.btn-enter {
  min-height: 48px;
  min-width: 120px;
  padding: 0.6rem 1.5rem;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--accent);
  color: #0B1220;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-enter:hover, .btn-enter:focus-visible {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(45,212,191,0.5);
  outline: none;
}

/* ===== شاشة شكر تيك توك ===== */
.tiktok-thanks {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: radial-gradient(ellipse at center, #1a1040 0%, #0B1220 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.5s;
}
.tiktok-thanks.hidden { opacity: 0; pointer-events: none; }
.thanks-content { text-align: center; animation: fade-up 0.8s ease; }
.thanks-msg {
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 700;
  margin-bottom: 2rem;
  color: #E9D5FF;
}
.btn-continue {
  min-height: 48px;
  padding: 0.7rem 2rem;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== التطبيق الرئيسي ===== */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.app.hidden { display: none; }

.top-bar {
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  background: var(--card);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 50;
  gap: 0.5rem;
}
.app-title {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-align: center;
}
.btn-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}
.btn-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.hamburger {
  width: 22px;
  height: 2px;
  background: var(--text);
  position: relative;
  display: block;
}
.hamburger::before, .hamburger::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 2px;
  background: var(--text);
  left: 0;
}
.hamburger::before { top: -7px; }
.hamburger::after { top: 7px; }

.tiktok-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  text-decoration: none;
}
.tiktok-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== المشهد ===== */
.canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.webgl-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
  background: var(--bg);
}
.webgl-fallback.hidden { display: none; }
.safety-note { font-size: 0.9rem; opacity: 0.85; max-width: 320px; }

/* ===== bottom sheet ===== */
.info-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 0.75rem 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 40;
  max-height: 45%;
  overflow-y: auto;
}
.info-sheet.open {
  transform: translateY(0);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}
.info-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--accent);
}
.info-role { margin-bottom: 0.5rem; font-size: 0.95rem; }
.info-question {
  font-size: 0.9rem;
  opacity: 0.9;
  border-right: 3px solid var(--accent);
  padding-right: 0.75rem;
  margin-bottom: 0.75rem;
}
.btn-close-sheet {
  min-height: 44px;
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  background: rgba(45,212,191,0.15);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}

/* ===== شريط التحكم ===== */
.controls-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--card);
  border-top: 1px solid rgba(255,255,255,0.06);
  overflow-x: auto;
  z-index: 30;
  min-height: 56px;
}
.ctrl-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 1.1rem;
  background: #1e293b;
  color: var(--text);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.ctrl-btn:focus-visible {
  outline: 2px solid var(--accent);
}
.ctrl-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}
.ctrl-label {
  font-size: 0.7rem;
  opacity: 0.7;
  line-height: 1.2;
}
input[type="range"] {
  width: 70px;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}
.timer-display {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 600;
  min-width: 70px;
  text-align: center;
  flex-shrink: 0;
}
.timer-max { opacity: 0.55; font-size: 0.8rem; }

/* ===== أزرار الإزالة ===== */
.remove-bar {
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  overflow-x: auto;
  background: rgba(19,28,47,0.9);
  border-top: 1px solid rgba(255,255,255,0.04);
  flex-shrink: 0;
}
.rm-btn {
  min-height: 40px;
  padding: 0.3rem 0.7rem;
  font-family: inherit;
  font-size: 0.8rem;
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.rm-btn[aria-pressed="true"] {
  background: rgba(239,68,68,0.2);
  border-color: var(--pos);
  color: #fca5a5;
}
.rm-btn:focus-visible {
  outline: 2px solid var(--accent);
}

/* ===== رسالة الحالة ===== */
.status-msg {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19,28,47,0.95);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 90%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 35;
  border: 1px solid rgba(45,212,191,0.3);
}
.status-msg.show { opacity: 1; }

.safety-fixed {
  position: absolute;
  bottom: 110px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.72rem;
  opacity: 0.55;
  pointer-events: none;
  z-index: 20;
  padding: 0 0.5rem;
}

/* ===== اللوحة الجانبية ===== */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(320px, 88vw);
  height: 100%;
  background: var(--card);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.side-panel.open {
  transform: translateX(0);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.panel-header h3 { font-size: 1.1rem; }
.panel-nav { padding: 0.75rem; flex: 1; }
.panel-section { margin-bottom: 1.25rem; }
.panel-section h4 {
  font-size: 0.85rem;
  opacity: 0.7;
  margin-bottom: 0.5rem;
  font-weight: 500;
}
.exp-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.exp-list button {
  width: 100%;
  text-align: right;
  min-height: 48px;
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: #1e293b;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.exp-list button.active {
  border-color: var(--accent);
  background: rgba(45,212,191,0.12);
}
.exp-list button:focus-visible {
  outline: 2px solid var(--accent);
}
.panel-btn {
  width: 100%;
  min-height: 48px;
  margin-bottom: 0.4rem;
  padding: 0.6rem;
  font-family: inherit;
  font-size: 0.95rem;
  background: #1e293b;
  color: var(--text);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.panel-btn:focus-visible {
  outline: 2px solid var(--accent);
}

/* ===== النوافذ المنبثقة ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 400px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-content h3 {
  margin-bottom: 1rem;
  font-size: 1.15rem;
  color: var(--accent);
}
.prep-list {
  list-style: none;
  margin-bottom: 1rem;
}
.prep-list li {
  margin-bottom: 0.6rem;
}
.prep-list label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.prep-list input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.btn-modal-close {
  width: 100%;
  min-height: 48px;
  margin-top: 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  background: rgba(45,212,191,0.15);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}
.teacher-qa p { margin-bottom: 0.5rem; font-size: 0.95rem; }
.teacher-qa .answer {
  color: var(--accent);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  padding-right: 0.75rem;
  border-right: 2px solid var(--accent);
}
.teacher-qa .answer.hidden { display: none; }
.predict-q { margin-bottom: 1rem; font-size: 1rem; }
.predict-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.predict-options button {
  min-height: 48px;
  font-family: inherit;
  font-size: 0.95rem;
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 8px;
  cursor: pointer;
  text-align: right;
  padding: 0.5rem 0.8rem;
}
.predict-options button.selected {
  border-color: var(--accent);
  background: rgba(45,212,191,0.15);
}
.predict-feedback {
  font-size: 0.95rem;
  min-height: 1.5em;
  margin-bottom: 0.5rem;
}

/* ===== تقليل الحركة ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== شاشات صغيرة ===== */
@media (max-width: 400px) {
  .app-title { font-size: 0.9rem; }
  .ctrl-label { font-size: 0.65rem; }
  input[type="range"] { width: 55px; }
  .safety-fixed { font-size: 0.65rem; bottom: 105px; }
  .status-msg { bottom: 130px; }
}

/* تركيز واضح */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
