/* ==========================================================================
   Screen of Memories — photorealistic scene + single-photo overlay
   Scene reference: scene.webp (1280×720). Hotspot coords below.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Self-hosted fonts
   -------------------------------------------------------------------------- */

@font-face {
  font-family: 'Cinzel';
  src: url('/assets/fonts/cinzel/Cinzel-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Reem Kufi';
  src: url('/assets/fonts/reem-kufi/ReemKufi-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Reem Kufi';
  src: url('/assets/fonts/reem-kufi/ReemKufi-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Reem Kufi';
  src: url('/assets/fonts/reem-kufi/ReemKufi-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Tajawal';
  src: url('/assets/fonts/tajawal/Tajawal-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Tajawal';
  src: url('/assets/fonts/tajawal/Tajawal-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Tajawal';
  src: url('/assets/fonts/tajawal/Tajawal-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Aref Ruqaa';
  src: url('/assets/fonts/aref-ruqaa/ArefRuqaa-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

@font-face {
  font-family: 'Aref Ruqaa';
  src: url('/assets/fonts/aref-ruqaa/ArefRuqaa-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
    U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74,
    U+FE76-FEFC;
}

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */

:root {
  /* Full black bezel to inner metal edge + carved plaque inner area */
  --scene-w: 1280;
  --scene-h: 720;
  --screen-x: 260;
  --screen-y: 107;
  --screen-w: 765;
  --screen-h: 399;
  --plaque-x: 412;
  --plaque-y: 572;
  --plaque-w: 456;
  --plaque-h: 56;

  --navy-900: #0b1e3f;
  --navy-700: #12305e;
  --blue-500: #2a6fd6;
  --blue-600: #1f4fa0;

  --gold-300: #f3d27a;
  --gold-500: #d4a64a;
  --gold-700: #9c7424;
  --gold-metallic: linear-gradient(180deg, #f7e08a 0%, #b8862b 45%, #f3d27a 100%);

  --viewport-bg: #0a0f1a;

  --slide-fade: 900ms;
  --info-enter: 500ms;
  --ken-burns-scale: 1.06;
  --ken-burns-duration: 8s;
  --screen-info-bar-h: 11.5%;

  --font-en: 'Cinzel', Georgia, serif;
  --font-ar: 'Tajawal', 'Reem Kufi', system-ui, sans-serif;
  --font-plaque: 'Aref Ruqaa', 'Reem Kufi', serif;
}

/* --------------------------------------------------------------------------
   Page shell
   -------------------------------------------------------------------------- */

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

html,
body {
  margin: 0;
  padding: 0;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--viewport-bg);
  color: #f8fafc;
  font-family: var(--font-ar);
  font-feature-settings: 'liga' 1, 'calt' 1;
  -webkit-font-feature-settings: 'liga' 1, 'calt' 1;
}

body.is-fs-idle {
  cursor: none;
}

/* --------------------------------------------------------------------------
   Viewport — cover fill, edges may crop
   -------------------------------------------------------------------------- */

.memory-viewport {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--viewport-bg);
  cursor: pointer;
}

.memory-viewport:fullscreen,
.memory-viewport:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: var(--viewport-bg);
}

.memory-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(100vw, 177.78vh);
  height: max(56.25vw, 100vh);
  aspect-ratio: 16 / 9;
  container-type: size;
  --u: 1cqw;
  overflow: hidden;
  isolation: isolate;
}

@supports not (container-type: size) {
  .memory-stage {
    container-type: normal;
  }
}

.memory-scene {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  object-position: center;
  pointer-events: none;
  user-select: none;
}

/* --------------------------------------------------------------------------
   Inner digital screen overlay
   -------------------------------------------------------------------------- */

.memory-inner-screen {
  position: absolute;
  z-index: 4;
  left: calc(var(--screen-x) / var(--scene-w) * 100%);
  top: calc(var(--screen-y) / var(--scene-h) * 100%);
  width: calc(var(--screen-w) / var(--scene-w) * 100%);
  height: calc(var(--screen-h) / var(--scene-h) * 100%);
  overflow: hidden;
  background: var(--navy-900);
}

.memory-photo-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: var(--navy-700);
}

.memory-photo-column {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
}

.memory-photo-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.memory-photo-bg,
.memory-photo-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-position: center;
}

.memory-photo-bg {
  object-fit: cover;
  object-position: center;
  filter: blur(calc(var(--u) * 1.4)) brightness(0.55) saturate(1.08);
  transform: scale(1.12);
  opacity: 0;
  transition: opacity var(--slide-fade) ease;
  pointer-events: none;
}

.memory-photo-bg.is-visible {
  opacity: 1;
}

.memory-photo-layer {
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transition: opacity var(--slide-fade) ease;
  will-change: opacity, transform;
  z-index: 1;
}

/* Default: full photo visible; blurred .memory-photo-bg fills pillar/letter areas */
.memory-photo-layer:not(.is-fit-cover) {
  object-fit: contain;
  object-position: center;
}

.memory-photo-layer.is-fit-cover {
  object-fit: cover;
  object-position: center 30%;
}

.memory-photo-layer.is-fit-contain {
  object-fit: contain;
  object-position: center;
}

.memory-photo-layer.is-visible {
  opacity: 1;
}

.memory-photo-layer.is-ken-burns {
  animation: memory-ken-burns var(--ken-burns-duration, 8s) linear forwards;
}

@keyframes memory-ken-burns {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(var(--ken-burns-scale));
  }
}

.memory-photo-layer.is-broken {
  background: linear-gradient(145deg, var(--navy-700), var(--navy-900));
}

.memory-photo-layer.is-broken::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(243, 210, 122, 0.15) 0%, transparent 65%);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Info bar — slim overlay at bottom of photo
   -------------------------------------------------------------------------- */

.memory-info-bar {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--screen-info-bar-h);
  max-height: var(--screen-info-bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--u) * 1.2);
  padding: 0 calc(var(--u) * 1.6);
  box-sizing: border-box;
  background: rgba(11, 30, 63, 0.88);
  border-top: 1px solid rgba(212, 166, 74, 0.6);
  direction: rtl;
  pointer-events: none;
  container-type: size;
}

@supports (backdrop-filter: blur(6px)) {
  .memory-info-bar {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
}

.memory-info-bar__student {
  flex: 1 1 auto;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-size: 42cqh;
  animation: memory-info-enter var(--info-enter) ease;
}

.memory-info-bar__student-avatar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85em;
  height: 1.85em;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(243, 210, 122, 0.22), rgba(156, 116, 36, 0.14));
  border: 1px solid rgba(212, 166, 74, 0.62);
  box-shadow:
    0 0 0 1px rgba(11, 30, 63, 0.35) inset,
    0 2px 6px rgba(0, 0, 0, 0.18);
}

.memory-info-bar__student-icon {
  flex: 0 0 auto;
  width: 0.92em;
  height: 0.92em;
  color: var(--gold-300);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.22));
}

.memory-info-bar__student-name {
  min-width: 0;
  font-family: var(--font-ar);
  font-weight: 600;
  font-size: 1em;
  line-height: 1.2;
  font-feature-settings: 'liga' 1, 'calt' 1;
  color: #f8fafc;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.memory-info-bar__meta {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: calc(var(--u) * 0.65);
  min-width: 0;
}

.memory-info-bar__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  box-sizing: border-box;
  height: 52cqh;
  max-height: 52cqh;
  max-width: calc(var(--u) * 17);
  padding: 0 0.7em;
  border-radius: 999px;
  border: 1px solid rgba(212, 166, 74, 0.45);
  background: rgba(31, 79, 160, 0.32);
  color: #e2e8f0;
  font-size: 34cqh;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: memory-info-enter var(--info-enter) ease;
}

.memory-info-bar__chip svg {
  flex: 0 0 auto;
  width: 0.9em;
  height: 0.9em;
  opacity: 0.9;
}

.memory-info-bar__chip--now {
  display: none;
  border-color: rgba(54, 164, 191, 0.55);
  background: rgba(54, 164, 191, 0.22);
  color: #e0f2fe;
}

@keyframes memory-info-enter {
  from {
    opacity: 0;
    transform: translateY(calc(var(--u) * 0.6));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   Priority mode
   -------------------------------------------------------------------------- */

.memory-inner-screen.is-priority-mode .memory-info-bar__chip--now {
  display: inline-flex;
}

/* --------------------------------------------------------------------------
   Empty / emergency message
   -------------------------------------------------------------------------- */

.memory-empty-message {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 1.8);
  padding: calc(var(--u) * 4);
  text-align: center;
  background: linear-gradient(180deg, rgba(11, 30, 63, 0.35) 0%, rgba(11, 30, 63, 0.72) 100%);
  pointer-events: none;
}

.memory-empty-message[hidden] {
  display: none !important;
}

.memory-empty-message__icon {
  width: calc(var(--u) * 9);
  height: calc(var(--u) * 9);
  color: var(--gold-500);
  opacity: 0.9;
}

.memory-empty-message__title {
  margin: 0;
  max-width: 80%;
  font-family: var(--font-ar);
  font-weight: 700;
  font-size: calc(var(--u) * 2.6);
  line-height: 1.35;
  font-feature-settings: 'liga' 1, 'calt' 1;
  color: var(--gold-300);
}

.memory-inner-screen.is-empty-mode .memory-photo-stage,
.memory-inner-screen.is-empty-mode .memory-info-bar {
  visibility: hidden;
  pointer-events: none;
}

.memory-inner-screen.is-empty-mode .memory-empty-message {
  display: flex;
}

/* --------------------------------------------------------------------------
   Plaque text overlay
   -------------------------------------------------------------------------- */

.memory-plaque {
  position: absolute;
  z-index: 5;
  left: calc(var(--plaque-x) / var(--scene-w) * 100%);
  top: calc(var(--plaque-y) / var(--scene-h) * 100%);
  width: calc(var(--plaque-w) / var(--scene-w) * 100%);
  height: calc(var(--plaque-h) / var(--scene-h) * 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: calc(var(--u) * 0.15) calc(var(--u) * 0.8);
  pointer-events: none;
  text-align: center;
}

.memory-plaque__line {
  margin: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.05;
}

.memory-plaque__line--ar {
  font-family: var(--font-plaque);
  font-weight: 700;
  font-size: clamp(calc(var(--u) * 1.05), calc(var(--plaque-h) / var(--scene-h) * 52cqh), calc(var(--u) * 1.65));
  font-feature-settings: 'liga' 1, 'calt' 1;
  color: #c9a227;
  text-shadow:
    0 calc(var(--u) * 0.06) calc(var(--u) * 0.12) rgba(0, 0, 0, 0.65),
    0 calc(var(--u) * -0.04) calc(var(--u) * 0.08) rgba(255, 230, 160, 0.35);
}

.memory-plaque__line--en {
  font-family: var(--font-en);
  font-weight: 600;
  font-size: clamp(calc(var(--u) * 0.55), calc(var(--plaque-h) / var(--scene-h) * 28cqh), calc(var(--u) * 0.95));
  letter-spacing: calc(var(--u) * 0.02);
  color: #d4a64a;
  text-shadow: 0 calc(var(--u) * 0.08) calc(var(--u) * 0.2) rgba(0, 0, 0, 0.55);
  opacity: 0.92;
}

/* --------------------------------------------------------------------------
   Debug layout outlines (?debug=1 only)
   -------------------------------------------------------------------------- */

body.is-debug-layout .memory-inner-screen {
  outline: 2px solid #00ff88;
  outline-offset: -2px;
}

body.is-debug-layout .memory-photo-stage {
  outline: 2px solid #ffcc00;
  outline-offset: -2px;
}

body.is-debug-layout .memory-info-bar {
  outline: 2px solid #ff66aa;
  outline-offset: -2px;
}

body.is-debug-layout .memory-plaque {
  outline: 2px solid #c084fc;
  outline-offset: -2px;
}

body.is-debug-layout .memory-stage {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
}

/* --------------------------------------------------------------------------
   Plain layout — fullscreen inner screen without scene frame
   -------------------------------------------------------------------------- */

body.is-layout-plain .memory-stage {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  aspect-ratio: unset;
  --u: 1vw;
}

body.is-layout-plain .memory-inner-screen {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

body.is-layout-plain,
body.is-layout-scene {
  --memory-info-bar-h: clamp(36px, 5vh, 48px);
}

body.is-layout-plain .memory-photo-stage,
body.is-layout-scene .memory-photo-stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.is-layout-plain .memory-photo-bg,
body.is-layout-scene .memory-photo-bg {
  inset: 0;
}

body.is-layout-plain .memory-photo-column,
body.is-layout-scene .memory-photo-column {
  position: relative;
  inset: auto;
  flex: 0 1 auto;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  z-index: 2;
}

body.is-layout-plain .memory-photo-canvas,
body.is-layout-scene .memory-photo-canvas {
  position: relative;
  inset: auto;
  flex: 0 0 auto;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

body.is-layout-plain .memory-photo-layer,
body.is-layout-scene .memory-photo-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

body.is-layout-plain .memory-info-bar,
body.is-layout-scene .memory-info-bar {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  flex: 0 0 var(--memory-info-bar-h);
  width: 100%;
  height: var(--memory-info-bar-h);
  max-height: var(--memory-info-bar-h);
  margin-top: 0;
  padding: 0 clamp(8px, 1.8cqw, 12px);
  gap: calc(var(--u) * 0.45);
  z-index: 3;
  border-radius: 0 0 3px 3px;
  border-top-color: rgba(212, 166, 74, 0.45);
  container-type: size;
}

body.is-layout-plain .memory-info-bar__student,
body.is-layout-scene .memory-info-bar__student {
  gap: 0.4em;
  font-size: clamp(11px, 38cqh, 14px);
}

body.is-layout-plain .memory-info-bar__student-avatar,
body.is-layout-scene .memory-info-bar__student-avatar {
  width: 1.5em;
  height: 1.5em;
  box-shadow:
    0 0 0 1px rgba(11, 30, 63, 0.35) inset,
    0 1px 3px rgba(0, 0, 0, 0.16);
}

body.is-layout-plain .memory-info-bar__student-icon,
body.is-layout-scene .memory-info-bar__student-icon {
  width: 0.82em;
  height: 0.82em;
}

body.is-layout-plain .memory-info-bar__student-name,
body.is-layout-scene .memory-info-bar__student-name {
  font-weight: 600;
  font-size: 1em;
}

body.is-layout-plain .memory-info-bar__chip,
body.is-layout-scene .memory-info-bar__chip {
  height: auto;
  max-height: none;
  font-size: clamp(10px, 30cqh, 12px);
  padding: 0.18em 0.5em;
}

body.is-layout-plain .memory-info-bar__meta,
body.is-layout-scene .memory-info-bar__meta {
  gap: calc(var(--u) * 0.3);
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  :root {
    --slide-fade: 400ms;
    --info-enter: 300ms;
  }

  .memory-photo-layer.is-ken-burns {
    animation: none;
    transform: none;
  }

  .memory-info-bar__student,
  .memory-info-bar__student-avatar,
  .memory-info-bar__student-name,
  .memory-info-bar__chip {
    animation: none;
  }
}
