/* ===== DESIGN TOKENS ===== */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(30, 30, 55, 0.85);
  --bg-card-back: rgba(40, 20, 60, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-muted: #65657a;
  --accent-correct: #22c55e;
  --accent-correct-glow: rgba(34, 197, 94, 0.3);
  --accent-wrong: #ef4444;
  --accent-wrong-glow: rgba(239, 68, 68, 0.3);
  --accent-flip: #8b5cf6;
  --accent-flip-glow: rgba(139, 92, 246, 0.3);
  --accent-streak: #f59e0b;
  --gradient-card: linear-gradient(135deg, #1e1e3a 0%, #2a1a3e 100%);
  --gradient-card-back: linear-gradient(135deg, #2a1a3e 0%, #1e1e3a 100%);
  --gradient-header: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Animated background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 400px at 20% 20%, rgba(139, 92, 246, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 500px 350px at 80% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 70%);
  z-index: 0;
  pointer-events: none;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  padding-top: calc(var(--safe-top) + 8px);
  padding-bottom: calc(var(--safe-bottom) + 16px);
}

/* ===== HEADER ===== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}
#header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  background: var(--gradient-header);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.92); }

/* ===== STATS BAR ===== */
#stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}
.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}
.stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ===== PROGRESS BAR ===== */
#progress-wrap {
  width: 100%;
  height: 4px;
  background: var(--bg-secondary);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}
#progress-bar {
  height: 100%;
  width: 0%;
  background: var(--gradient-header);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ===== CARD AREA ===== */
#card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  perspective: 1000px;
}

#card-container {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 3 / 2.2;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
  border-radius: var(--radius-xl);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

.card-front {
  background: var(--gradient-card);
}
.card-back {
  background: var(--gradient-card-back);
  transform: rotateY(180deg);
}

.card-lang-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.card-text {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  max-width: 100%;
  word-wrap: break-word;
}

.card-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 12px;
  line-height: 1.4;
  max-width: 90%;
  opacity: 0.85;
}

.card-hint {
  position: absolute;
  bottom: 16px;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  animation: pulse-hint 2s ease-in-out infinite;
}

@keyframes pulse-hint {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

#card-counter {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Card slide-in animation */
.card-enter {
  animation: card-slide-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes card-slide-in {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Feedback flash */
.card-correct { animation: flash-correct 0.4s ease; }
.card-wrong { animation: flash-wrong 0.4s ease; }

@keyframes flash-correct {
  0% { box-shadow: var(--glass-shadow); }
  50% { box-shadow: 0 0 40px var(--accent-correct-glow), var(--glass-shadow); }
  100% { box-shadow: var(--glass-shadow); }
}
@keyframes flash-wrong {
  0% { box-shadow: var(--glass-shadow); }
  50% { box-shadow: 0 0 40px var(--accent-wrong-glow), var(--glass-shadow); }
  100% { box-shadow: var(--glass-shadow); }
}

/* ===== ACTION BUTTONS ===== */
#actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 16px 0 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 80px;
  height: 72px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.2s;
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}
.action-btn:active { transform: scale(0.9); }

.btn-wrong {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}
.btn-wrong:hover { background: rgba(239, 68, 68, 0.2); box-shadow: 0 4px 20px var(--accent-wrong-glow); }

.btn-correct {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}
.btn-correct:hover { background: rgba(34, 197, 94, 0.2); box-shadow: 0 4px 20px var(--accent-correct-glow); }

.btn-flip {
  background: rgba(139, 92, 246, 0.12);
  color: #c4b5fd;
}
.btn-flip:hover { background: rgba(139, 92, 246, 0.2); box-shadow: 0 4px 20px var(--accent-flip-glow); }

/* ===== SETTINGS PANEL ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  transition: opacity 0.3s;
}
.overlay.hidden {
  display: none;
}

.panel {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 24px 20px calc(var(--safe-bottom) + 24px);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  animation: slide-up 0.3s ease;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.panel-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.setting-group {
  margin-bottom: 20px;
}
.setting-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.toggle-group {
  display: flex;
  gap: 6px;
  background: var(--bg-primary);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.toggle-btn {
  flex: 1;
  padding: 10px 8px;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle-btn.active {
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
}
.toggle-btn:hover:not(.active) {
  color: var(--text-secondary);
}

.setting-danger {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--glass-border);
}
.reset-btn {
  width: 100%;
  padding: 12px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}
.reset-btn:hover { background: rgba(239, 68, 68, 0.2); }
.reset-btn:active { transform: scale(0.98); }

.setting-info {
  text-align: center;
  padding-top: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.muted { color: var(--text-muted); font-size: 0.7rem; margin-top: 4px; }

/* ===== CELEBRATION ===== */
.celebration-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  animation: pop-in 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.celebration-emoji {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounce 0.6s ease infinite alternate;
}
@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
.celebration-content h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  background: var(--gradient-header);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.celebration-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.celebration-content .action-btn {
  width: auto;
  height: auto;
  flex-direction: row;
  padding: 14px 32px;
  font-size: 0.85rem;
  gap: 8px;
}

/* ===== KEYBOARD HINTS ===== */
@media (min-width: 768px) {
  .action-btn::after {
    font-size: 0.55rem;
    color: var(--text-muted);
    margin-top: 2px;
  }
  .btn-wrong::after { content: '← or 1'; }
  .btn-flip::after { content: 'Space'; }
  .btn-correct::after { content: '→ or 3'; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 360px) {
  .card-text { font-size: 1.2rem; }
  .stat-value { font-size: 1.1rem; }
  #card-container { aspect-ratio: 3 / 2.4; }
}

@media (min-height: 800px) {
  #card-container { aspect-ratio: 3 / 2; }
}
