﻿/* =========================
   PFC Layout (No-Scroll, Fit-to-Viewport)
   - Balanced safe-area padding (L/R)
   - Content shrink-wraps; no footer element
   - Button centered, ≤50% width on small screens
   - Images constrained inside cards
   - Page width limited for larger screens
   ========================= */

/* Tunables */
:root {
  --pfc-gap: 0.5rem;

  --pfc-font-min: 1.1rem;
  --pfc-font-max: 1rem;

  --pfc-img-maxw: 240px;
  --pfc-img-maxh-vh: 24vh;

  --pfc-card-size: 88px;
  --pfc-card-size-min: 72px;

  --pfc-grid-maxw: 220px;

  --pfc-actions-pad-v: 8px;
  --pfc-play-mt: 10px;

  --pfc-text-pad: 10px;        /* paragraph L/R padding */
  --pfc-feedback-pad-x: 10px;  /* feedback L/R padding */

  --pfc-btn-font-sm: 0.875rem;
  --pfc-btn-pad-sm-v: 0.35rem;
  --pfc-btn-pad-sm-h: 0.75rem;
}

/* ===== Page container (balanced safe area + width limit) ===== */
.pfc-page-container {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  background: #fff;

  /* Balanced safe-area on all edges */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);

  box-sizing: border-box;
  overflow: hidden; /* no scrolling */

  /* Limit overall width and center on wide devices */
  max-width: 480px;   /* adjust as desired */
  margin: 0 auto;
  width: 100%;
}

/* ===== Content (top-aligned, shrink-wrap; no extra side padding) ===== */
.pfc-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--pfc-gap);
  padding: 0.5rem 0;      /* vertical only; side padding handled by page container */
  text-align: center;
  width: 100%;
  flex: 0 auto;           /* shrink-wrap so it won’t push actions off-screen */
  box-sizing: border-box;
}

/* ===== Top Image ===== */
.pfc-top img {
  margin-top: 0.25rem;
  max-width: var(--pfc-img-maxw);
  max-height: var(--pfc-img-maxh-vh);
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

/* ===== Text Blocks ===== */
.pfc-paragraph,
.read-along-line,
.trigger-intro {
 font-size: clamp(var(--pfc-font-min), 1.6vh, var(--pfc-font-max));
 line-height: 1.32;
 margin: 0.25rem 0;
 word-break: keep-all;
 overflow-wrap: normal;
 white-space: normal;
 font-weight: 500; /*shannan added*/
}

/* Ensure paragraph text never clips at edges */
.pfc-paragraph,
.pfc-paragraph .read-along-line {
  padding-inline: var(--pfc-text-pad);
  max-width: 92vw;         /* keep within viewport width */
  box-sizing: border-box;
  overflow-wrap: break-word;
}

.trigger-intro {
  font-weight: 800;
  margin-top: 0.25rem;
}

/* ===== Cards Grid ===== */
.pfc-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--pfc-gap);
  width: 100%;
  max-width: var(--pfc-grid-maxw);
  margin: 0.4rem auto 0;
  justify-items: center;
}

.trigger-card-wrapper {
  position: relative;
  width: clamp(var(--pfc-card-size-min), 12vh, var(--pfc-card-size));
  height: clamp(var(--pfc-card-size-min), 12vh, var(--pfc-card-size));
  aspect-ratio: 1 / 1;    /* square */
  overflow: hidden;
}

.trigger-card {
  background: #000;
  padding: 0.4rem;        /* tight padding keeps images comfy */
  border: none;
  border-radius: 8px;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;       /* clip overflow */
  box-sizing: border-box;
}

.trigger-card img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;    /* contain within box */
  display: block;
}

.trigger-card:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Checkmark overlay */
.check-overlay {
  position: absolute;
  top: 4px;
  right: 4px;
  background-color: #28a745;
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  width: 20px;
  height: 20px;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  box-shadow: 0 0 4px rgba(0,0,0,0.2);
  pointer-events: none;
}

/* ===== Feedback ===== */
.feedback-area {
  background-color: #fff8e1;
  border: 1px solid #f1c40f;
  border-radius: 8px;
  padding: 0.6rem;
  margin: 0.6rem auto 0;

  width: min(420px, calc(92vw - (2 * var(--pfc-feedback-pad-x))));
  max-width: 92vw;
  padding-inline: var(--pfc-feedback-pad-x);

  text-align: center;
  font-size: clamp(0.8rem, 1.5vh, 0.95rem);
  display: flex;
  flex-direction: column;
  align-items: center;

  /* Keep fully on-screen vertically */
  max-height: 18vh;
  overflow: hidden;
  box-sizing: border-box;
}

.feedback-label {
  font-weight: 800;
  margin-bottom: 0.35rem;
  font-size: inherit;
}

/* Highlight style */
.highlighted {
  background-color: #e7f3ff;
  border-radius: 6px;
  transition: background-color 0.3s ease;
}

.trigger-explanation {
  text-align: center;
  margin: 0.5rem auto 0;
  font-size: clamp(0.8rem, 1.6vh, 0.95rem);
  max-width: 92vw;
}

/* ===== Actions (button area) ===== */
.pfc-actions {
  width: 100%;
  padding:
    var(--pfc-actions-pad-v)
    env(safe-area-inset-right)
    calc(var(--pfc-actions-pad-v) + env(safe-area-inset-bottom))
    env(safe-area-inset-left);
  box-sizing: border-box;

  display: flex;              /* center buttons inline */
  justify-content: center;
}



/* Small screens: cap button to 50% width (with a sensible minimum) */
@media (max-width: 480px) {
  .pfc-play-button {
    width: 50%;
    min-width: 120px;
  }
}

/* ===== Tight mode (optional helper) ===== */
.pfc-tight {
  --pfc-img-maxh-vh: 18vh;
  --pfc-card-size: 78px;
  --pfc-card-size-min: 66px;
  --pfc-gap: 0.35rem;
  --pfc-grid-maxw: 196px;
  --pfc-play-mt: 8px;
}

/* Ultra-short viewports: hide feedback if needed to guarantee fit */
@media (max-height: 580px) {
  .pfc-page-container.pfc-tight .feedback-area { display: none; }
}

.pfc-play-button.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none; /* keeps space but disables interaction */
}

.pfc-play-button.visible {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.3s ease;
}
