/* ===== Reset + Theme Vars ===== */
* {
  margin: 0;
  padding: 0;
}

html {
  box-sizing: border-box;
}
*,
*::before,
*::after {
  box-sizing: inherit;
}

:root {
  /* ===== Backgrounds ===== */
  --page-bg: #e8e8e8;
  --surface-light: #fafafa;
  --backdrop-dark: #000;

  /* ===== UI Layers ===== */
  --ui-bg: rgba(0, 0, 0, 0.75);
  --ui-glass: rgba(255, 255, 255, 0.18);
  --ui-hover: rgba(255, 255, 255, 0.12);
  --ui-active: rgb(230, 230, 230);
  --ui-border: rgba(255, 255, 255, 0.15);
  --ui-border-strong: rgba(255, 255, 255, 0.35);
  --ui-border-dark: rgb(97, 96, 96);

  /* ===== Cards & Popups ===== */
  --card-bg: rgba(255, 255, 255, 0.96);
  --card-border: rgba(0, 0, 0, 0.12);

  /* ===== Text ===== */
  --text-light: #ffffff;
  --text-light-muted: #d1d1d1;
  --text-mid: #6c6c6c;
  --text-muted: #757474;
  --text-hover: #969696;
  --text-dark: #111;
  --pure-black: #000;

  /* ===== Accent & Buttons ===== */
  --accent: #038cab;
  --accent-hover: #26c3e0;
  --popup-close-bg: rgba(255, 255, 255, 0.9);
  --popup-close-hover: #fff;

  /* ===== Shadows ===== */
  --shadow-soft: rgba(0, 0, 0, 0.15);
  --shadow-strong: rgba(0, 0, 0, 0.22);
}

body {
  background-color: rgba(248, 246, 244, 0.8);
  font-family: "Orbitron", sans-serif;
}

/* ===== Loading ===== */
#loading-screen {
  position: fixed;
  inset: 0;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

#loading-screen img {
  max-height: 50vh; /* يمنع الصورة من تجاوز نصف ارتفاع الشاشة */
  max-width: 80vw; /* يمنعها من تجاوز 80% من عرض الشاشة */
  height: auto;
  width: auto;
  position: relative;
}

#loading-text {
  position: absolute;
  top: 65%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dark);
  font-size: 26px;
  font-weight: 500;
  background: transparent;
  font-family: "Orbitron", sans-serif;
}

/* ===== Start CTA ===== */
#startBtn {
  position: absolute;
  top: 65%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  border-radius: 8px;
  background: var(--surface-light);
  color: var(--text-dark);

  font-size: 18px;
  font-family: "Orbitron", sans-serif;
  cursor: pointer;
  display: none;
  transition: background 0.2s, transform 0.15s;
  z-index: 2100;
  animation: pulseScale 1.2s ease-in-out infinite alternate;
}
#startBtn:hover {
  transform: translate(-50%, -50%) scale(1.05);
}
@keyframes pulseScale {
  from {
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

/* ===== Global fade & Canvas ===== */
#fade {
  position: fixed;
  inset: 0;
  background: var(--backdrop-dark);
  opacity: 0;
  pointer-events: none;
  z-index: 1800;
}
.canvas {
  position: fixed;
  left: 0;
  top: 0;
}

/* ===== Controls (top-left) ===== */
.controls {
  position: fixed;
  top: 20px;
  left: 20px;
  right: auto;
  display: none;
  flex-wrap: wrap;
  gap: 8px 10px;
  z-index: 10000;
  align-items: center;
}
.controls .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 20px;
  border-radius: 5px;
  color: #000;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  border: 1px solid var(--ui-border-dark);
  background: var(--ui-glass);

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}
.controls .btn:hover,
.color-picker:hover {
  transform: translateY(-1px);
}
.controls .btn:active {
  transform: none;
}
.controls .btn:focus {
  outline: none;
  background: var(--ui-active);

  transform: none;
}
.controls .btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 2px;
}

/* رؤية بحسب الوضعيات */
body.demo-mode .controls .btn:not(#modelsBtn) {
  display: none !important;
}
body.intro-mode .controls .btn:not(#startAnimBtn) {
  display: none !important;
}

/* ===== Hotspots ===== */
.pulse {
  position: fixed;
  transform: translate3d(-50%, -50%, 0);
  will-change: left, top;
  z-index: 999;
  display: none;
  cursor: pointer;
  background: transparent;
}
.pulse img {
  width: 28px;
  height: 28px;
  display: block;
  will-change: transform;
  transform-origin: center center;
  animation: pulse 1s infinite alternate;
}
@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.3);
  }
}
body.ui-hide-pulses .pulse {
  display: none !important;
}

#popup-text {
  text-align: center;
   font-family: "Orbitron", sans-serif;
     font-size: 16px;
  line-height: 1.6;
  color: var(--text-dark);
  text-align: center;
  margin-top: 10px;
  padding: 0 14px;
}

.about-img {
  display: block;
  margin: auto;
  width: auto;
  height: auto;
  max-width: min(45vw, 220px);
  max-height: min(40vh, 260px);
  object-fit: contain;
  opacity: 0.95;
  border-radius: 12px;
}

.about-desc {
  font-size: 22px;
  color: #333;
  font-weight: 600;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
  display: block;
  margin-top: 35px;
}
.about-desc a {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 12px;
  color: #6c6c6c;
  text-decoration: none;
  border: 2px solid var(--text-mid);

  border-radius: 6px;
}
.about-desc a:hover {
  background: var(--text-hover);
  color: var(--text-light);
}

/* ===== Models Grid ===== */
.models-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  justify-items: center;
  align-items: center;
}
.models-grid .model-item {
  text-align: center;
  cursor: pointer;
  background: #000;
  border-radius: 8px;
  padding: 10px;
  transition: transform 0.3s ease;
}
.models-grid .model-item:hover {
  transform: scale(0.99);
}
.models-grid img {
  width: 95%;
  height: auto;
  border-radius: 8px;
  object-fit: contain;
}
.model-caption {
  margin-top: 8px;
  font-family: "Orbitron", sans-serif;
  font-size: 18px;
  color: #757474;
}

.popup.models-popup {
  width: min(96vw, 770px);
  max-height: min(94vh, 860px);
  padding: 22px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.models-popup img {
  display: block;
  margin: auto;
  width: 100%;
  height: auto;
  max-width: clamp(180px, 22vw, 320px);
  max-height: clamp(160px, 25vh, 300px);
  object-fit: contain;
  opacity: 0.96;
}

.popup.models-viewing {
  width: clamp(320px, 60vw, 750px);
  max-height: min(75vh, 600px);
  padding: clamp(10px, 2vh, 18px);
  border-radius: 14px;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  overflow: auto; /* يمنع القطع */
}

.popup.models-viewing img {
  max-width: 100%;
  max-height: calc(70vh - 100px); 
  height: auto;
  width: auto;
  object-fit: contain;
}

.popup.pulse2-popup {
  width: min(88vw, 1080px);
  max-height: min(90vh, 840px);
  padding: 14px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.popup.models2-popup {
  width: clamp(420px, 70vw, 900px);
  max-height: 80vh;
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===== Buttons ===== */
.btn-back {
  display: inline-block;
  padding: 12px 24px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text-light);
  cursor: pointer;
  font-size: 16px;
}
.btn-back:hover {
  background: gray;
  border-color: var(--ui-border-strong);
}
.popup .btn-back {
  align-self: center;
  margin-top: 10px;
}

/* ===== Skip Button ===== */
#skipBtn {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100000;
  display: none;
  height: 40px;
  padding: 0 20px;
  background: var(--ui-glass);
  border: 1px solid var(--ui-border-dark);

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 5px;
  color: #000;
  font-size: 16px;
  font-family: "Orbitron", sans-serif;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
#skipBtn:hover {
  background: var(--ui-hover);
  border-color: var(--ui-border-strong);
  transform: translateY(-1px);
}

/* ===== Popup Base (Dynamic & Centered) ===== */
.popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  background: var(--card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 14px;
  box-sizing: border-box;

  width: min(86vw, calc(100vh * 1.4), 900px);
  max-height: min(80vh, 680px);
  overflow: hidden;
  z-index: 1000;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease;
  will-change: opacity;
}

.popup.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.popup.hiding {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* ===== Popup Content ===== */
#popup-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
}

/* ===== Popup Image ===== */
#popup-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(92vh - 120px);
  margin: auto;
}

/* ===== Close Button ===== */
.popup .close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  font-size: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--popup-close-bg);
  cursor: pointer;
  font-weight: 700;
  z-index: 9999;
  color: var(--text-dark);
  transition: transform 0.08s ease, background 0.12s ease;
}
.popup .close-btn:hover {
  transform: scale(1.06);
  background: var(--popup-close-hover);
}

/* ===== Popup Modifiers (inherit sizing) ===== */
.popup.models-viewing,
.popup.models2-popup {

  max-height: unset;
  padding: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .controls {
    top: 10px;
    left: 20px;
    right: auto;
    width: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
  }
  .controls .btn,
  .controls {
    height: 36px;
    padding: 0 10px;
    font-size: 14px;
  }

  #startBtn {
    top: 65%;
  }
  #loading-text {
    top: 65%;
  }
}

@media (orientation: landscape) and (max-width: 920px) {
  #loading-screen img {
    max-height: 150vh;
    max-width: 90vw;
    top: -9%;
    position: relative;
  }
  #startBtn {
    top: 77%;
  }
  .controls .btn {
    height: 32px;
    padding: 0 8px;
    font-size: 13px;
  }
}

@media (orientation: portrait) and (max-width: 390px) {
  #loading-screen img {
    max-height: 100vh;
    max-width: 90vw;
    top: -9%;
    position: relative;
  }
  #loading-text {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-dark);
    font-size: 26px;
    font-weight: 500;
    background: transparent;
    font-family: "Orbitron", sans-serif;
  }
  #startBtn {
    top: 55%;
  }
  .controls .btn {
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }
}
