:root {
  /* Scale factor based on standard 67.75 cm canvas width */
  --cm: calc(100vw / 67.75);
  --cursor-x: 0px;
  --cursor-y: 0px;
}

@media (min-aspect-ratio: 6775/3800) {
  :root {
    /* Scale down if viewport aspect ratio is wider than 16:9 to prevent cutoff */
    --cm: calc(100vh / 38);
  }
}

/* Premium Typography System */
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #ffffff;
  color: #000000;
  font-family: "Microsoft New Tai Lue", "Outfit", "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* Hide default cursor on all elements to ensure custom cursor is used */
* {
  cursor: none !important;
}

/* Custom Circular Cursor */
#custom-cursor {
  width: calc(0.8 * var(--cm));
  height: calc(0.8 * var(--cm));
  background: #000000;
  border-radius: 50%;
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 10000;
  transform: translate3d(calc(var(--cursor-x) - 50%), calc(var(--cursor-y) - 50%), 0);
  transition: width 0.15s cubic-bezier(0.25, 1, 0.5, 1),
              height 0.15s cubic-bezier(0.25, 1, 0.5, 1),
              background-color 0.15s ease,
              border 0.15s ease;
}

#custom-cursor.hovering-project {
  width: calc(1.28 * var(--cm));
  height: calc(1.28 * var(--cm));
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Loading Bar (1mm progress indicator at top) */
#loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 1mm;
  background: #000000;
  width: 0%;
  z-index: 10001;
  transition: width 0.4s cubic-bezier(0.1, 0.8, 0.3, 1), opacity 0.3s ease;
}

/* SPA Sections */
section {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: none;
  opacity: 0;
  transition: opacity 0.6s cubic-bezier(0.25, 1, 0.5, 1);
  box-sizing: border-box;
}

section.active-page {
  display: block;
  opacity: 1;
}

/* ---------------------------------------------------- */
/* Page 1: Cover Page                                  */
/* ---------------------------------------------------- */
#page-cover {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ffffff;
}

.cover-content {
  width: calc(47.89 * var(--cm)); /* Exact width of the title block */
  margin-left: calc(9.93 * var(--cm)); /* Exact left margin */
  margin-right: calc(9.93 * var(--cm)); /* Exact right margin */
  display: flex;
  justify-content: center;
  align-items: center;
}

.cover-title {
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(7.48 * var(--cm)); /* Exact equivalent of 212pt (7.48cm) */
  font-weight: 700;
  color: #000000;
  display: flex;
  align-items: baseline;
  justify-content: center;
  margin: 0;
  white-space: nowrap;
  letter-spacing: -0.015em;
  cursor: pointer;
  transition: transform 0.4s ease;
}

.cover-title:hover {
  transform: scale(1.01);
}

.cover-title .part-o-letter {
  line-height: 1;
  display: inline-block;
}

.cover-title .part-o-dot {
  display: inline-block;
  width: calc(1.28 * var(--cm)); /* Exact dot diameter */
  height: calc(1.28 * var(--cm)); /* Exact dot diameter */
  background: #000000;
  border-radius: 50%;
  margin-left: calc(0.3 * var(--cm));
  margin-right: 0;
  transform: translateY(calc(-0.25 * var(--cm))); /* visually sits on baseline */
}

.cover-title .part-betancourt {
  margin-left: calc(2.92 * var(--cm)); /* Exact spacing dot to 'b' */
  line-height: 1;
  display: inline-block;
}

/* Tiny Home Button Style */
.home-link-fixed {
  position: fixed;
  top: calc(2.2 * var(--cm)); /* Aligned with back button */
  right: calc(3.12 * var(--cm)); /* Symetric to back button */
  font-family: "Inter", sans-serif;
  font-size: calc(0.5 * var(--cm)); /* Diminuto/Tiny */
  font-weight: 700;
  color: #000000;
  text-decoration: none;
  text-transform: lowercase;
  z-index: 960;
  transition: opacity 0.2s, transform 0.2s;
  opacity: 0;
  pointer-events: none;
  display: inline-block;
}

.home-link-fixed:hover {
  opacity: 0.6;
  transform: translateY(-1px);
}

/* Show home link on pages other than cover */
body:not(.on-cover-page) .home-link-fixed {
  opacity: 1;
  pointer-events: auto;
}


/* ---------------------------------------------------- */
/* Page 2: Carousel Page                               */
/* ---------------------------------------------------- */
#page-carousel {
  background: #ffffff;
  position: relative;
}

.carousel-container {
  width: 100%;
  height: calc(100vh - 2.21 * var(--cm));
  margin-top: calc(2.21 * var(--cm));
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.carousel-track-container {
  display: flex;
  flex-direction: column;
  gap: calc(2.4 * var(--cm));
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  transform-origin: center center;
  will-change: transform;
  width: auto;
  white-space: nowrap;
}

.carousel-row {
  display: flex;
  gap: calc(2.4 * var(--cm));
  will-change: transform;
}

.carousel-item {
  position: relative;
  width: calc(35.5 * var(--cm));
  height: calc(20 * var(--cm));
  overflow: hidden;
  background: #f0f0f0;
  flex-shrink: 0;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.carousel-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(100%);
  opacity: 0.9;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.carousel-item:hover img {
  filter: grayscale(100%);
  opacity: 1;
}

/* ---------------------------------------------------- */
/* Pages 3, 4, 5: Project Details Page                  */
/* ---------------------------------------------------- */
#page-project {
  background: #ffffff;
  overflow-y: auto;
  overflow-x: hidden;
}

.project-scroll-container {
  width: 100%;
  margin: 0 auto;
  position: relative;
  padding-top: calc(3.12 * var(--cm)); /* exact 3.12cm top margin */
  box-sizing: border-box;
}

/* Return Button */
.back-to-carousel {
  position: absolute;
  top: calc(1 * var(--cm)); /* positioned above content */
  left: calc(2.2 * var(--cm)); /* aligned with content left edge */
  background: transparent;
  border: none;
  color: #000000;
  font-family: "Inter", sans-serif;
  font-size: calc(0.5 * var(--cm));
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: calc(0.3 * var(--cm));
  cursor: pointer;
  padding: calc(0.3 * var(--cm)) calc(0.5 * var(--cm));
  border-radius: 4px;
  transition: background-color 0.2s;
  z-index: 10;
}

.back-to-carousel:hover {
  background-color: rgba(0,0,0,0.05);
}

.back-to-carousel svg {
  width: calc(0.7 * var(--cm));
  height: calc(0.7 * var(--cm));
}

/* Detail Section */
.project-section-detail {
  padding-left: calc(2.2 * var(--cm)); /* exact 2.2cm left margin */
  padding-right: calc(2.2 * var(--cm)); /* exact 2.2cm right margin */
  margin-bottom: 0;
}

.project-title {
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(1.41 * var(--cm)); /* Exact converted 40pt = 1.41cm */
  font-weight: 700;
  color: #000000;
  text-transform: uppercase;
  margin: 0 0 calc(1 * var(--cm)) 0; /* exact 1cm gap below title */
  line-height: 1;
}

.project-description {
  font-family: "Microsoft New Tai Lue", "Inter", sans-serif;
  font-size: calc(0.872 * var(--cm)); /* Exact converted 24.72pt = 0.872cm */
  color: #000000;
  text-align: justify;
  margin: 0 0 calc(3.77 * var(--cm)) 0; /* exact 3.77cm gap below description */
  line-height: 1.5;
  font-weight: 400;
}

/* Main Image Wrapper */
.project-image-main-wrap {
  width: 100%;
  max-width: 100%;
  height: calc(23.84 * var(--cm)); /* maintains exact design height */
  margin: 0 auto calc(2.24 * var(--cm)) auto; /* exact 2.24cm gap below main render */
  overflow: hidden;
  background: #f0f0f0;
}

.project-img-clickable {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease, filter 0.3s ease;
  cursor: pointer;
}

.project-img-clickable:hover {
  transform: scale(1.015);
  filter: brightness(1.05);
}

/* Double Renders Section */
.project-section-grid-double {
  margin-top: 0;
  margin-bottom: 0; /* space between double and triple is handled by triple's margin-top */
  width: 100%;
}

.project-image-double-wrap {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.project-image-double-wrap img {
  width: calc(50% - 1.05 * var(--cm)); /* exact 2.1cm gap in middle, touching left/right borders */
  height: auto;
  aspect-ratio: 32.72 / 18;
}

/* Triple Renders Section */
.project-section-grid-triple {
  margin-top: calc(2.1 * var(--cm)); /* exact 2.1cm vertical separation from double section */
  margin-bottom: calc(7.5 * var(--cm)); /* exact 7.5cm gap below triple renders */
  width: 100%;
}

.project-image-triple-wrap {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.project-image-triple-wrap img {
  width: calc(33.33% - 1.4 * var(--cm)); /* exact 2.1cm gaps in middle, touching left/right borders */
  height: auto;
  aspect-ratio: 21.17 / 25.42;
}

/* ---------------------------------------------------- */
/* Page 7: Contact Footer Section                       */
/* ---------------------------------------------------- */
#section-contact {
  width: 100%;
  height: calc(37.63 * var(--cm));
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: calc(2.17 * var(--cm));
  margin-top: calc(5 * var(--cm));
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.contact-isotopo-wrap {
  position: absolute;
  top: calc(15.52 * var(--cm));
  left: 50%;
  transform: translateX(-50%);
  height: calc(5.41 * var(--cm));
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-isotopo {
  display: flex;
  align-items: baseline;
  justify-content: center;
  position: relative;
  width: calc(6.98 * var(--cm));
  height: calc(5.41 * var(--cm));
}

.isotopo-letter {
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(7.48 * var(--cm)); /* Exact converted 212pt = 7.48cm */
  font-weight: 700;
  color: #000000;
  line-height: 0.75;
  user-select: none;
}

.isotopo-dot {
  width: calc(1.28 * var(--cm));
  height: calc(1.28 * var(--cm));
  background: #000000;
  border-radius: 50%;
  position: absolute;
  right: 0;
  bottom: calc(0.35 * var(--cm));
  transform-origin: center center;
  transition: transform 0.2s ease;
}

/* Isotopo dot animations */
@keyframes orbit-dot {
  0% {
    transform: rotate(0deg) translate(calc(2.5 * var(--cm))) rotate(0deg);
  }
  100% {
    transform: rotate(360deg) translate(calc(2.5 * var(--cm))) rotate(-360deg);
  }
}

@keyframes pulse-dot {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

/* Isotopo dot remains static and fixed */

/* Contact Links Bottom Row */
.contact-links-row {
  position: absolute;
  bottom: calc(2.17 * var(--cm));
  left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding-left: calc(2.52 * var(--cm));
  padding-right: calc(2.48 * var(--cm));
}

.contact-link-item {
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(0.705 * var(--cm)); /* Exact converted 20pt = 0.705cm */
  font-weight: 700;
  color: #000000;
  text-transform: lowercase;
  text-decoration: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  display: inline-block;
  white-space: nowrap;
}

.contact-link-item:hover {
  opacity: 0.5;
  transform: translateY(-2px);
}

#link-contact {
  width: calc(2.43 * var(--cm));
}

#link-gmail {
  width: calc(1.79 * var(--cm));
  margin-left: calc(27.97 * var(--cm));
}

#link-instagram {
  width: calc(3.26 * var(--cm));
  margin-left: calc(23.82 * var(--cm));
}

/* ---------------------------------------------------- */
/* Page 6: Render Detail Viewer Modal                   */
/* ---------------------------------------------------- */
#render-viewer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.98);
  display: none;
  z-index: 950;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

#render-viewer.active {
  display: flex;
  opacity: 1;
}

.viewer-content {
  width: calc(50 * var(--cm));
  height: calc(28.4 * var(--cm));
  background: #000000;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
  display: flex;
  justify-content: center;
  align-items: center;
}

.viewer-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 0.3s ease;
}

.viewer-content:active img {
  filter: brightness(0.9);
}

.viewer-caption {
  position: absolute;
  bottom: calc(-2 * var(--cm));
  left: 0;
  width: 100%;
  text-align: center;
  font-size: calc(0.55 * var(--cm));
  color: #666666;
  font-family: "Inter", sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.close-viewer {
  position: absolute;
  top: calc(2.2 * var(--cm));
  left: calc(3.12 * var(--cm));
  background: transparent;
  border: none;
  color: #000000;
  cursor: pointer;
  padding: calc(0.3 * var(--cm));
  z-index: 10;
  transition: transform 0.2s;
}

.close-viewer:hover {
  transform: scale(1.1);
}

.close-viewer svg {
  width: calc(0.8 * var(--cm));
  height: calc(0.8 * var(--cm));
}

/* ---------------------------------------------------- */
/* Global Fixed Shortcut Link to Contact               */
/* ---------------------------------------------------- */
.contact-link-fixed {
  position: fixed;
  bottom: calc(2.17 * var(--cm));
  right: calc(2.48 * var(--cm));
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(1.834 * var(--cm)); /* Exact converted 52pt = 1.834cm */
  font-weight: 700;
  color: rgba(0, 0, 0, 0.13);
  text-decoration: none;
  display: flex;
  align-items: baseline;
  z-index: 960; /* Higher than page-project and viewer modal */
  transition: color 0.3s ease, opacity 0.3s ease;
  line-height: 1;
}

.contact-link-fixed:hover {
  color: rgba(0, 0, 0, 0.6);
}

.contact-link-fixed .dot {
  display: inline-block;
  width: calc(0.32 * var(--cm)); /* 0.32 cm dot diameter */
  height: calc(0.32 * var(--cm));
  background: currentColor;
  border-radius: 50%;
  margin-left: calc(0.1 * var(--cm));
}

/* Hide fixed contact link on the cover page */
body.on-cover-page .contact-link-fixed {
  opacity: 0;
  pointer-events: none;
}

body:not(.on-cover-page) .contact-link-fixed {
  opacity: 1;
  pointer-events: auto;
}

/* Hide fixed elements on the contact footer itself when it's fully visible */
body.contact-visible .contact-link-fixed,
body.contact-visible .simulator-trigger-btn {
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------- */
/* Floating Simulator Trigger Button                    */
/* ---------------------------------------------------- */
.simulator-trigger-btn {
  position: fixed;
  bottom: calc(2.17 * var(--cm));
  left: calc(3.12 * var(--cm));
  font-family: "Microsoft New Tai Lue", "Outfit", sans-serif;
  font-size: calc(0.38 * var(--cm)); /* equivalent to around 10-11px */
  font-weight: 700;
  color: #ffffff;
  background: #000000;
  border: none;
  padding: calc(0.2 * var(--cm)) calc(0.5 * var(--cm));
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 2px;
  z-index: 10000; /* stays on top of content layers */
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: calc(0.15 * var(--cm));
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.3s ease, box-shadow 0.3s ease;
}

.simulator-trigger-btn:hover {
  transform: translateY(-2px);
  background-color: #222222;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

/* Hide simulator button on the cover page */
body.on-cover-page .simulator-trigger-btn {
  opacity: 0;
  pointer-events: none;
}

body:not(.on-cover-page) .simulator-trigger-btn {
  opacity: 1;
  pointer-events: auto;
}

/* Hide fixed contact link on the cover page */
body.on-cover-page .contact-link-fixed {
  opacity: 0;
  pointer-events: none;
}

body:not(.on-cover-page) .contact-link-fixed {
  opacity: 1;
  pointer-events: auto;
}

/* ---------------------------------------------------- */
/* Mobile Responsive Optimization (max-width: 768px)   */
/* ---------------------------------------------------- */
@media (max-width: 768px) {
  /* Restore default cursor behavior for touches and hide custom cursor dot on mobile */
  body {
    cursor: auto;
  }
  * {
    cursor: auto !important;
  }
  #custom-cursor {
    display: none !important;
  }

  /* Hide simulator button completely on mobile devices */
  .simulator-trigger-btn {
    display: none !important;
  }

  /* Cover page mobile adjustments with local scale to fit logo horizontally */
  #page-cover {
    --cm: calc(100vw / 55);
  }

  .cover-content {
    width: 95%;
    margin: 0 auto;
  }

  /* Carousel layout for mobile viewports with local scale */
  #page-carousel {
    --cm: calc(100vw / 37.5);
  }

  .carousel-track-container {
    gap: calc(3.5 * var(--cm));
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
  }

  .carousel-row {
    gap: calc(3.5 * var(--cm));
  }

  .carousel-item {
    width: calc(30 * var(--cm));
    height: calc(18 * var(--cm));
  }

  /* Project page layout scaling for readability and spacing */
  #page-project {
    --cm: calc(100vw / 22);
  }

  /* Distribute contact footer links nicely without breaking/overflowing */
  .contact-links-row {
    padding-left: calc(2.2 * var(--cm)) !important;
    padding-right: calc(2.2 * var(--cm)) !important;
    justify-content: space-between !important;
  }

  .contact-link-item {
    width: auto !important;
    margin-left: 0 !important;
    font-size: calc(1.1 * var(--cm)) !important;
  }

  /* Adjust contact footer layout height */
  #section-contact {
    height: calc(35 * var(--cm)) !important;
    margin-top: calc(3 * var(--cm)) !important;
  }

  .contact-isotopo-wrap {
    top: calc(12 * var(--cm)) !important;
  }

  /* Responsive render viewer modal for mobile */
  #render-viewer {
    --cm: calc(100vw / 22);
  }

  .viewer-content {
    width: 90vw !important;
    height: calc(90vw * (18 / 32.72)) !important;
  }

  .viewer-caption {
    font-size: calc(0.8 * var(--cm)) !important;
    bottom: calc(-3 * var(--cm)) !important;
  }

  .close-viewer {
    top: calc(2 * var(--cm)) !important;
    left: calc(2 * var(--cm)) !important;
  }

  /* Fixed control badges/buttons resizing for readability on mobile screens */
  .contact-link-fixed {
    --cm: calc(100vw / 22);
    font-size: calc(2.5 * var(--cm)) !important;
    bottom: calc(2 * var(--cm)) !important;
    right: calc(2 * var(--cm)) !important;
  }

  .home-link-fixed {
    --cm: calc(100vw / 22);
    font-size: calc(0.9 * var(--cm)) !important;
    top: calc(2 * var(--cm)) !important;
    right: calc(2 * var(--cm)) !important;
  }

  .back-to-carousel {
    font-size: calc(0.9 * var(--cm)) !important;
    top: calc(1.5 * var(--cm)) !important;
    left: calc(2.2 * var(--cm)) !important;
  }
}
