/* Overlay / Detail View */
.r-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  visibility: hidden;
}

.r-overlay[aria-hidden="false"] {
  visibility: visible;
}

/* Backdrop */
.r-overlay__bg {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.95) 20%,
    rgba(255, 255, 255, 0) 70%
  );
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.r-overlay[aria-hidden="false"] .r-overlay__bg {
  opacity: 1;
}

/* Modal Content */
.r-modal {
  position: relative;
  width: 100%;
  max-width: 960px;
  height: 90vh;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.05);
  opacity: 0;
  transform: scale(0.96) translateY(10px);
  transition:
    transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.4s ease;
}

/* Use inner box-shadow for active border to prevent layout shift */
.r-modal.is-in-cart {
  box-shadow: 0 0 0 1.5px #000;
  border-color: transparent;
}

.r-overlay[aria-hidden="false"] .r-modal {
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* Ensure spacers are hidden by default (desktop) */
.r-modal::before,
.r-modal::after {
  display: none;
}

/* Modal Visual (Left) */
.r-modal__visual {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 40px 40px;
  position: relative;
  border-right: 1px solid rgba(0, 0, 0, 0.05);
}

.r-modal__img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  box-shadow: 10px 20px 40px rgba(0, 0, 0, 0.15);
  transform: rotate(-1deg);
}

.r-btn-cart-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  border: 1px solid #000;
  background: transparent;
  color: #000;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.r-btn-cart-toggle:hover {
  background: #000;
  color: #fff;
}

.r-btn-cart-toggle.is-in-cart {
  background: #f0f0f0;
  color: #333;
  border-color: #ddd;
}
.r-btn-cart-toggle.is-in-cart:hover {
  background: #e0e0e0;
  color: #000;
  border-color: #ccc;
}

/* Modal Info (Right) */
.r-modal__info {
  padding: 80px 40px 40px; /* Offset to clear absolute sticky bar (56px) */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}


/* ... existing styles ... */
/* FAB Cart Button (Inside Header) */
.r-fab-cart {
  width: 26px; 
  height: 26px;
  border-radius: 50%;
  border: 1px solid #000;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0.2, 1);
  color: #000;
  flex-shrink: 0;
  margin-left: 8px; /* Fixed gap when following notes button */
  margin-bottom: 8px; 
}

.r-fab-cart svg {
  width: 14px; 
  height: 14px;
  fill: currentColor;
  transition: transform 0.2s;
}

.r-fab-cart:hover {
  background: #000;
  color: #fff;
}

.r-fab-cart.is-in-cart {
  background: #000;
  color: #fff;
  border-color: #000;
}

/* FAB Notes Button (Eye Icon - Inside Header) */
.r-fab-notes {
  width: 26px; 
  height: 26px;
  border-radius: 50%;
  border: 1px solid #000;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0.2, 1);
  color: #000;
  flex-shrink: 0;
  margin-bottom: 8px; 
}

.r-fab-notes svg {
  width: 16px; 
  height: 16px;
  fill: currentColor;
  transition: transform 0.2s;
}

.r-fab-notes:hover {
  background: #000;
  color: #fff;
}

.r-fab-notes.is-active {
  background: #000;
  color: #fff;
  border-color: #000;
}

/* Modal Header Layout */
.r-modal__header {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.r-modal__notes-spacer {
  height: 120px;
  width: 100%;
}
.r-modal__title-row {
  display: flex;
  align-items: flex-end; /* Align icons with title baseline/bottom */
  margin-bottom: 8px;
}

.r-modal__title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.2;
  margin-right: 12px; /* Adding margin right to separate from FAB if text wraps */
}


/* Hide old controls */
.r-modal__bar-left {
  display: none;
}

/* Sticky Header Controls (Right Aligned, Info Left) */
.r-modal__sticky-bar {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between; 
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.85); 
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  z-index: 50;
  gap: 16px;
  overflow: hidden; /* For gradient overlap safety */
}
/* Info Text (Left) */
.r-modal__mini-info {
  font-size: 10px;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Default: show ellipsis on desktop */
  text-align: left; 
  flex-grow: 1; 
  margin-left: 10px; 
  margin-right: 10px;
  display: flex;
  align-items: center;
  height: 100%;
  position: relative;
}

.r-modal__mini-info span {
  display: inline-block;
}

/* Mobile-only scrolling animation */
@media (max-width: 800px) {
  .r-modal__mini-info.is-overflowing {
    text-overflow: clip;
  }
  
  .r-modal__mini-info.is-overflowing span {
    animation: marquee-scroll 10s ease-in-out infinite;
    animation-delay: 1.5s;
  }
  
  /* Text scrolls LEFT first (to show end), then RIGHT (back to start) */
  @keyframes marquee-scroll {
    0%, 15% {
      transform: translateX(0);
    }
    40%, 60% {
      transform: translateX(var(--scroll-distance, -50px));
    }
    85%, 100% {
      transform: translateX(0);
    }
  }
}

/* 
.r-modal[aria-hidden="false"] .r-modal__mini-info {
  opacity: 1;
  transform: translateY(0);
}
*/

/* Controls Container (Right) */
.r-modal__controls {
  display: flex;
  align-items: center;
  gap: 4px; 
  flex-shrink: 0;
  position: relative;
  background: transparent; 
  z-index: 5;
  padding-left: 20px; 
}

/* Gradient Mask on Controls Left */
.r-modal__controls::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40px; /* Width of fade */
  background: linear-gradient(to right, rgba(255,255,255,0), rgba(255,255,255,0.9) 50%, rgba(255,255,255,1));
  pointer-events: none;
  transform: translateX(-100%); /* Move left of padding */
  margin-left: 20px; /* Match padding offset */
}
/* Wait, sticking to padding-left method. simpler: 
   Gradient is INSIDE controls box at left edge. 
   Controls has bg? No. Sticky bar has bg. 
   But sticky bar bg is semi-transparent white.
   We need a gradient that matches the sticky bar's effective color. 
   Let's assume white for the fade.
 */

/* Re-thinking the Gradient: 
   The 'mini-info' is the one that needs to fade out. 
   But user asked for a "gradation box to the left of controls".
   So the controls container should have a pseudo element hitting its left side.
*/
/* Gradient Mask Removed */
/* Controls need to be on top of text */


/* Sticky Header Controls */
.r-modal__cart-text-controls {
  margin-right: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Reset Nav Buttons to previous style (borderless) */
.r-btn-text {
  background: transparent;
  border: none; 
  font-size: 13px; /* Reduced size as requested ("shrink controls") */
  font-weight: 500;
  color: #666;
  cursor: pointer;
  padding: 4px 6px; /* Reduced padding */
  border-radius: 4px;
  transition: all 0.2s;
  height: auto;
  display: block; 
}

.r-btn-text:hover {
  background: transparent;
  color: #1a1a1a;
}

.r-modal__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Responsive adjustment for FAB */
@media (max-width: 800px) {
  .r-fab-cart {
    position: static; /* Kept in header */
    width: 32px;
    height: 32px;
  }
  .r-fab-notes {
    position: static; /* Kept in header */
    width: 32px;
    height: 32px;
  }
}

.r-cart-text-btn {
  cursor: pointer;
  transition: color 0.2s;
  user-select: none;
}

.r-sep {
  color: #ccc;
  margin: 0 2px;
}

.r-mini-text {
  /* Existing mini info style logic */
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Button Specifics */

.r-btn-text[data-action="cart-add"],
.r-btn-text[data-action="cart-remove"] {
  width: 54px; /* Fixed width to prevent layout shift between bold/normal */
  text-align: center;
  transition: color 0.2s, font-weight 0s; /* Instant font-weight to match snap */
}

/* Default state (Not in Cart) */
/* Add is active (bold), Remove is disabled */
.r-modal:not(.is-in-cart) .r-btn-text[data-action="cart-add"] {
    color: #1a1a1a;
    font-weight: 700;
    pointer-events: auto;
}
.r-modal:not(.is-in-cart) .r-btn-text[data-action="cart-remove"] {
    color: #ccc;
    font-weight: 400;
    pointer-events: none;
}

/* In Cart state */
/* Remove is active (bold), Add is disabled */
.r-modal.is-in-cart .r-btn-text[data-action="cart-add"] {
    color: #ccc;
    font-weight: 400;
    pointer-events: none;
}
.r-modal.is-in-cart .r-btn-text[data-action="cart-remove"] {
    color: #1a1a1a;
    font-weight: 700;
    pointer-events: auto;
}

/* Hover state is handled globally for .r-btn-text */

/* Meta Info Layout */
.r-modal__sub-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 20px;
  font-size: 14px;
  color: #333;
  margin-top: 24px;
  font-weight: 500;
  line-height: 1.5;
}

.r-modal__author-text {
  text-align: left;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.r-modal__title {
  word-break: keep-all;
  overflow-wrap: break-word;
  margin: 0 0 8px 0;
  line-height: 1.3;
}

.r-modal__pub-text {
  text-align: right;
  color: #555;
  font-weight: 400;
}


/* Responsive (Mobile Stack) */
@media (max-width: 800px) {
  .r-modal {
    position: relative;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    max-height: 82dvh; /* Account for dynamic UI bars on mobile */
    max-height: 82vh;  /* Fallback */
    width: 86vw;
    border-radius: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling on iOS */
    display: block;
    margin: auto;
    background: #fff;
  }

  .r-modal__sticky-bar {
    position: sticky;
    top: 0;
    right: 0;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    width: 100%;
  }

  .r-modal__visual {
    background: #fff;
    padding: 40px 30px;
    border-right: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    overflow: visible; /* Prevent separate scroll context */
  }

  .r-modal__img {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  }

  .r-modal__info {
    padding: 24px;
    height: auto;
    overflow: visible; /* Reset desktop overflow-y: auto */
    max-height: none;  /* Reset desktop max-height: 90vh */
  }

  .r-modal__sub-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .r-modal__pub-text {
    text-align: left;
  }

  /* Bottom spacer using pseudo-element for reliable rendering */
  .r-modal__desc::after {
    content: "";
    display: block;
    height: 80px;
  }

}
