/* The card is a single piece of paper; all study UI lives outside its two faces. */
.flashcard-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.flashcard-wrapper {
  --card-radius: 10px;
  --turn-duration: 720ms;
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 5;
  min-height: 300px;
  perspective: 1600px;
  perspective-origin: 50% 45%;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  isolation: isolate;
}

/* A stationary contact shadow anchors the turning card to the surface. */
.flashcard-wrapper::before {
  content: '';
  position: absolute;
  inset: 24px 18px -12px;
  background: rgba(45, 39, 29, 0.12);
  border-radius: 50%;
  filter: blur(18px);
  pointer-events: none;
  z-index: -1;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform var(--turn-duration) cubic-bezier(0.45, 0.03, 0.25, 1);
}

.flashcard-wrapper.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

/* The core and slightly separated faces give the paper an edge as it turns. */
.flashcard-inner::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  background: #ded9cf;
  border: 1px solid #d4cec3;
}

.card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 38px 44px;
  border: 1px solid #e0dcd3;
  border-radius: var(--card-radius);
  background: linear-gradient(145deg, #fffefa 0%, #fdfcf8 65%, #f6f3ec 100%);
  box-shadow: 0 1px 1px rgba(56, 46, 29, 0.12), 0 7px 16px -7px rgba(56, 46, 29, 0.18), 0 22px 38px -24px rgba(56, 46, 29, 0.28), inset 0 1px 0 #fff;
  box-sizing: border-box;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(1px);
  overflow: hidden;
}

.card-face-back {
  transform: rotateY(180deg) translateZ(1px);
}

/* Light falls across the paper as it lifts, rather than turning like a flat panel. */
.card-face::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(105deg, rgba(46, 37, 22, 0.16), transparent 50%, rgba(255, 255, 255, 0.5));
  opacity: 0;
  pointer-events: none;
}

.flashcard-wrapper.turning { animation: card-lift var(--turn-duration) ease-in-out; }
.flashcard-wrapper.turning::before { animation: card-shadow var(--turn-duration) ease-in-out; }
.flashcard-wrapper.turning .card-face::after { animation: card-light var(--turn-duration) ease-in-out; }

@keyframes card-lift {
  0%, 100% { transform: translateY(0) rotateZ(0); }
  45% { transform: translateY(-12px) rotateZ(-0.6deg); }
}
@keyframes card-shadow {
  0%, 100% { opacity: 1; transform: scaleX(1); }
  45% { opacity: 0.45; transform: scaleX(0.65) translateY(12px); }
}
@keyframes card-light {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

.card-body {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.card-text {
  --card-min-font: 18px;
  width: 100%;
  min-width: 0;
  margin: 0;
  color: #292b30;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.ancient-text { font-size: 64px; line-height: 1.4; }
.ancient-text.script-hebrew { font-size: 72px; }
.script-greek { font-family: var(--font-greek); }
.script-hebrew { font-family: var(--font-hebrew); direction: rtl; }
.verse-text { --card-min-font: 16px; font-size: 28px; line-height: 1.65; }
.verse-text:not(.script-greek):not(.script-hebrew) { font-family: Georgia, 'Times New Roman', serif; }
.answer-title { font-size: 38px; line-height: 1.4; font-weight: 600; letter-spacing: -0.025em; }

/* Context, actions, and the turn cue sit below the paper. */
.card-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 24px;
}
.card-context-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.card-tag { font-size: 12px; font-weight: 600; color: #475569; }
.card-counter { font-size: 12px; color: #64748b; font-variant-numeric: tabular-nums; }
.card-status { font-size: 11px; color: #64748b; text-transform: capitalize; }
.card-actions-top { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #64748b;
  border: 1px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: #f1f5f9; color: #0f172a; }
.icon-btn.starred { color: #b45309; background: #fffbeb; border-color: #fde68a; }
.card-study-cue {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.6;
  color: #64748b;
}
.flip-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 6px 0;
  background: transparent;
  font-size: 12px;
  color: #475569;
  font-weight: 600;
  cursor: pointer;
}
.flip-hint:hover { color: var(--primary); }

.card-support { width: 100%; margin-top: 24px; text-align: left; font-size: 14px; line-height: 1.65; color: #475569; }
.card-support:empty { display: none; }
.card-reading-aids { display: grid; gap: 8px; }
.card-reading-aids:empty { display: none; }
.reading-aid { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.reading-aid .label, .detail-cell .label { font-size: 11px; font-weight: 600; color: #64748b; }
.transliteration-badge { font-style: italic; overflow-wrap: anywhere; }
.passage-reference { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.passage-reference span { font-size: 12px; font-weight: 400; color: #64748b; }
.card-answer-details { padding-top: 20px; margin-top: 20px; border-top: 1px solid #e2e8f0; }
.study-details-title { font-size: 13px; font-weight: 700; color: #334155; margin-bottom: 14px; }
.alphabet-details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; margin-bottom: 18px; }
.detail-cell .value { font-size: 14px; color: #334155; overflow-wrap: anywhere; }
.detail-cell .value.script-hebrew, .detail-cell .value.script-greek { font-size: 20px; }
.definition-box { margin-bottom: 16px; }
.definition-box h4 { font-size: 12px; font-weight: 600; color: #64748b; margin-bottom: 4px; }
.kjv-verse-quote { margin: 16px 0; padding-left: 16px; border-left: 2px solid #d4cec3; font-family: Georgia, 'Times New Roman', serif; color: #475569; }
.kjv-tag { display: block; margin-bottom: 6px; font-family: var(--font-sans); font-size: 11px; font-weight: 600; color: #64748b; }
.interlinear-wrapper { width: 100%; margin-bottom: 18px; }
.interlinear-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 12px; text-align: left; }
.interlinear-table caption { text-align: left; padding-bottom: 8px; font-size: 12px; font-weight: 600; color: #64748b; }
.interlinear-table th { padding: 10px 8px; border-bottom: 1px solid #cbd5e1; font-weight: 600; color: #475569; }
.interlinear-table td { padding: 10px 8px; border-bottom: 1px solid #e2e8f0; overflow-wrap: anywhere; }
.interlinear-table tr:last-child td { border-bottom: none; }
.interlinear-greek { font-family: var(--font-greek); font-size: 18px; color: #334155; }
.interlinear-hebrew { font-family: var(--font-hebrew); font-size: 20px; color: #334155; direction: rtl; }
.interlinear-translit { font-style: italic; color: #64748b; }

.study-controls { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-top: 20px; }
.rating-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 10px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.rating-btn .main-label { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.rating-btn .sub-label { font-size: 11px; color: #64748b; }
.rating-btn.btn-hard { border-color: #fecaca; color: #b91c1c; }
.rating-btn.btn-hard:hover { background: #fef2f2; }
.rating-btn.btn-good { border-color: #bae6fd; color: #0284c7; }
.rating-btn.btn-good:hover { background: #f0f9ff; }
.rating-btn.btn-easy { border-color: #bbf7d0; color: #15803d; }
.rating-btn.btn-easy:hover { background: #f0fdf4; }
.rating-btn:active:enabled { transform: translateY(1px); }
.rating-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.rating-btn:disabled:hover { background: #fff; }
.grade-hint { margin-top: 10px; font-size: 12px; line-height: 1.6; color: #64748b; text-align: center; }
.study-nav-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; margin-top: 18px; }
.shortcut-tips { font-size: 11px; color: #64748b; display: flex; align-items: center; gap: 8px; }
.key-badge { background: #e9edf2; color: #64748b; padding: 2px 5px; border-radius: 4px; font-size: 10px; font-family: monospace; }

/* Preserve the question-only reset when moving on from a turned card. */
.flashcard-wrapper.no-flip-transition .flashcard-inner { transition: none; }
.flashcard-wrapper:focus { outline: none; }
.flashcard-wrapper:focus-visible { outline: 3px solid var(--border-focus, #3b82f6); outline-offset: 6px; border-radius: var(--card-radius); }
.icon-btn:focus-visible, .flip-hint:focus-visible { outline: 2px solid var(--border-focus, #3b82f6); outline-offset: 3px; }
.flashcard-stage [hidden], .demo-card-container [hidden] { display: none !important; }

@media (max-width: 640px) {
  .flashcard-wrapper { aspect-ratio: 6 / 5; min-height: 280px; perspective: 1000px; }
  .card-face { padding: 26px 24px; }
  .ancient-text { font-size: 52px; }
  .ancient-text.script-hebrew { font-size: 60px; }
  .verse-text { font-size: 24px; }
  .answer-title { font-size: 30px; }
  .card-context { gap: 8px; margin-top: 20px; }
  .card-context-meta { gap: 4px 10px; }
  .card-status { display: none; }
  .card-study-cue { flex-wrap: wrap; gap: 2px 12px; }
  .study-controls { gap: 8px; margin-top: 16px; }
  .rating-btn { padding: 12px 5px; }
  .rating-btn .main-label { font-size: 12px; }
  .rating-btn .sub-label { font-size: 10px; }
  .shortcut-tips { display: none; }
  .alphabet-details-grid { gap: 14px; }
  .interlinear-table th, .interlinear-table td { padding: 8px 4px; }
}

@media (prefers-reduced-motion: reduce) {
  /* Keep the essential front-to-back turn visible; omit the decorative movement. */
  .flashcard-wrapper { --turn-duration: 480ms; }
  .flashcard-wrapper.turning, .flashcard-wrapper.turning::before, .flashcard-wrapper.turning .card-face::after { animation: none; }
}
