/* ============================================================
   Flashcards — shared mobile-first layout
   Loaded by every person's app; only the palette differs per
   person, via their own css/theme.css (loaded before this file).
   Designed for phones (iPhone Safari / Android Chrome): the whole
   practice UI fits one screen (100dvh) so nobody has to scroll to
   start. Larger screens are progressively enhanced at the bottom.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% 0%, var(--bg-tint) 0%, var(--bg) 55%);
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Jost', 'Inter', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ─── One-screen practice area ───────────── */
.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;   /* smallest viewport height: stays fixed as the mobile
                           browser bar hides/shows, so the card no longer
                           stretches/glitches while scrolling */
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
  gap: 10px;
}

/* Back to the student menu (flashcards page) */
.back-flash {
  align-self: flex-start;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 2px 0;
}
.back-flash span { font-weight: 600; }
.back-flash:active { opacity: 0.6; }

/* ─── Header ─────────────────────────────── */
.header { text-align: center; flex-shrink: 0; }
.header h1 {
  font-family: 'EB Garamond', 'PT Serif', serif;
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
  line-height: 1.15;
}
.header .sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-top: 3px;
}

/* Progress bar */
.prog-track {
  width: 100%;
  height: 5px;
  background: rgba(var(--ink-rgb), 0.09);
  border-radius: 99px;
  margin: 10px auto 8px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--front-1), var(--accent));
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* Compact stat chips */
.stats {
  display: flex;
  justify-content: center;
  gap: 7px;
}
.chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill, 999px);
  padding: 3px 10px;
  white-space: nowrap;
}
.chip b { font-weight: 700; }
.chip.k b { color: var(--known); }
.chip.l b { color: var(--learn); }
.chip.r b { color: var(--accent); }

/* Study-mode slider. A thumb slides under the active label; the
   container's data-mode drives both the slide and the label colour.
   inline-flex centres it inside the text-align:center header. */
.mode-toggle {
  position: relative;
  display: inline-flex;
  width: 264px;
  max-width: 100%;
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill, 999px);
  padding: 4px;
}
.mode-thumb {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  border-radius: calc(var(--r-pill, 999px) - 3px);  /* sits inside the track */
  background: var(--accent);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}
.mode-toggle[data-mode="def"] .mode-thumb { transform: translateX(100%); }
.mode-opt {
  position: relative;
  z-index: 1;
  flex: 1;
  border: none;
  background: transparent;
  border-radius: var(--r-pill, 999px);
  padding: 7px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.18s;
}
.mode-toggle[data-mode="word"] #modeWord,
.mode-toggle[data-mode="def"]  #modeDef { color: #fff; }

/* ─── Card scene (flexes to fill the screen) ─── */
.scene {
  flex: 1 1 auto;
  min-height: 190px;
  width: 100%;
  position: relative;
  perspective: 1200px;
  cursor: pointer;
  touch-action: pan-y;   /* horizontal swipes drive the cards, vertical still scrolls */
  -webkit-tap-highlight-color: transparent;
}

.card {
  position: absolute;
  inset: 0;          /* fill the flexed scene reliably */
  border-radius: var(--r-lg, 26px);
  box-shadow: var(--shadow);
  will-change: transform;   /* only slides (translateX); the flip lives on .card-inner */
}
/* Inner element does the 3D flip, so the stamp on .card never mirrors. */
.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.52s cubic-bezier(0.4, 0, 0.2, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg, 26px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 28px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Front (prompt) */
.front {
  background: linear-gradient(150deg, var(--front-1) 0%, var(--front-2) 100%);
}

.badge {
  position: absolute;
  top: 12px; left: 14px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #fff;
  background: rgba(255,255,255,0.19);
  padding: 4px 9px;
  border-radius: var(--r-pill, 999px);
}
.counter {
  position: absolute;
  top: 14px; right: 16px;
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  font-weight: 600;
}
/* Rating stamp — a single element on .card (outside the flipping
   .card-inner), so it travels with the card but never mirrors or doubles. ✓ sits bottom-left, ✗ bottom-right, each
   with its own tilt. Stamps in big when rated; shows statically on
   already-rated cards. */
.stamp {
  --tilt: -12deg;
  position: absolute;
  bottom: 12px; left: 14px;
  width: 36px; height: 36px;
  border: 2.5px solid currentColor;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; font-weight: 700;
  transform: rotate(var(--tilt));
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}
.stamp.known { color: var(--known); opacity: 0.9; }
.stamp.learn {
  --tilt: 12deg;
  color: var(--learn); opacity: 0.9;
  left: auto; right: 14px;
}
.stamp.animate { animation: stamp-in 0.32s cubic-bezier(0.2, 1.4, 0.5, 1) both; }
@keyframes stamp-in {
  0%   { transform: scale(2.6) rotate(calc(var(--tilt) * -0.6)); opacity: 0; }
  100% { transform: scale(1)   rotate(var(--tilt));              opacity: 0.9; }
}

/* ─── Face content slots ─────────────────────────────────────
   Either face can hold a word or a definition depending on the
   study mode. The *face* sets the colour (white on the gradient
   front, dark on the white back); the content *kind* (k-word /
   k-def) sets the font family + size scale; app.js picks the
   size step (s1–s4) from the text length. */
.face-primary { text-align: center; }
.front .face-primary { color: var(--on-front); }
.back  .face-primary { color: var(--ink); }

.face-primary.k-word { font-family: 'EB Garamond', 'PT Serif', serif; font-weight: 700; line-height: 1.18; }
.face-primary.k-def  { font-family: 'Jost', 'Inter', sans-serif; font-weight: 500; line-height: 1.26; }

/* word scale (short text, hero size) */
.k-word.s1 { font-size: clamp(38px, 11vw, 62px); }
.k-word.s2 { font-size: clamp(30px, 8.5vw, 46px); }
.k-word.s3 { font-size: clamp(24px, 6.5vw, 34px); }
.k-word.s4 { font-size: clamp(18px, 5vw, 24px); }
/* definition scale (longer text, calmer size) */
.k-def.s1 { font-size: clamp(26px, 8vw, 38px); }
.k-def.s2 { font-size: clamp(22px, 6.5vw, 30px); }
.k-def.s3 { font-size: clamp(18px, 5vw, 23px); }
.k-def.s4 { font-size: clamp(15px, 4.2vw, 18px); }

/* Secondary line under the primary — a translation cue or pronunciation.
   Hidden by app.js when empty. */
.face-secondary {
  margin-top: 10px;
  font-family: 'EB Garamond', 'PT Serif', serif;
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
}
.front .face-secondary { color: rgba(255,255,255,0.82); }
.back  .face-secondary { color: var(--ink-soft); }

/* Back (answer) — clean white */
.back {
  background: var(--surface);
  transform: rotateY(180deg);
  border: 1px solid var(--line);
}
.back .badge {
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.12);
}

/* Example sentence — under the translation, set off by a hairline.
   Hidden by app.js when a card has no `sentence`. */
.back-sentence {
  margin-top: 14px;
  padding-top: 12px;
  max-width: 280px;
  border-top: 1px solid var(--line);
  font-family: 'EB Garamond', 'PT Serif', serif;
  font-style: italic;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-soft);
  text-align: center;
}

/* ─── Nav controls (prev / next) ─────────────
   The card flips on tap/swipe, so there's no flip button — these two
   wide arrows are the tap alternative to swiping. */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.btn-nav {
  flex: 1;
  height: 52px;
  border-radius: var(--r-md, 16px);
  border: none;
  background: var(--surface);
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), 0.16);
}
.btn-nav:active:not(:disabled) { transform: scale(0.97); }
.btn-nav:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }

/* ─── Mark row (primary actions) ─────────── */
.mark-row {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.btn-mark {
  flex: 1;
  height: 48px;
  border-radius: var(--r-md, 14px);
  border: 2px solid;
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s;
}
.btn-mark:active { transform: scale(0.98); }
.btn-mark.known-btn { border-color: var(--known); color: var(--known); }
.btn-mark.known-btn.on { background: var(--known); color: #fff; }
.btn-mark.learn-btn { border-color: var(--learn); color: var(--learn); }
.btn-mark.learn-btn.on { background: var(--learn); color: #fff; }

/* ─── Util row (secondary) ───────────────── */
.util-row {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.btn-util {
  flex: 1;
  height: 38px;
  border-radius: var(--r-sm, 11px);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.btn-util:active { background: rgba(var(--accent-rgb), 0.09); }
.btn-util.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Done banner ────────────────────────── */
.done-banner {
  display: none;
  background: linear-gradient(135deg, var(--known), var(--known-2));
  color: #fff;
  border-radius: var(--r-md, 14px);
  padding: 12px 18px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  flex-shrink: 0;
}
.done-banner.show { display: block; }

/* ─── Keyboard hint (desktop only) ───────── */
.kb-hint { display: none; }
kbd {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: monospace;
  font-size: 10px;
}

/* ─── Deck selector (below the fold) ─────── */
.weeks {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 16px calc(40px + env(safe-area-inset-bottom));
}
.week-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 12px;
}
.week-bar {
  display: flex;
  flex-direction: column;   /* newest sits on top */
  align-items: center;
  gap: 8px;
}
.week-btn {
  width: 100%;
  max-width: 320px;
  padding: 12px 16px;
  border-radius: var(--r-md, 14px);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s;
}
.week-btn:active { transform: scale(0.98); }
.week-btn.active {
  background: linear-gradient(135deg, var(--front-1), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(var(--accent-rgb), 0.22);
}

/* ─── Desktop / larger screens ───────────── */
@media (min-width: 640px) {
  .screen {
    min-height: 0;
    margin-top: 24px;
    margin-bottom: 8px;
    gap: 12px;
  }
  .scene { min-height: 300px; height: 300px; flex: 0 0 300px; }
  .kb-hint {
    display: block;
    max-width: 460px;
    margin: 4px auto 0;
    font-size: 11px;
    color: var(--ink-soft);
    text-align: center;
    line-height: 2;
  }
}
