/* Flashcards Mini App. Colors come from Telegram theme variables
   (--tg-theme-*, set by telegram-web-app.js) with neutral fallbacks. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--card));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --again: #e5484d;
  --hard: #f5a524;
  --good: #30a46c;
  --easy: #2481cc;
  --radius: 22px;
  --safe-top: var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
[hidden] { display: none !important; }
.muted { color: var(--hint); }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  height: var(--tg-viewport-stable-height, 100vh);
  padding: calc(10px + var(--safe-top)) 16px calc(14px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.top { display: flex; align-items: center; gap: 10px; min-height: 22px; }
.progress { flex: 1; height: 6px; border-radius: 3px; background: var(--card); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.counter { font-size: 13px; color: var(--hint); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.center { align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 0 12px; }
.center h1 { font-size: 22px; margin: 4px 0; }
.big-emoji { font-size: 56px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--card); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage { position: relative; flex: 1; display: flex; padding: 14px 0; min-height: 260px; perspective: 1400px; }
.card {
  position: relative; flex: 1; outline: none; cursor: pointer;
  touch-action: none; will-change: transform;
  transition: transform .25s ease;
}
.card.dragging { transition: none; }
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2,.7,.2,1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: var(--radius);
  background: var(--section);
  box-shadow: 0 6px 24px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 26px 22px; text-align: center; gap: 10px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.back { transform: rotateY(180deg); }
.badge {
  position: absolute; top: 14px; left: 16px;
  font-size: 12px; color: var(--hint); letter-spacing: .02em;
}
.hint { margin: 0; color: var(--hint); font-size: 14px; }
.phrase { margin: 0; font-size: clamp(22px, 6.5vw, 32px); font-weight: 600; line-height: 1.25; word-break: break-word; }
.phrase[dir="rtl"] { font-size: clamp(24px, 7vw, 34px); }
.translation { margin: 0; font-size: 19px; }
.word, .pattern { margin: 0; font-size: 14px; }
.tap { position: absolute; bottom: 14px; left: 0; right: 0; margin: 0; font-size: 12px; }
.audio {
  border: 0; background: var(--card); color: var(--text);
  width: 48px; height: 48px; border-radius: 50%; font-size: 22px; cursor: pointer;
}
.audio:active { transform: scale(.94); }
.audio.playing { background: var(--accent); color: var(--accent-text); }

.swipe-label {
  position: absolute; top: 40px; padding: 6px 12px; border-radius: 10px;
  font-weight: 700; font-size: 15px; opacity: 0; pointer-events: none;
  border: 2px solid currentColor; transition: opacity .1s;
}
.swipe-label.left { left: 18px; color: var(--again); transform: rotate(-8deg); }
.swipe-label.right { right: 18px; color: var(--good); transform: rotate(8deg); }

.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ratings[aria-hidden="true"] { display: none; }
.rate {
  border: 0; border-radius: 14px; padding: 10px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #fff; font-size: 15px;
}
.rate small { font-size: 12px; opacity: .9; }
.rate:active { transform: scale(.96); }
.rate.again { background: var(--again); }
.rate.hard { background: var(--hard); }
.rate.good { background: var(--good); }
.rate.easy { background: var(--easy); }

.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-size: 16px; font-weight: 600;
  background: var(--card); color: var(--text); cursor: pointer; width: 100%; max-width: 360px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn:active { opacity: .85; }
.show { align-self: center; min-height: 58px; }
.ratings, .show { flex: none; }

.summary { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; min-width: 220px; }
.summary li { display: flex; justify-content: space-between; gap: 18px; background: var(--card); border-radius: 12px; padding: 10px 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: 90vw; z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .card, .progress-fill { transition: none; }
}
