/* ==========================
   GLOBAL RESET & BASE
=========================== */
:root{
  /* set by JS; defaults are safe */
  --fc-controls: 140px;
  --fc-ad: 0px;
}
body {
  font-family: 'Quicksand', sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f5f5f5;
}

/* ==========================
   FLASHCARD CONTAINER
=========================== */
#flashcard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
}

/* ==========================
   FLASHCARD STRUCTURE
=========================== */
.flashcard {
  width: 100%;
  max-width: 1024px;
  height: clamp(320px, 64svh, 720px);
  margin: 20px 0;
  position: relative;
  perspective: 1000px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 5px 12px rgba(0,0,0,.15);
  overflow: hidden; /* keep content inside rounded corners */
}

.flashcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .6s ease-in-out;
  min-width: 0;
}
.flashcard-inner.flipped { transform: rotateY(180deg); }

.flashcard-front,
.flashcard-back {
  position: absolute;
  inset: 0;
  padding: clamp(18px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;       /* default: center both ways */
  justify-content: center;
  backface-visibility: hidden;
  border-radius: 12px;
  overflow: auto;            /* scroll inside when tall */
  -webkit-overflow-scrolling: touch;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.6;
}
.flashcard-front { background:#fff; color:#000; }
.flashcard-back  { background:#e0e0e0; color:#000; transform: rotateY(180deg); }

/* If a face is overflowing, switch to top-left so it reads like a page */
#flashcard-container .flashcard-front.is-overflowing,
#flashcard-container .flashcard-back.is-overflowing{
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
}

/* ==========================
   QUESTION / ANSWER & IMAGE
=========================== */
.flashcard-question,
.flashcard-answer {
  width: 100%;
  margin: 0 0 12px 0;
  line-height: 1.55;
  font-size: clamp(18px, 3.2vw, 28px);
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  max-width: min(92%, 72ch);
  margin-inline: auto;
}
.flashcard-image { width: 100%; display:flex; justify-content:center; }
.flashcard-image img {
  width: 100%;
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,.08);
  display: block;
  margin: 8px auto 0;
}

/* ==========================
   CONTROLS
=========================== */
.controls,
.fc-controls {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 15px auto 0;
  flex-wrap: wrap;
  width: min(1000px, 92vw);
}
.controls button {
  background: #2c3e50;
  color: #fff;
  padding: 12px 24px;
  font-size: 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background .3s ease;
}
.controls button:hover { background:#34495e; }

/* Controls fixed & visible in fullscreen (native + CSS fallback) */
:fullscreen .controls,
:-webkit-full-screen .controls,
body.fc-fullscreen .controls,
body.fc-fullscreen .fc-controls {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: rgba(255,255,255,.95);
  padding: 12px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0,0,0,.2);
  bottom: calc(20px + var(--fc-ad, 0px)); /* sit above ad if present */
}

/* ==========================
   FULLSCREEN CENTERING
=========================== */
/* Center content and reserve space for controls + ad (native & fallback) */
:fullscreen #flashcard-container,
:-webkit-full-screen #flashcard-container,
body.fc-fullscreen #flashcard-container {
  min-height: calc(100dvh - (var(--fc-controls, 140px) + var(--fc-ad, 0px)));
  display: grid;
  place-items: center;
  padding: 20px 20px max(env(safe-area-inset-bottom), 20px);
}

/* Size the card and remove outside margins in fullscreen */
:fullscreen #flashcard-container .flashcard,
:-webkit-full-screen #flashcard-container .flashcard,
body.fc-fullscreen #flashcard-container .flashcard {
  margin: 0;
  width: min(1000px, 96vw);
  max-width: 100%;
  max-height: calc(100dvh - (var(--fc-controls, 160px) + var(--fc-ad, 0px)));
  height: min(
    clamp(360px, 76dvh, 860px),
    calc(100dvh - (var(--fc-controls, 160px) + var(--fc-ad, 0px)))
  );
}

/* Prevent page scroll behind CSS fullscreen */
body.fc-fullscreen { overflow: hidden; }

/* ==========================
   FULLSCREEN AD AT BOTTOM
=========================== */
.fc-ad-bottom{
  margin: 12px auto 0;
  width: min(1000px, 92vw);
}
:fullscreen .fc-ad-bottom,
:-webkit-full-screen .fc-ad-bottom,
body.fc-fullscreen .fc-ad-bottom{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: env(safe-area-inset-bottom);
  width: min(1000px, 96vw);
  z-index: 998; /* just below controls (999) */
}

/* ==========================
   SET & CATEGORY GRIDS
=========================== */
.flashcard-set-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px,1fr));
  gap: 24px;
  max-width: 1200px;
  margin: 30px auto;
  padding: 0 20px;
}
.flashcard-set-item {
  background:#fff; border:1px solid #ddd; border-radius:10px;
  padding:20px; text-align:center;
  box-shadow:0 4px 10px rgba(0,0,0,.08);
  transition: transform .2s ease, box-shadow .2s ease;
}
.flashcard-set-item:hover { transform: translateY(-5px); box-shadow:0 6px 16px rgba(0,0,0,.15); }
.flashcard-set-item h4 { font-size:16px; margin-bottom:10px; }
.view-set { background:#007BFF; color:#fff; padding:8px 16px; border-radius:6px; text-decoration:none; display:inline-block; margin-top:10px; }
.view-set:hover { background:#0056b3; }

.flashcard-category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px,1fr));
  gap: 24px;
  max-width: 1200px;
  margin: 30px auto;
  padding: 20px;
}
.flashcard-category-card {
  background:#fff; border:1px solid #e0e0e0; border-radius:10px; padding:20px; text-align:center;
  box-shadow:0 4px 10px rgba(0,0,0,.06);
  transition: transform .2s ease, box-shadow .2s ease;
}
.flashcard-category-card:hover { transform: translateY(-5px); box-shadow:0 6px 16px rgba(0,0,0,.12); }
.flashcard-category-card h3 { font-size:20px; margin-bottom:10px; }
.flashcard-category-card p { font-size:14px; color:#666; }

/* ==========================
   PAGINATION
=========================== */
.pagination ul {
  display: flex; gap: 10px; justify-content: center;
  list-style: none; padding: 0;
}
.pagination li a,
.pagination li span {
  padding: 8px 14px; font-size: 15px;
  border: 1px solid #007bff; color: #007bff;
  border-radius: 5px; text-decoration: none; transition: .3s;
}
.pagination li span.current,
.pagination li a:hover { background:#007bff; color:#fff; }

/* ==========================
   RESPONSIVE TWEAKS
=========================== */
@media (max-width: 768px) {
  .controls button { font-size: 14px; padding: 8px 16px; }
  .flashcard-set-grid { grid-template-columns: 1fr; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .flashcard-inner { transition: none; }
}
