:root {
  --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

  --text: #f0f9ff;
  --text-muted: #94a3b8;

  --accent: #22d3ee;
  --accent-glow: 0 0 20px rgba(34, 211, 238, 0.6);
  --good: #4ade80;
  --bad: #f87171;

  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 650px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
  z-index: 1;
}

/* --- Glass Panel (Header/Footer/Controls) --- */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--glass-shadow);
}

/* --- Header & Top Stats --- */
.top {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 2.8rem;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(to right, #67e8f9, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(34, 211, 238, 0.3));
}

.controls {
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 12px;
}

.control {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select {
  background: rgba(255, 255, 255, 0.05);
  color: white;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
  font-size: 0.95rem;
  transition: all 0.2s;
}

select:hover,
select:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
}

option {
  background: #1e1b4b;
  color: white;
}

/* --- Score & Logic --- */
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}

.score-board {
  display: flex;
  gap: 16px;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.1rem;
  font-weight: bold;
}

.score-item.correct {
  color: var(--good);
}

.score-item.wrong {
  color: var(--bad);
}

.streak-container {
  font-size: 1.1rem;
  font-weight: bold;
  color: #fb923c;
  text-shadow: 0 0 10px rgba(251, 146, 60, 0.4);
  animation: pulse-orange 2s infinite;
}

@keyframes pulse-orange {
  0% {
    transform: scale(1);
    opacity: 0.9;
  }

  50% {
    transform: scale(1.05);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 0.9;
  }
}

.progress-container {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease-out;
  box-shadow: 0 0 10px var(--accent);
}

/* --- Card Area --- */
.card-area {
  perspective: 1200px;
}

.flashcard-container {
  width: 100%;
  min-height: 160px;
  /* Reduced from 400px back to 320px (or slightly more if needed, but trying to fit) */
  margin-bottom: 12px;
  /* Reduced from 24px */
}

.flashcard {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-style: preserve-3d;
  cursor: default;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  /* Glassmorphism Card Info */
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  border-radius: 24px;
  padding: 30px;
  user-select: none;
}

.face.back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9));
  border-color: var(--accent);
}

.content {
  font-size: 2.2rem;
  /* Reduced from 3rem */
  font-weight: 800;
  margin-bottom: 10px;
  line-height: 1.3;
  width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.hint-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  opacity: 0.8;
  margin-top: auto;
}

/* --- Choices Grid --- */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  /* Reduced from 16px */
}

.choice-btn {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border: 1px solid var(--glass-border);
  padding: 12px;
  /* Reduced from 18px */
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.choice-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  border-color: var(--accent);
}

.choice-btn:active:not(:disabled) {
  transform: translateY(-1px);
}

/* Correct/Wrong States */
.choice-btn.correct {
  background: rgba(74, 222, 128, 0.2) !important;
  border-color: var(--good) !important;
  color: var(--good) !important;
  box-shadow: 0 0 15px rgba(74, 222, 128, 0.3) !important;
}

.choice-btn.wrong {
  background: rgba(248, 113, 113, 0.2) !important;
  border-color: var(--bad) !important;
  color: var(--bad) !important;
  animation: shakeX 0.5s;
}

.choice-btn.unknown {
  grid-column: span 2;
  /* Make it full width */
  border-color: rgba(251, 191, 36, 0.5);
  color: #fbbf24;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.1), rgba(251, 191, 36, 0.05));
  font-style: italic;
  margin-top: 5px;
}

.choice-btn.unknown:hover {
  background: rgba(251, 191, 36, 0.2);
  border-color: #fbbf24;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(251, 191, 36, 0.2);
}

/* --- Summary List --- */
.summary-container {
  width: 100%;
  text-align: left;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
}

.summary-heading {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 10px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 1rem;
}

.summary-item:last-child {
  border-bottom: none;
}

.summary-word {
  color: var(--accent);
  font-weight: bold;
}

.summary-meaning {
  color: var(--text);
}

@keyframes shakeX {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.feedback-message {
  height: 20px;
  /* spacer */
}

/* --- Footer Nav --- */
.navigation {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

#nextBtn {
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  color: #0f172a;
  border: none;
  font-weight: 800;
  padding: 14px 28px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}

#nextBtn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 25px rgba(14, 165, 233, 0.6);
}

#nextBtn:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
  cursor: not-allowed;
}

.hint {
  text-align: center;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 20px;
}

/* --- Modal --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: #1e293b;
  border: 1px solid var(--bad);
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(248, 113, 113, 0.3);
  transform: scale(1);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
  transform: scale(0.8);
}

.error-icon {
  font-size: 4rem;
  color: var(--bad);
  margin-bottom: 20px;
  animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-content h2 {
  margin: 0;
  color: white;
  margin-bottom: 10px;
}

.modal-content p {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 25px;
}

.modal-btn {
  background: var(--bad);
  color: white;
  border: none;
  padding: 12px 30px;
  font-size: 1.1rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-btn:hover {
  background: #ef4444;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
}

/* Mobile responsiveness */
@media (max-width: 600px) {
  .choices-grid {
    grid-template-columns: 1fr;
  }

  .choice-btn.unknown {
    grid-column: auto;
    /* Reset column span on mobile */
    width: 100%;
  }

  h1 {
    font-size: 2rem;
  }

  .content {
    font-size: 2rem;
  }
}