/* ================================================================
   QOD OVERFLOW FIX  —  Prevents right-side content cutoff
   Load AFTER qodstyles.css, qod-responsive.css, and quiz-fixes.css
   ================================================================ */


/* ── 1. ROOT CAUSE: Container must never exceed its parent ────────
   The widget lives inside a WordPress content area that is narrower
   than the 1400px max-width. Force every layer to stay within the
   available paint width.                                           */

.app-container {
  max-width: 100%;
  width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* ── 2. GRID CHILDREN must be allowed to shrink below their content
   size. Without min-width:0, a grid/flex child never shrinks past
   its intrinsic content width, causing overflow.                   */

.main-content {
  min-width: 0;
  overflow: hidden; /* clip any stray child that still pokes out */
}

.left-column,
.right-column {
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
}

/* ── 3. MOOD FILTER: allow full scroll with no overflow ──────────
   The filter row has 7 buttons × min-width ≥ 64 px = 448 px+.
   On narrow pages this alone causes horizontal scroll.            */

.mood-filter-section {
  width: 100%;
  overflow: hidden;
}

.mood-filters {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: wrap;             /* wrap on desktop so buttons center */
  justify-content: center;     /* centered on desktop               */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.mood-filters::-webkit-scrollbar {
  display: none;
}

/* Keep buttons at a sane size but allow them to flex-shrink       */
.mood-btn {
  flex: 0 0 auto;
  min-width: 72px;
  max-width: 110px;
}

/* ── 4. ALL CARDS AND SECTIONS: prevent internal overflow ────────*/

.engagement-card,
.mood-tracker-card,
.week-quote-card,
.quick-library-card,
.quiz-trigger-card,
.quote-display-container,
.action-buttons,
.share-section {
  max-width: 100%;
  width: 100%;           /* stretch to fill the flex column        */
  box-sizing: border-box;
  overflow-x: hidden;
}

/* ── 4b. RIGHT COLUMN cards must fill 100% of column width ───────
   Flex children stretch by default only when align-items is
   stretch. Explicitly set it to be safe.                          */

.right-column {
  align-items: stretch;
}

.right-column > * {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* ── 4c. MOOD CHART — fix overflow and centering ─────────────────
   The chart container must clip its children; bars use min-width
   which can sum wider than the container on narrow screens.       */

.mood-tracker-card {
  width: 100%;
}

.mood-chart-container {
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.mood-chart {
  width: 100%;
  box-sizing: border-box;
  overflow: visible;        /* must NOT clip — the current-day dot  */
                            /* sits at top:-8px above the bar and   */
                            /* overflow:hidden cuts it off           */
}

/* Contain horizontal overflow at the container level instead      */
.mood-chart-container {
  overflow-x: hidden;
  overflow-y: visible;      /* allow dot to peek above chart area   */
}

/* Bars: remove the fixed min-width so they shrink with space      */
.mood-bar {
  min-width: 0 !important;
  flex: 1 1 0;
  max-width: 60px;
  overflow: visible;        /* allow ::after dot to render above bar */
}

/* The dot uses left:50% + translateX(-50%). The @keyframes must
   also carry translateX(-50%) or the dot drifts off-centre during
   the animation. Belt-and-suspenders: anchor with left+translate  */
.mood-bar.current-day::after {
  left: 50% !important;
  /* Use margin-left instead of transform for centering so the
     CSS animation's transform (scale) doesn't knock it off       */
  margin-left: -4px;          /* half of 8px dot width             */
  transform: none;
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.7;
  }
}

/* Mood selector: fill full width with equal-size buttons          */
.mood-selector {
  width: 100%;
  box-sizing: border-box;
}

.mood-option {
  flex: 1 1 0;
  min-width: 0;
}

/* Quiz chip row: wrap so chips never overflow                     */
.quiz-trigger-preview {
  flex-wrap: wrap;
  gap: 6px;
}

/* ── 5. IMAGES: always fit their container ───────────────────────*/

img {
  max-width: 100%;
  height: auto;
}

.quote-image {
  max-width: 100%;
  width: 100%;
  object-fit: cover;
}

/* ── 6. UTILITY / SHARE BUTTON GRIDS: use auto-fit so columns
   shrink when space is tight rather than overflowing              */

.utility-buttons,
.share-buttons {
  width: 100%;
  box-sizing: border-box;
}

/* ── 7. HISTORY GRID: prevent card overflow ─────────────────────*/

.history-grid {
  width: 100%;
  box-sizing: border-box;
}

.history-card {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* ── 8. ACHIEVEMENT GRID ─────────────────────────────────────────*/

.achievement-container,
.achievement-grid {
  width: 100%;
  box-sizing: border-box;
}

.achievement-item {
  min-width: 0;
}

/* ── 9. TEXT: stop long words/URLs from stretching containers ────*/

.quote-text-overlay,
.quote-text-card,
.quote-card-content,
.week-quote-text,
.did-you-know-fact,
.challenge-text,
.collection-name,
.achievement-name {
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

/* ── 10. WEEK QUOTE FULL-WIDTH SECTION ───────────────────────────*/

.quote-of-week-section,
.week-content {
  max-width: 100%;
  box-sizing: border-box;
}

/* ── 11. MODALS: ensure they don't widen the page ────────────────*/

.modal,
.quiz-modal-overlay {
  max-width: 100vw;
  overflow-x: hidden;
}

/* ── 12. TOAST CONTAINER ─────────────────────────────────────────*/

.toast-container {
  max-width: calc(100vw - 2rem);
}


/* ================================================================
   ASPECT RATIO FIX — Portrait/Landscape toggle on mobile
   
   qod-responsive.css @media (max-width: 479px) forces overlay-mode
   to aspect-ratio: 3/4 unconditionally — this overrides the JS
   toggle so switching to landscape has no visible effect on phones.
   
   Fix: explicitly restore the landscape ratio when .portrait is
   NOT present, with higher specificity to win the cascade.
   ================================================================ */

@media (max-width: 479px) {
  /* Landscape (no .portrait class) — restore 4:3 */
  .quote-display-container.overlay-mode:not(.portrait) {
    aspect-ratio: 4 / 3 !important;
  }

  /* Portrait — keep 3:4 */
  .quote-display-container.overlay-mode.portrait {
    aspect-ratio: 3 / 4 !important;
  }
}

/* Same fix for the 640px range where it's also set */
@media (max-width: 640px) {
  .quote-display-container.overlay-mode:not(.portrait) {
    aspect-ratio: 4 / 3;
  }
  .quote-display-container.overlay-mode.portrait {
    aspect-ratio: 3 / 4;
  }
}


/* ================================================================
   NARROW CONTEXT OVERRIDES
   These kick in when the widget is embedded inside a WordPress
   content column that is ≤ 700 px wide.
   ================================================================ */

@media (max-width: 700px) {

  /* Remove all horizontal padding so the widget uses every pixel  */
  .app-container {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Stack the two columns unconditionally ─────────────────────── */
  .main-content {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }

  /* Mood filter: switch to horizontal scroll on mobile            */
  .mood-filters {
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 4px;
    -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    mask-image: linear-gradient(to right, black 85%, transparent 100%);
  }

  /* Drop min-width so all 7 buttons fit with scroll as safety net */
  .mood-btn {
    min-width: 60px;
    padding: 0.4rem 0.35rem;
  }

  .mood-icon {
    font-size: 1.25rem;
  }

  .mood-label {
    font-size: 0.625rem;
  }

  /* Right column: always single column                            */
  .right-column {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
  }
}

@media (max-width: 480px) {

  .app-container {
    padding-left: 8px;
    padding-right: 8px;
  }

  /* Utility / share: 3 equal columns that actually fit            */
  .utility-buttons {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px;
  }

  .utility-btn {
    padding: 8px 4px;
    font-size: 0.6875rem;
  }

  .share-buttons {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px;
  }

  .share-btn {
    padding: 8px 4px;
    font-size: 0.625rem;
  }

  /* Mood filter buttons even tighter                              */
  .mood-btn {
    min-width: 52px;
    padding: 0.35rem 0.25rem;
  }

  /* Mood tracker scroll row                                       */
  .mood-selector {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .mood-selector::-webkit-scrollbar {
    display: none;
  }

  .mood-option {
    flex: 0 0 auto;
    min-width: 52px;
  }
}