/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #080e1a;
  --surface:      #0f1a2e;
  --surface-2:    #162035;
  --gold:         #c9a84c;
  --gold-bright:  #f0cc72;
  --gold-glow:    rgba(201,168,76,.25);
  --silver:       #a8bdd0;
  --text:         #f0e8d8;
  --text-muted:   rgba(240,232,216,.5);
  --correct:      #34d399;
  --wrong:        #f87171;
  --radius:       18px;
  --radius-sm:    12px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }


/* ══════════════════════════════════════════════════════════════
   SCREEN 1 — Category Selection
══════════════════════════════════════════════════════════════ */

#category-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: relative;
  text-align: center;
  padding: 52px 20px 44px;
  overflow: hidden;
}

.header-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 100% at 50% 0%, rgba(201,168,76,.18) 0%, transparent 70%);
  pointer-events: none;
}

.app-header h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
  position: relative;
}

.gold { color: var(--gold-bright); }

.subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: 8px;
  position: relative;
}

.category-main {
  flex: 1;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px 48px;
}

/* Options row */
.options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding: 14px 18px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(201,168,76,.15);
}

.options-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.shuffle-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1.5px solid rgba(201,168,76,.3);
  border-radius: 99px;
  padding: 7px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: 'Inter', system-ui, sans-serif;
}

.shuffle-toggle:hover { border-color: var(--gold); color: var(--text); }

.shuffle-toggle.active {
  background: var(--gold-glow);
  border-color: var(--gold);
  color: var(--gold-bright);
}

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Category grid */
.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cat-all { grid-column: 1 / -1; }

.cat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1.5px solid rgba(201,168,76,.12);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  text-align: left;
  transition: all 0.22s ease;
  position: relative;
  overflow: hidden;
}

.cat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 40%, rgba(201,168,76,.06) 60%, transparent 80%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cat-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(201,168,76,.15);
}

.cat-card:hover::before { opacity: 1; }

.cat-all {
  background: linear-gradient(135deg, #1a2a45, #0f1a2e);
  border-color: var(--gold);
}

.cat-all:hover { box-shadow: 0 10px 36px rgba(201,168,76,.25); }

.cat-icon { font-size: 2rem; flex-shrink: 0; }
.cat-all .cat-icon { font-size: 2.2rem; }

.cat-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.cat-name { font-size: 1rem; font-weight: 700; color: var(--text); }
.cat-all .cat-name { font-size: 1.1rem; color: var(--gold-bright); }
.cat-count { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

/* Best score badge on category cards */
.cat-best {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(201,168,76,.12);
  border: 1px solid rgba(201,168,76,.25);
  border-radius: 99px;
  padding: 3px 9px;
  white-space: nowrap;
  flex-shrink: 0;
  /* Hidden by default; JS sets textContent to show it */
}

.cat-best:empty { display: none; }


/* ══════════════════════════════════════════════════════════════
   SCREEN 2 — Flashcard Game
══════════════════════════════════════════════════════════════ */

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40px;
  overflow-x: hidden; /* prevents scroll during card exit animations */
}

/* Top bar */
.top-bar {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 10px;
  gap: 10px;
}

.btn-back {
  background: transparent;
  border: 1.5px solid rgba(201,168,76,.25);
  border-radius: 99px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: 'Inter', system-ui, sans-serif;
}

.btn-back:hover { border-color: var(--gold); color: var(--gold-bright); }

.top-category {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
}

/* Right side of top bar: streak + score stacked */
.top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

/* 🔥 Streak counter */
.streak-display {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-muted);
  transition: color 0.3s ease;
  white-space: nowrap;
}

/* When streak >= 3, glow gold */
.streak-display.hot {
  color: var(--gold-bright);
  text-shadow: 0 0 12px rgba(240,204,114,.6);
  animation: streakPulse 0.5s ease;
}

@keyframes streakPulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.top-score {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Progress bar */
.progress-row {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 24px;
}

.progress-bar-track {
  flex: 1;
  height: 6px;
  background: var(--surface-2, #162035);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px var(--gold-glow);
}

.card-counter {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Flashcard ─────────────────────────────────────────────── */
.card-scene {
  width: calc(100% - 40px);
  max-width: 460px;
  height: 300px;
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: 24px;
}

/* Card exit animations — triggered from JS */
.card-scene.exit-correct {
  animation: exitRight 0.28s ease forwards;
  pointer-events: none;
}

.card-scene.exit-wrong {
  animation: exitLeft 0.28s ease forwards;
  pointer-events: none;
}

.card-scene.enter {
  animation: enterCard 0.28s ease forwards;
}

@keyframes exitRight {
  to { opacity: 0; transform: translateX(80px) scale(0.88); }
}
@keyframes exitLeft {
  to { opacity: 0; transform: translateX(-80px) scale(0.88); }
}
@keyframes enterCard {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}

/* The rotating card wrapper */
.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius);
}

.card.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  backface-visibility: hidden;
  user-select: none;
}

/* Front — deep navy */
.card-front {
  background: linear-gradient(145deg, #1a3255, #0d1e38);
  border: 1.5px solid rgba(201,168,76,.35);
  box-shadow: 0 12px 48px rgba(0,0,0,.5), inset 0 1px 0 rgba(201,168,76,.15);
}

/* Back — deep purple */
.card-back {
  background: linear-gradient(145deg, #22144a, #130c30);
  border: 1.5px solid rgba(168,189,208,.25);
  box-shadow: 0 12px 48px rgba(0,0,0,.5), inset 0 1px 0 rgba(168,189,208,.1);
  transform: rotateY(180deg);
}

.lang-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 5px 12px;
  border-radius: 99px;
  background: rgba(255,255,255,.06);
  color: var(--text-muted);
}

.card-front .lang-badge {
  background: rgba(201,168,76,.12);
  color: var(--gold);
}

.word {
  font-size: 2.6rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.15;
}

.card-front .word { color: var(--gold-bright); }

.flip-hint { font-size: 0.78rem; color: var(--text-muted); }

/* ── Answer Buttons ─────────────────────────────────────────── */
.answer-buttons {
  display: flex;
  gap: 14px;
  width: calc(100% - 40px);
  max-width: 460px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.answer-buttons.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  font-family: 'Inter', system-ui, sans-serif;
}

.btn:active { transform: scale(0.96) !important; }

.btn-correct {
  background: linear-gradient(135deg, #1f6b4a, #155c3e);
  color: var(--correct);
  border: 1.5px solid rgba(52,211,153,.3);
  box-shadow: 0 4px 20px rgba(52,211,153,.15);
}

.btn-correct:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(52,211,153,.25);
  filter: brightness(1.1);
}

.btn-wrong {
  background: linear-gradient(135deg, #6b1f1f, #5c1515);
  color: var(--wrong);
  border: 1.5px solid rgba(248,113,113,.3);
  box-shadow: 0 4px 20px rgba(248,113,113,.15);
}

.btn-wrong:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(248,113,113,.25);
  filter: brightness(1.1);
}

/* ── Keyboard hint ──────────────────────────────────────────── */
.keyboard-hint {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.6;
  text-align: center;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 700;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 5px;
  color: var(--silver);
}


/* ══════════════════════════════════════════════════════════════
   SCREEN 3 — End / Results
══════════════════════════════════════════════════════════════ */

#end-screen {
  position: fixed;
  inset: 0;
  background: rgba(8,14,26,.94);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.end-card {
  background: var(--surface);
  border: 1.5px solid rgba(201,168,76,.25);
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}

.end-emoji { font-size: 4rem; margin-bottom: 16px; }
.end-title { font-size: 1.8rem; font-weight: 800; margin-bottom: 10px; }
.end-message { font-size: 1rem; color: var(--text-muted); margin-bottom: 20px; }

.end-score-box {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  background: rgba(201,168,76,.1);
  border: 1px solid rgba(201,168,76,.25);
  border-radius: var(--radius-sm);
  padding: 14px 28px;
  margin-bottom: 14px;
}

#end-score-text { font-size: 1.8rem; font-weight: 800; color: var(--gold-bright); }
#end-pct-text   { font-size: 1rem; font-weight: 700; color: var(--gold); opacity: 0.75; }

/* Best score comparison line */
.end-best-label {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 6px;
  min-height: 1.2em;
}

.end-best-label.new-best {
  color: var(--gold-bright);
}

.end-best-label.prev-best {
  color: var(--text-muted);
}

/* Streak highlight line */
.end-streak {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 28px;
  min-height: 1.2em;
}

.end-streak.hot { color: var(--gold); }

.end-actions { display: flex; gap: 12px; }

.btn-restart {
  flex: 1;
  background: linear-gradient(135deg, var(--gold), #a07830);
  color: #0b0e18;
  border: none;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: 'Inter', system-ui, sans-serif;
  box-shadow: 0 4px 20px rgba(201,168,76,.3);
}

.btn-restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(201,168,76,.4);
}

.btn-change-cat {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid rgba(201,168,76,.2);
  padding: 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', system-ui, sans-serif;
}

.btn-change-cat:hover { border-color: var(--gold); color: var(--gold-bright); }


/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app-header h1         { font-size: 2.1rem; }
  .category-grid         { grid-template-columns: 1fr; }
  .cat-all               { grid-column: 1; }
  .word                  { font-size: 2rem; }
  .end-card              { padding: 36px 22px; }
  .end-actions           { flex-direction: column; }
  .card-scene            { height: 260px; }
  .keyboard-hint         { display: none; } /* hidden on touch devices */
}
