/* Study mode — mobile-first single-card review surface.
 * Scoped to /study/<slug>; nothing here leaks into /preview. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #f5f3ef;
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #1a1a1a;
  /* Defeat iOS pull-to-refresh that would otherwise eat downward swipes. */
  overscroll-behavior: contain;
  /* Prevent iOS rubber-band scroll past page edges. */
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  /* 100dvh handles iOS URL-bar collapse; 100vh is the fallback. */
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Top bar ─────────────────────────────────────────────────── */
.study-top {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  height: 48px;
  padding: 0 8px;
  background: white;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
.study-back {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  width: 44px;
  font-size: 1.4rem;
  text-decoration: none;
  color: #4a4a4a;
  border-radius: 8px;
}
.study-back:active { background: rgba(0, 0, 0, 0.06); }
.study-title {
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  overflow: hidden;
}
.study-anime {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.study-counter {
  font-size: 0.75rem;
  color: #777;
  margin-top: 2px;
}

/* ── Card stage ──────────────────────────────────────────────── */
.study-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.study-card-stack {
  position: relative;
  width: 100%;
  max-width: 480px;
  /* Definite height — sidesteps the "percentage of indeterminate flex
     parent" trap. Sized to fill the viewport minus top bar (48), footer
     (~80), and stage padding (32), capped at 600px on tall screens. */
  height: min(calc(100vh - 160px), 600px);  /* fallback for older Safari */
  height: min(calc(100dvh - 160px), 600px);
}

.study-card {
  position: absolute;
  inset: 0;
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.06);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* GPU-accelerated transform; layer promotion. */
  will-change: transform;
  transform: translate3d(0, 0, 0);
  /* Vertical scroll passes through; horizontal owned by us. */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.study-card.is-dragging { cursor: grabbing; }
.study-card.is-springing {
  /* Slight overshoot on release-without-commit; "lands like a spring". */
  transition: transform 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.study-card.is-committing {
  /* Ease-out as it flies off. */
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
.study-card.is-entering {
  /* Next card slides up from below. */
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tint overlays — fade in as drag progresses. JS sets the opacity vars. */
.study-card::before,
.study-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  transition: opacity 80ms linear;
}
.study-card::before {
  background: linear-gradient(90deg, rgba(217, 83, 79, 0.55), rgba(217, 83, 79, 0));
  opacity: var(--_hard-opacity, 0);
}
.study-card::after {
  background: linear-gradient(270deg, rgba(92, 184, 92, 0.55), rgba(92, 184, 92, 0));
  opacity: var(--_easy-opacity, 0);
}

/* Drag-direction labels. Visible only past 20% threshold. */
.study-card-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 80ms linear;
  z-index: 2;
}
.study-card-label.label-hard {
  left: 16px;
  color: #d9534f;
  border: 3px solid #d9534f;
}
.study-card-label.label-easy {
  right: 16px;
  color: #5cb85c;
  border: 3px solid #5cb85c;
}

/* Inner card content — wraps the front_html / back_html injected by study.js */
.study-card-body {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.1rem;
  overflow-y: auto;
  position: relative;
  z-index: 1;
}

/* Existing pv-* content classes from preview.py — restyle for study mode. */
.study-card .pv-front {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.study-card .pv-front-sentence {
  font-size: 1.05rem;
  color: #444;
  line-height: 1.5;
}
.study-card .pv-front-sentence mark {
  background: #fff7a8;
  padding: 0 2px;
  border-radius: 2px;
}
.study-card .pv-front-word {
  font-size: 2.4rem;
  font-weight: 700;
  margin-top: 8px;
}
.study-card .pv-front-audio {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.study-card .pv-front-prompt {
  font-size: 0.9rem;
  color: #888;
}
.study-card .pv-front-audio-btns {
  display: flex;
  gap: 12px;
}
.study-card .pv-front-audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
}
.study-card .pv-back { width: 100%; }
.study-card .pv-answer { margin-bottom: 12px; }
.study-card .pv-word { font-size: 2rem; font-weight: 700; }
.study-card .pv-reading { font-size: 1rem; color: #777; margin-top: 4px; }
.study-card .pv-meaning { font-size: 1.15rem; margin-top: 12px; color: #1a1a1a; }
.study-card .pv-translation {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(103, 80, 164, 0.06);
  border-radius: 6px;
  color: #555;
  font-size: 0.95rem;
  font-style: italic;
}

/* ── Empty state (all caught up) ─────────────────────────────── */
.study-empty-state {
  text-align: center;
  padding: 32px 16px;
}
.study-empty-state p { margin: 8px 0; font-size: 1.1rem; }
.study-empty-state .study-empty-eta { color: #777; font-size: 0.95rem; }

/* ── Footer with HARD / EASY buttons ─────────────────────────── */
.study-footer {
  display: flex;
  gap: 12px;
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  background: white;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
.study-grade {
  flex: 1;
  min-height: 56px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: filter 100ms ease, transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
}
.study-grade:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.study-hard { background: #d9534f; color: white; }
.study-easy { background: #5cb85c; color: white; }
.study-grade:not(:disabled):active {
  filter: brightness(1.1);
  transform: scale(0.98);
}

/* ── Toast ───────────────────────────────────────────────────── */
.study-toast-region {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
}
.study-toast {
  background: rgba(0, 0, 0, 0.88);
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.study-toast button {
  background: transparent;
  color: #b3d8ff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 4px 8px;
}

/* ── "Deck not found" empty state ────────────────────────────── */
.study-empty {
  text-align: center;
  padding: 64px 16px;
  margin: 0 auto;
  max-width: 420px;
}
.study-btn-primary {
  display: inline-block;
  padding: 12px 24px;
  background: #6750a4;
  color: white;
  text-decoration: none;
  border-radius: 10px;
  font-weight: 600;
  margin-top: 24px;
}

/* ── Larger screens: keep the card centered, don't full-width ── */
@media (min-width: 600px) {
  .study-card-stack { max-height: 560px; }
}
