body {
  font-family: "Courier New", Courier, monospace;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #f5f7ff 0%, #dfe4f5 40%, #bcc6db 100%);
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-container {
  width: min(900px, 95%);
  background: rgba(255, 255, 255, 0.94);
  border-radius: 24px;
  padding: 2rem 2rem 2.5rem;
  box-shadow: 0 24px 60px rgba(35, 50, 87, 0.16);
  text-align: left;
}

.app-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
  gap: 1.75rem;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
}

.app-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(100, 116, 139, 0.15);
}

.instructions {
  margin: 0;
  color: #475569;
  line-height: 1.7;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 2.5vw, 2.6rem);
  color: #1d2c4d;
}

.deck-note {
  margin: 0;
  color: #4f5c7c;
  max-width: 100%;
  line-height: 1.5;
}

.flashcard-filter,
.flip-start-control {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.flashcard-filter label,
.flip-start-control label {
  font-size: 0.95rem;
  color: #3d4b6e;
  font-weight: 700;
}

.flashcard-filter select,
.flip-start-control select {
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  min-width: 180px;
  background: #fff;
  color: #1f2937;
}

.card-deck {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 320px;
  width: min(520px, 100%);
  max-width: 520px;
  margin: 0 auto;
  overflow: visible;
}

.card-deck.reshuffle {
  animation: reshuffle 0.45s ease;
}

@keyframes reshuffle {
  0% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-8px) rotate(-2deg); }
  50% { transform: translateX(8px) rotate(2deg); }
  75% { transform: translateX(-4px) rotate(-1deg); }
  100% { transform: translateX(0) rotate(0deg); }

}


.card-stack {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Background stack cards that appear behind the active card. */
.card-stack span {
  position: absolute;
  left: 50%;
  width: 100%;
  max-width: 520px;
  height: 260px;
  border-radius: 20px;
  background: #fcfcfa;
  border: 1px solid rgba(125, 117, 98, 0.16);
  transform: translateX(-50%) translateY(-450px) rotate(var(--final-rotate, 0deg));
  box-shadow: 0 16px 38px rgba(31, 37, 64, 0.08);
  opacity: 0;
  animation: fallIn 0.85s cubic-bezier(0.22, 1.0, 0.36, 1.0) forwards;
}

/* Stagger the background stack cards so they appear as a fanned pile. */
.card-stack span:nth-child(1) {
  top: 0;
  --final-rotate: -1.5deg;
  animation-delay: 0.08s;
}

.card-stack span:nth-child(2) {
  top: 8px;
  --final-rotate: 1.2deg;
  animation-delay: 0.16s;
}

.card-stack span:nth-child(3) {
  top: 16px;
  --final-rotate: -0.8deg;
  animation-delay: 0.24s;
}

@keyframes fallIn {
  0% {
    transform: translateX(-50%) translateY(-450px) rotate(var(--final-rotate, 0deg));
    opacity: 0;
  }
  70% {
    transform: translateX(-50%) translateY(18px) rotate(var(--final-rotate, 0deg));
    opacity: 1;
  }
  100% {
    transform: translateX(-50%) translateY(0) rotate(var(--final-rotate, 0deg));
    opacity: 1;
  }
}

/* The visible flashcard wrapper. */
.flashcard {
  width: min(520px, 100%);
  max-width: 520px;
  min-height: 260px;
  perspective: 1200px;
  cursor: pointer;
  z-index: 2;
  opacity: 0;
  transform: translateY(18px);
  animation: cardFadeIn 0.5s ease-out 0.4s forwards;
}

/* The clone used for animation while the real flashcard stays hidden. */
.animated-copy {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  max-width: 520px;
  pointer-events: none;
}

/* Preview card behind the active card. This is the next card in the queue. */
.flashcard.next-card {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  transform: translateY(18px) scale(0.96);
  opacity: 0.94;
  pointer-events: none;
}

/* Applied to the active card when moving it to the back of the deck. */
.flashcard.move-to-back {
  transform-origin: bottom center;
  animation: moveBack 0.78s ease-in-out forwards;
  z-index: 3;
}

/* Applied to the active card when moving it to the front of the deck. */
.flashcard.move-to-front {
  transform-origin: bottom center;
  animation: moveFront 0.78s ease-in-out forwards;
  z-index: 3;
}

/* Animate the card lifting, rotating, and sliding to the back. */
@keyframes moveBack {
  0% {
    transform: translateY(0) scale(1) rotateX(0deg) rotateZ(0deg);
    opacity: 1;
  }
  20% {
    transform: translateY(-18px) scale(1.03) rotateX(18deg) rotateZ(-4deg);
    opacity: 1;
  }
  45% {
    transform: translateY(-36px) translateX(18px) scale(1.02) rotateX(20deg) rotateZ(-10deg);
    opacity: 0.98;
  }
  70% {
    transform: translateY(-26px) translateX(30px) scale(0.98) rotateX(10deg) rotateZ(16deg);
    opacity: 0.86;
  }
  100% {
    transform: translateY(-12px) translateX(34px) scale(0.92) rotateX(0deg) rotateZ(22deg);
    opacity: 0.68;
  }
}

/* Animate the previous card moving forward and flipping back into the front position. */
@keyframes moveFront {
  0% {
    transform: translateY(-12px) translateX(34px) scale(0.92) rotateX(0deg) rotateZ(22deg);
    opacity: 0.68;
  }
  35% {
    transform: translateY(-8px) translateX(22px) scale(0.98) rotateX(10deg) rotateZ(16deg);
    opacity: 0.82;
  }
  70% {
    transform: translateY(-24px) translateX(8px) scale(1.02) rotateX(18deg) rotateZ(-8deg);
    opacity: 0.94;
  }
  100% {
    transform: translateY(0) scale(1) rotateX(0deg) rotateZ(0deg);
    opacity: 1;
  }
}

@keyframes cardFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


.card-inner {
  position: relative;
  width: 100%;
  min-height: 260px;
  transition: transform 0.8s ease;
  transform-style: preserve-3d;
}

.flashcard.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  box-shadow: 0 18px 40px rgba(26, 35, 72, 0.15);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.9rem 1.8rem;
  overflow: hidden;
}

.card-front {
  justify-content: flex-start;
  align-items: center;
}

.term-side {
  background: #ffffff;
  background-image: none;
  justify-content: center;
}

.term-side::after {
  display: none;
}

.term-side .card-definition {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 0;
}

.term-side .card-label {
  visibility: hidden;
}

.definition-side {
  background: #fbfaf6;
  border: 1px solid #d8d5c7;
  background-image:
    linear-gradient(to bottom, transparent 46px, rgba(62, 68, 117, 0.06) 47px),
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 46px,
      rgba(58, 83, 145, 0.18) 47px,
      rgba(58, 83, 145, 0.18) 48px
    );
  justify-content: flex-start;
  align-items: center;
}

.definition-side::after {
  content: "";
  position: absolute;
  left: 1.6rem;
  right: 1.6rem;
  top: 4.2rem;
  height: 1px;
  background: rgba(58, 83, 145, 0.25);
}

.definition-side .card-word,
.definition-side .card-definition {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 0;
  text-align: center;
  font-size: clamp(1.4rem, 2.2vw, 1.75rem);
  line-height: 1.5;
}

.definition-side .card-label {
  position: relative;
}

.definition-side .card-label::after {
  content: "";
  position: absolute;
  left: -15rem;
  right: -15rem;
  bottom: -0.35rem;
  height: 3px;
  background: #ca2e2e;
  border-radius: 999px;
}

.card-front::after {
  content: "";
  position: absolute;
  left: 1.6rem;
  right: 1.6rem;
  top: 4.2rem;
  height: 1px;
  background: rgba(58, 83, 145, 0.25);
}

.card-back.definition-side {
  background: #fbfaf6;
  border: 1px solid #d8d5c7;
  background-image:
    linear-gradient(to bottom, transparent 46px, rgba(62, 68, 117, 0.06) 47px),
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 46px,
      rgba(58, 83, 145, 0.18) 47px,
      rgba(58, 83, 145, 0.18) 48px
    );
  justify-content: flex-start;
  align-items: center;
}

.card-back {
  background: #ffffff;
  color: #1f2d4c;
  border: 1px solid #d8d5c7;
  transform: rotateY(180deg);
  justify-content: space-between;
}

.card-back-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
  flex: 1;
}

.card-back .card-label,
.card-back .card-word {
  text-align: center;
}

.card-front .card-word {
  text-align: center;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(1.55rem, 2.4vw, 2.05rem);
  letter-spacing: 0.02em;
  margin-bottom: 1.35rem;
}

.card-front .card-label {
  position: relative;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: #7d6b4b;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.card-front .card-label::after {
  content: "";
  position: absolute;
  left: -15rem;
  right: -15rem;
  bottom: -0.35rem;
  height: 3px;
  background: #ca2e2e;
  border-radius: 999px;
}

.card-front .card-footnote {
  text-align: center;
}

.card-label {
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: #7d6b4b;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.card-word,
.card-definition {
  font-size: clamp(1.4rem, 2.2vw, 1.95rem);
  line-height: 1.3;
  font-weight: 700;
  color: #1f2d4c;
  text-align: center;
}

.hint-toggle {
  display: inline-block;
  margin: 1rem auto 0;
  padding: 0.1rem 0.4rem;
  color: #4b5563;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: lowercase;
  text-decoration: underline;
  cursor: pointer;
}

.hint-toggle:hover,
.hint-toggle:focus-visible {
  color: #1f2937;
  outline: none;
}

.hint-text {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  color: #4f4f4f;
  max-width: 85%;
  margin-left: auto;
  margin-right: auto;
}

.hidden {
  display: none;
}

.matching-mode {
  margin-top: 2rem;
}

.match-header {
  margin-bottom: 1rem;
}

.match-instructions {
  margin: 0 auto;
  max-width: 640px;
  color: #475569;
}

.matching-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.match-column {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.match-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.terms-list,
.defs-list {
  display: grid;
  gap: 0.8rem;
}

.match-card {
  width: 100%;
  min-height: 96px;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  text-align: left;
  font-size: 0.94rem;
  line-height: 1.4;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.match-card:hover,
.match-card:focus-visible {
  transform: translateY(-1px);
  border-color: #93c5fd;
  box-shadow: 0 12px 22px rgba(147, 197, 253, 0.18);
}

.match-card.selected {
  border-color: #93c5fd;
  background: #e0f2fe;
  color: #1e293b;
}

.match-card.matched {
  opacity: 0.3;
  pointer-events: none;
}

.match-message {
  margin-top: 1rem;
  min-height: 1.5rem;
  color: #334155;
  font-size: 0.97rem;
}

.match-message.success {
  color: #166534;
}

.match-message.error {
  color: #b91c1c;
}

.completion-list {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}

.completion-card {
  padding: 0.85rem 1rem;
  background: #eef2ff;
  border-radius: 14px;
  border: 1px solid #c7d2fe;
  color: #1e293b;
  font-size: 0.95rem;
}

.game-menu {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0 0.5rem;
}

.game-mode {
  background: #e2e8f0;
  color: #1f2937;
  border-radius: 999px;
  padding: 0.75rem 1.1rem;
  font-weight: 700;
}

.game-mode.active {
  background: #3347a1;
  color: #fff;
}

.card-front .card-definition {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-top: 0.3rem;
}

.card-back .card-definition {
  color: #f3f3f3;
}

.card-footnote {
  margin-top: 1.6rem;
  font-size: 0.96rem;
  color: #6b7284;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.95rem 1.35rem;
  background-color: #3347a1;
  color: white;
  font-size: 1rem;
  transition: transform 0.18s ease, background-color 0.2s ease;
}

button:hover,
button:focus-visible {
  background-color: #252f73;
  transform: translateY(-1px);
}

.flashcard:focus-visible,
.flashcard:focus {
  outline: none;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.7rem;
}

#shuffle {
  background-color: #2563eb;
}

.animated-copy.shuffle {
  animation: shuffleCard 0.75s ease forwards;
}

@keyframes shuffleCard {
  0% {
    transform: translateX(0) rotate(0deg);
    opacity: 1;
  }
  20% {
    transform: translateX(-18px) rotate(-10deg);
  }
  40% {
    transform: translateX(18px) rotate(10deg);
    opacity: 0.95;
  }
  60% {
    transform: translateX(-14px) rotate(-6deg);
  }
  80% {
    transform: translateX(12px) rotate(6deg);
  }
  100% {
    transform: translateX(0) rotate(0deg);
    opacity: 0;
  }
}

button:focus-visible {
  outline: 3px solid rgba(77, 109, 255, 0.35);
  outline-offset: 4px;
}

@media (max-width: 860px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .main-content {
    width: 100%;
  }

  .main-content {
    align-items: stretch;
  }
}

@media (max-width: 520px) {
  .card-face {
    padding: 1.5rem 1.3rem;
  }

  .card-word,
  .card-definition {
    font-size: 1.45rem;
  }
}
