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

:root {
	--fg: #000000;
	--muted: #ffffff;
	--ph-bg: #ffffff00;
	--font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
	--overlay-gap: 80px;
	--frame-outer-border: clamp(2px, 0.25vw, 6px);
	--frame-ratio: 1.7777778;
	--frame-v-gap: max(0px, calc((100vh - (100vw / var(--frame-ratio))) / 2));
	--frame-display-w: min(100vw, calc(100vh * var(--frame-ratio)));
	--frame-display-h: min(100vh, calc(100vw / var(--frame-ratio)));
	--grid-fit-width: min(72vw, calc((100vh * var(--frame-ratio)) * 0.72));
	--frame-pad-x: clamp(6px, calc(var(--frame-display-w) * 0.01), 18px);
	--frame-pad-y: clamp(10px, calc(var(--frame-display-h) * 0.05), 56px);
	--frame-safe-y: calc(var(--frame-v-gap) + var(--nav-top) + var(--nav-h) + clamp(16px, 3vh, 32px));
	--nav-h: 26px;
	--nav-top: clamp(28px, calc(var(--frame-display-h) * 0.11), 90px);
}

html, body {
	color: var(--fg);
	font-family: var(--font);
	font-size: 11px;
	font-weight: 900;
	text-transform: uppercase;
	-webkit-text-stroke: 0.75px #000000;
	background-color: #000000;
	min-height: 100vh;
	height: 100%;
	overflow-y: auto;
	overscroll-behavior-y: contain;
	overscroll-behavior-x: none;
	touch-action: pan-y;
}

body::before {
	content: '';
	position: fixed;
	top: 50%;
	left: 50%;
	width: var(--frame-display-w);
	height: var(--frame-display-h);
	transform: translate(-50%, -50%);
	pointer-events: none;
	z-index: 3;
	box-shadow: 0 0 0 100vmax #000000;
}

body::after {
	content: '';
	position: fixed;
	top: 50%;
	left: 50%;
	width: var(--frame-display-w);
	height: var(--frame-display-h);
	transform: translate(-50%, -50%);
	pointer-events: none;
	z-index: 4;
	border: var(--frame-outer-border) solid #000000;
}

.page {
    padding: var(--frame-pad-y) var(--frame-pad-x) var(--frame-pad-y);
    padding-top: max(var(--frame-pad-y), var(--frame-safe-y));
    /* Increase this value to create space at the bottom */
    padding-bottom: clamp(100px, 15vh, 200px); 
    display: flex;
    justify-content: center;
    width: var(--grid-fit-width);
    margin: 0 auto;
    position: relative;
}

.page::after {
	content: '';
	position: fixed;
	inset: 0;
	background-image: url('Assets/Frames/1-800-Jina-Lee.png');
	background-size: contain;
	background-position: center;
	background-repeat: no-repeat;
	pointer-events: none;
}
.page::after {
	z-index: 5;
}

/* =========================
	Grid + Cards
	========================= */

.grid {
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	grid-auto-rows: 275px;
	gap: 0 15px;
	border-left: 1px solid var(--border);
	border-top: 1px solid var(--border);
	align-items: end;
	width: 100%;
	max-width: 1500px;
	margin-bottom: 10px;
	perspective: 900px;
	transform-style: preserve-3d;
	position: relative;
	z-index: 2;
	opacity: 0.9;
	filter: blur(0.6px);
}

body.layout-pending .grid {
	opacity: 0 !important;
}

.col {
	border-right: 1px solid var(--border);
	border-bottom: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	transform-origin: center center;
}

.ph {
	background: var(--ph-bg);
	position: relative;
	flex-shrink: 0;
	overflow: hidden;
	display: flex;
	align-items: flex-end;
	padding: 5px 6px;
	cursor: pointer;
}

.ph + .ph { border-top: 1px solid var(--border); }

.ph::before {
	content: '';
	position: absolute;
	inset: 0;
	background-image:
		linear-gradient(to bottom right, transparent calc(50% - 0.5px), var(--ph-text) calc(50% - 0.5px), var(--ph-text) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
		linear-gradient(to bottom left,  transparent calc(50% - 0.5px), var(--ph-text) calc(50% - 0.5px), var(--ph-text) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.ph.has-image {
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
}

.ph.has-image::before {
	display: none;
}

.ph.v  { aspect-ratio: 3/4; }
.ph.s  { aspect-ratio: 1/1; }
.ph.h  { aspect-ratio: 4/3; }

.meta {
	padding: 6px 7px 10px;
	flex-shrink: 0;
	border-top: 1px solid var(--border);
}

.meta .ref {
	display: block;
	color: #000000;
	font-size: 9px;
	line-height: 1.5;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.meta .name {
	display: block;
	color: var(--fg);
	font-size: 12px;
	line-height: 1.4;
	margin-bottom: 2px;
	font-weight: 800;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.meta .ref,
.meta .name,
.overlay-nav {
	text-shadow:
		0 0 0.22px rgba(255, 255, 255, 0.28),
		0.22px -0.14px rgba(255, 255, 255, 0.2),
		-0.24px 0.18px rgba(0, 0, 0, 0.22),
		0.42px 0 rgba(255, 255, 255, 0.14),
		-0.42px 0 rgba(0, 0, 0, 0.16),
		0 0.34px rgba(255, 255, 255, 0.1),
		0 -0.34px rgba(0, 0, 0, 0.12);
}

/* =========================
	Overlay
	========================= */

.overlay {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 999;
	opacity: 0.9;
}

.overlay.active { display: flex; }

body.overlay-open .grid,
body.overlay-open .page-nav { visibility: hidden; }

.overlay-inner {
	width: 80vw;
	max-width: 900px;
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	position: relative;
}

.overlay-nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 36px;
	height: 36px;
	border: none;
	background: transparent;
	cursor: pointer;
	display: grid;
	place-items: center;
	z-index: 2;
	padding: 0;
}

.overlay-nav img {
	width: 50px;
	height: 50px;
	object-fit: contain;
	display: block;
	opacity: 0.85;
}

.overlay-nav.prev { left: 18px; filter: blur(0.3px); opacity: 0.75; }
.overlay-nav.next { right: 18px; filter: blur(0.3px); opacity: 0.75; }

.overlay-ph {
	position: relative;
	display: flex;
	justify-content: center;
	align-items: center;
	background: transparent;
	max-width: 80%;
	max-height: 80vh;
}

.overlay-ph img {
	max-width: 100%;
	max-height: 80vh;
	object-fit: contain;
	display: block;
}

.overlay-ph::before {
	content: '';
	position: absolute;
	inset: 0;
	background-image:
		linear-gradient(to bottom right, transparent calc(50% - 0.5px), var(--ph-text) calc(50% - 0.5px), var(--ph-text) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
		linear-gradient(to bottom left,  transparent calc(50% - 0.5px), var(--ph-text) calc(50% - 0.5px), var(--ph-text) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.overlay-ph.video-mode {
	width: 72%;
	max-height: calc((100vh - var(--overlay-gap)) * 0.72);
	background: #000;
	overflow: hidden;
}

.overlay-ph.video-mode::before {
	display: none;
}

.overlay-ph.video-mode iframe {
	width: 100%;
	height: 100%;
	border: 0;
	display: block;
}

.overlay-ph.video-mode video {
	width: 100%;
	height: 100%;
	border: 0;
	display: block;
	object-fit: contain;
	background: transparent;
}

.overlay-ph.video-mode.fish-lens-mode {
	perspective: 900px;
	transform-style: preserve-3d;
	transform: none;
	transition: none;
	border-radius: 0;
	box-shadow: none;
}

.overlay-ph.video-mode.fish-lens-mode iframe,
.overlay-ph.video-mode.fish-lens-mode video {
	transform: translateZ(10px);
	transform-origin: center;
	transition: transform 120ms linear;
	filter: none;
	will-change: transform;
}

.overlay-ph.video-mode.fish-lens-mode video::-webkit-media-controls-panel {
	background-image: none;
	background-color: transparent;
}

.overlay-ph.video-mode.local-video-mode iframe,
.overlay-ph.video-mode.local-video-mode video {
	opacity: 0.85;
	filter: drop-shadow(0 0 40px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 80px rgba(0, 0, 0, 0.6));
}

.overlay-ph.video-mode.local-video-mode {
	background: transparent;
}

.overlay-ph.video-mode video::-webkit-media-controls-enclosure {
	border-radius: 0;
	background: transparent;
}

.overlay-ph.video-mode video::-webkit-media-controls-panel {
	background-image: none;
	background-color: transparent;
}

.overlay-ph.video-mode video::-webkit-media-controls-current-time-display,
.overlay-ph.video-mode video::-webkit-media-controls-time-remaining-display {
	-webkit-text-stroke: 0;
	text-shadow: none;
}

.overlay-ph.local-only-mode {
	width: auto;
	max-width: 80%;
	max-height: 80vh;
	background: transparent;
	overflow: visible;
}

.overlay-ph.local-only-mode::before {
	display: none;
}

.overlay-ph.local-only-mode video {
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 80vh;
	display: block;
	object-fit: contain;
	border: 0;
	background: transparent;
}

.overlay-ph.local-only-mode video::-webkit-media-controls-enclosure {
	border-radius: 0;
	background: transparent;
}

.overlay-ph.local-only-mode video::-webkit-media-controls-panel {
	background-image: none;
	background-color: transparent;
}

.overlay-ph.local-only-mode video::-webkit-media-controls-current-time-display,
.overlay-ph.local-only-mode video::-webkit-media-controls-time-remaining-display {
	-webkit-text-stroke: 0;
	text-shadow: none;
}

.overlay-video-link {
	position: absolute;
	right: 30px;
	top: 20px;
	width: 80px;
	height: 54px;
	border: 0;
	border-radius: 0;
	background-color: transparent;
	background-image: url('Assets/Logos/WhiteYTLogo.png');
	background-repeat: no-repeat;
	background-position: center;
	background-size: contain;
	font-size: 0;
	line-height: 0;
	text-indent: -9999px;
	overflow: hidden;
	text-decoration: none;
	z-index: 4;
	-webkit-text-stroke: 0;
	opacity: 0.85;
}

/* =========================
	Page Nav
	========================= */

.page-nav {
	position: fixed;
	top: calc(var(--frame-v-gap) + var(--nav-top));
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 6px;
	z-index: 6;
	pointer-events: none;
	filter: blur(0.4px);
}

.nav-btn {
	pointer-events: all;
	padding: 4px 10px;
	border: 1px solid #000000;
	background: rgba(255, 255, 255, 0.88);
	font-family: var(--font);
	font-size: 9px;
	font-weight: 900;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	cursor: pointer;
	color: #000000;
	text-decoration: none;
	display: inline-block;
	-webkit-text-stroke: 0;
	transition: background 0.15s, color 0.15s;
}

#infoBtn, #homeBtn {
	background: transparent !important;
	border: none !important;
	padding: 0 !important;
	width: auto;
	height: auto;
}

#infoBtn img {
	display: block;
	height: 5rem;
	width: auto;
	opacity: 0.8;
}

#homeBtn img {
	display: block;
	height: 6rem;
	width: auto;
	opacity: 0.9;
}

/* =========================
	INFO MODAL
	========================= */

.info-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.8);
    padding: 20px; /* Added padding to prevent image touching screen edges */
}

.info-modal.active {
    display: flex;
}

.info-modal-inner {
    position: relative;
    display: flex; /* Changed from inline-flex for better centering */
    justify-content: center;
    align-items: center;
    max-width: 100%;
    max-height: 100%;
    line-height: 0;
}

.info-modal-image {
    display: block;
    /* Use 'max' properties so it scales down on small screens 
       but maintains its aspect ratio */
    width: auto;
    height: auto;
    max-width: 98vw;  /* Cap width at 90% of screen */
    max-height: 92vh; /* Cap height at 80% of screen */
    object-fit: contain;
    filter: blur(0); /* Ensure the global blur doesn't make this unreadable */
}

/* Adjust for Mobile Devices */
@media (max-width: 768px) {
    .info-modal-image {
        max-width: 95vw;
        max-height: 70vh; /* Give more vertical breathing room on tall phones */
    }
}

/* Close button anchored to the actual image corners — not a letterbox gap */
/* .info-modal-close {
	position: absolute;
	top: 50px;
	right: 50px;
	padding: 0;
	border: none;
	background: transparent;
	cursor: pointer;
	z-index: 5;
	opacity: 0.75;
}

.info-modal-close img {
	width: 35px;
	height: 28px;
	display: block;
	opacity: 0.9;
} */

/* =========================
	Responsive
	========================= */

@media (min-width: 1400px) and (min-aspect-ratio: 16/9) {
	.page {
		width: calc((100vh * 16 / 9) * 0.75);
		max-width: 75vw;
	}

	.grid {
		grid-template-columns: repeat(7, minmax(0, 1fr));
		grid-auto-rows: clamp(150px, 22vh, 275px) !important;
		gap: 0 clamp(8px, 0.7vw, 15px);
	}
}

@media (min-width: 1400px) and (min-aspect-ratio: 16/9) and (max-height: 900px) {
	html,
	body {
		font-size: 10px;
		-webkit-text-stroke: 0.6px #000000;
	}

	.grid {
		grid-template-columns: repeat(6, minmax(0, 1fr));
	}

	.meta .name {
		font-size: 10px;
	}

	.meta .ref {
		font-size: 8px;
	}
}

@media (min-width: 1400px) and (min-aspect-ratio: 16/9) and (max-height: 760px) {
	html,
	body {
		font-size: 9px;
		-webkit-text-stroke: 0.5px #000000;
	}

	.grid {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}

	.meta .name {
		font-size: 9px;
	}

	.meta .ref {
		font-size: 7px;
	}
}

@media (min-width: 1025px) and (max-aspect-ratio: 16/9) {
	.page {
		width: calc(var(--frame-display-w) * 0.72);
	}

	.grid {
		grid-template-columns: repeat(7, minmax(0, 1fr));
		grid-auto-rows: clamp(130px, calc(var(--frame-display-h) * 0.2), 210px) !important;
		gap: 0 clamp(8px, 0.75vw, 12px);
	}
}

@media (min-width: 1025px) and (max-aspect-ratio: 4/3) {
	.page {
		width: calc(var(--frame-display-w) * 0.68);
	}

	.grid {
		grid-template-columns: repeat(5, minmax(0, 1fr));
		grid-auto-rows: clamp(115px, calc(var(--frame-display-h) * 0.18), 180px) !important;
	}
}

@media (min-width: 1025px) and (max-width: 1399px) and (max-height: 900px) {
	.grid {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}
}

@media (min-width: 1025px) and (max-width: 1399px) and (max-height: 760px) {
	.grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

@media (max-width: 1300px) {
	.grid {
		grid-template-columns: repeat(7, minmax(0,1fr));
		gap: 12px;
	}
}

@media (max-width: 1200px) {
	.grid { grid-template-columns: repeat(5, minmax(0,1fr)); }
}

@media (min-width: 769px) and (max-width: 1024px) {
    /* Keep your existing :root variables exactly as they were 
       to prevent the frame from moving */

    .grid {
		grid-auto-rows: 180px !important; 
        margin-bottom: 75px;
    }

    .page {
        /* Add extra invisible space at the bottom of the scrollable area 
           so the last row can be scrolled into the center of the frame */
        padding-bottom: 30vh !important; 
    }
}

@media (min-width: 769px) and (max-height: 900px) {
	.grid {
		grid-auto-rows: clamp(145px, 20vh, 240px) !important;
		gap: 0 clamp(6px, 0.65vw, 12px);
	}
}

@media (min-width: 769px) and (max-height: 760px) {
	.grid {
		grid-auto-rows: clamp(120px, 18vh, 190px) !important;
	}
}

@media (max-width: 900px) {
	.grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
}

@media (max-width: 800px) {
	.grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
}

@media (max-width: 769px) {
	.grid {
		grid-template-columns: repeat(3, minmax(0,1fr));
		width: 84%;
	}
}

@media (max-width: 768px) and (min-width: 680px) and (max-height: 700px) {
	:root {
		--grid-fit-width: 90vw;
	}

	.grid {
		width: 88%;
	}
}

@media (max-width: 768px) {
  :root {
    --frame-ratio: 0.5625;
    --frame-display-w: 100vw;
    --frame-display-h: 100vh;
    --grid-fit-width: 100vw;

    /* ===== SAFE AREA FIX (XR + SE consistent) ===== */
    --safe-top: env(safe-area-inset-top, 30px);
    --safe-bottom: env(safe-area-inset-bottom, 20px);

    /* NAV POSITIONING (more breathing room on SE) */
    --nav-top: calc(var(--safe-top) + clamp(16px, 4vh, 40px));
    --nav-h: 26px;

    /* HARD GAP between nav and grid (prevents overlap completely) */
    --nav-grid-gap: clamp(28px, 6vh, 60px);

    /* FINAL SAFE START FOR GRID */
    --frame-safe-y: calc(var(--nav-top) + var(--nav-h) + var(--nav-grid-gap));

    --frame-pad-x: clamp(3px, 1.1vw, 10px);
    --frame-pad-y: 10px;
  }

  /* NAV FIX */
  .page-nav {
    top: var(--nav-top) !important;
    transform: translateX(-50%);
    gap: 10px;
    padding: 6px 0;
  }

  /* Make nav buttons slightly less cramped on SE */
  .nav-btn {
    font-size: 10px;
    padding: 6px 12px;
  }

  #infoBtn img {
    height: 4.2rem;
  }

  #homeBtn img {
    height: 5.2rem;
  }

  /* PAGE LAYOUT */
  .page {
    padding-top: var(--frame-safe-y) !important;
    padding-bottom: calc(80px + var(--safe-bottom));
    width: var(--grid-fit-width);
    display: block;
  }

  /* GRID FIX */
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 140px !important;
    row-gap: 12px !important;
    width: 90%;
    margin: 0 auto;

    /* IMPORTANT: prevents visual "creeping upward" on small screens */
    perspective: 2000px;
    transform: none;
  }

  body::before { display: none; }

  html, body {
    font-size: 9px;
    -webkit-text-stroke: 0.55px #000000;
  }

  .page::after {
    background-image: url('Assets/Frames/Mobile.png');
    background-size: 100% 100%;
  }
}