/* ============================================
   SPODIC - Reader Container & RSVP Display
   ============================================ */

.reader-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  animation: fadeIn 0.5s ease;
}

/* RSVP Display */
.rsvp-display {
  font-size: var(--rsvp-font-size);
  font-weight: var(--rsvp-font-weight, 500);
  font-family: var(--app-font-family, 'Inter', system-ui, sans-serif);
  letter-spacing: var(--rsvp-letter-spacing);
  line-height: 1;
  /* Position controls */
  position: absolute;
  top: calc(var(--word-position-y, 50%) + var(--word-offset-y, 0%));
  left: calc(50% + var(--position-x, 0%) + var(--word-offset-x, 0%));
  transform: translate(-50%, -50%);
  color: var(--word-color, var(--text));
  height: 1em;
  /* Lock height to prevent vertical jitter */
}

/* Inner container for main word - keeps ORP centered */
.rsvp-inner {
  display: grid;
  /* 1fr auto 1fr ensures the center column (ORP) is exactly in the middle of the screen */
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  height: 100%;
  /* Fill the fixed parent height */
}

/* Wrappers to align text against the ORP */
.side-wrapper {
  display: flex;
  min-width: 0;
  overflow: visible;
  /* Allow peripheral words to hang outside */
}

.left-wrapper {
  justify-content: flex-end;
  /* Push left text to the right (ORP) */
}

.right-wrapper {
  justify-content: flex-start;
  /* Push right text to the left (ORP) */
}

/* Shrink-wraps the text content to allow anchoring peripheral words to text edges */
.text-anchor {
  position: relative;
  display: block;
  /* Becomes flex item */
  height: 1em;
  /* Ensure stable height for vertical centering */
}

.segment {
  white-space: pre;
}

/* ============================================
   Word Transition Effects
   ============================================ */

/* Fade: words fade in */
[data-transition="fade"] .rsvp-display .segment {
  animation: rsvpFadeIn var(--transition-duration, 120ms) ease-out both;
}

/* Crossfade: slight overlap feeling via fade */
[data-transition="crossfade"] .rsvp-display .segment {
  animation: rsvpCrossfade var(--transition-duration, 120ms) ease-in-out both;
}

/* Blur: words start blurry and sharpen */
[data-transition="blur"] .rsvp-display .segment {
  animation: rsvpBlurIn var(--transition-duration, 120ms) ease-out both;
}

/* Scale: words start slightly small and grow */
[data-transition="scale"] .rsvp-display .rsvp-inner {
  animation: rsvpScaleIn var(--transition-duration, 120ms) ease-out both;
}

/* Slide: words slide up into position */
[data-transition="slide"] .rsvp-display .rsvp-inner {
  animation: rsvpSlideIn var(--transition-duration, 120ms) ease-out both;
}

/* No transition default (also handles "none") */
[data-transition="none"] .rsvp-display .segment,
[data-transition="none"] .rsvp-display .rsvp-inner {
  animation: none;
}

/* Performance hint */
[data-transition]:not([data-transition="none"]) .rsvp-display {
  will-change: opacity, transform, filter;
}

#left {
  text-align: right;
}

#orp {
  color: var(--orp-color);
  font-weight: var(--rsvp-orp-weight, 600);
  text-align: center;
  position: relative;
}

#right {
  text-align: left;
}

/* ORP disabled state */
[data-orp="false"] #orp {
  color: var(--text);
  font-weight: 500;
}

/* ============================================
   Punctuation Styling (Phase 5B)
   ============================================ */

/* Subtle punctuation style - slightly faded */
.punct-subtle {
  opacity: 0.65;
  font-size: 0.95em;
}

/* Optional: Punctuation style variants controlled by data attribute */
[data-punct-style="subtle"] .segment .punct-subtle {
  opacity: 0.6;
}

[data-punct-style="hidden"] .segment .punct-subtle {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Grouped phrases indicator (subtle background) */
.grouped-phrase {
  position: relative;
}

.grouped-phrase::before {
  content: '';
  position: absolute;
  inset: -0.1em -0.2em;
  background: var(--orp-color);
  opacity: 0.08;
  border-radius: 0.15em;
}

/* ============================================
   Guide Lines
   ============================================ */

.guide {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: var(--guide-thickness, 2px);
  height: var(--guide-length, 32px);
  background: var(--guide-color);
  transition: none;
}

.guide-top {
  top: calc(var(--word-position-y, 50%) + var(--word-offset-y, 0%) - var(--guide-gap, 24px));
  transform: translateX(-50%) translateY(-100%);
}

.guide-bottom {
  top: calc(var(--word-position-y, 50%) + var(--word-offset-y, 0%) + var(--guide-gap, 24px));
}

[data-guide="false"] .guide {
  opacity: 0;
}

/* ============================================
   Horizontal Guides (Phase 9)
   ============================================ */

.guide-horizontal {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  height: var(--guide-thickness, 2px);
  width: var(--guide-horizontal-coverage, 100%);
  background: var(--guide-color);

  /* Update 1: Default clip to respect the Left Nav Bar width (56px) */
  clip-path: inset(0 0 0 var(--nav-width, 56px));

  /* Mask out center where vertical guide overlaps to prevent double-alpha */
  -webkit-mask-image: linear-gradient(to right,
    black calc(50% - var(--guide-thickness, 2px) / 2),
    transparent calc(50% - var(--guide-thickness, 2px) / 2),
    transparent calc(50% + var(--guide-thickness, 2px) / 2),
    black calc(50% + var(--guide-thickness, 2px) / 2)
  );
  mask-image: linear-gradient(to right,
    black calc(50% - var(--guide-thickness, 2px) / 2),
    transparent calc(50% - var(--guide-thickness, 2px) / 2),
    transparent calc(50% + var(--guide-thickness, 2px) / 2),
    black calc(50% + var(--guide-thickness, 2px) / 2)
  );

  transition: none;
  pointer-events: none;
}

/* Update 2: When Left Nav is hidden (auto-closed), extend line to full width */
body:has(.left-nav.hidden) .guide-horizontal {
  clip-path: inset(0 0 0 0);
}

/* When sidebar is open, only clip left side to prevent overlap */
/* Preview may appear off-center, but line is correctly centered when sidebar closes */
body.sidebar-open .guide-horizontal {
  clip-path: inset(0 0 0 calc(326px + var(--nav-width, 56px)));
}

.guide-horizontal-top {
  top: calc(var(--word-position-y, 50%) + var(--word-offset-y, 0%) - var(--guide-gap, 24px) - var(--guide-length, 32px));
}

.guide-horizontal-bottom {
  top: calc(var(--word-position-y, 50%) + var(--word-offset-y, 0%) + var(--guide-gap, 24px) + var(--guide-length, 32px));
  transform: translateX(-50%) translateY(-100%);
}

[data-guide-horizontal="false"] .guide-horizontal {
  opacity: 0;
}

/* ============================================
   Peripheral Vision Words
   ============================================ */

.peripheral-word {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);

  font-size: calc(var(--rsvp-font-size) * var(--peripheral-size) / 100);
  font-weight: var(--rsvp-font-weight, 500);
  font-family: var(--app-font-family, 'Inter', system-ui, sans-serif);
  letter-spacing: var(--rsvp-letter-spacing);
  line-height: 1;
  color: var(--word-color, var(--text));
  opacity: var(--peripheral-opacity);
  white-space: nowrap;
  pointer-events: none;

  /* Hidden by default */
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

/* Previous word - bound to LEFT edge of main word (the text-anchor) */
.peripheral-prev {
  right: calc(100% + var(--peripheral-spacing));
  text-align: right;
}

/* Next word - bound to RIGHT edge of main word (the text-anchor) */
.peripheral-next {
  left: calc(100% + var(--peripheral-spacing));
  text-align: left;
}

/* Show when enabled via data attributes */
[data-peripheral-prev="true"] .peripheral-prev {
  visibility: visible;
}

[data-peripheral-next="true"] .peripheral-next {
  visibility: visible;
}

/* ============================================
   Spotlight Vignette
   ============================================ */

[data-spotlight="true"]::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  /* Radial gradient vignette centered on the word position */
  /* Softness controls where the transparent→dark transition starts:
     0% softness = instant dark edge, 100% = very gradual fade from center */
  background: radial-gradient(
    ellipse
      var(--spotlight-radius, 200px)
      var(--spotlight-radius, 200px)
    at 50% var(--word-position-y, 50%),
    transparent calc(var(--spotlight-softness, 50%) * 0.8),
    rgba(0, 0, 0, var(--spotlight-intensity-decimal, 0.4)) 100%
  );
  transition: opacity 0.3s ease;
}

/* Don't show spotlight overlay above sidebar or nav */
body.sidebar-open [data-spotlight="true"]::after {
  /* Keep it behind the sidebar */
}