/* CSS Design System for YDT Vocabulary App - Light Minimalist Theme */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-blue: #2563eb;
  --accent-blue-light: #eff6ff;
  --accent-green: #10b981;
  --accent-green-light: #ecfdf5;
  --accent-red: #ef4444;
  --accent-red-light: #fef2f2;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.04), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior-y: none;
}

/* App Shell container to mimic mobile view on desktop */
.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.02);
}

header {
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  flex-direction: column;
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.brand span {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-blue);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: -2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-icon:active {
  transform: scale(0.95);
  background-color: var(--bg-primary);
}

/* Main Content Area */
main {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

/* Screen Transitions */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dashboard / Welcome Screen */
.welcome-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  text-align: center;
}

.welcome-logo {
  font-size: 48px;
  margin-bottom: 12px;
}

.welcome-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.welcome-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-item {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stat-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-blue);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Study mode buttons */
.menu-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-primary {
  background-color: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 16px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.15);
}

.btn-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.btn-secondary:active {
  transform: translateY(1px);
  background-color: var(--bg-primary);
}

/* Elimination Mode Screen */
.elimination-header {
  margin-bottom: 16px;
  text-align: center;
}

.elimination-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.elimination-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background-color: var(--border-color);
  border-radius: 3px;
  margin: 10px 0;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--accent-blue);
  width: 0%;
  transition: width 0.3s ease;
}

.card-stack {
  position: relative;
  width: 100%;
  height: 280px; /* Changed from min-height to fix collapse in absolute layout */
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 24px;
}

/* Clean elimination card */
.elim-card {
  width: 100%;
  height: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 30px 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: absolute;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
}

.elim-card .word-pos {
  background-color: var(--accent-blue-light);
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

.elim-card .word-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.elim-card .word-hint {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  max-width: 80%;
}

.elim-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: auto; /* Pins buttons to the bottom on tall screens */
  padding-top: 16px;
}

.btn-know {
  background-color: var(--accent-green-light);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-know:active {
  transform: scale(0.97);
  background-color: rgba(16, 185, 129, 0.15);
}

.btn-dontknow {
  background-color: var(--accent-red-light);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-dontknow:active {
  transform: scale(0.97);
  background-color: rgba(239, 68, 68, 0.15);
}

/* 3D Flashcard Section */
.study-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.study-progress {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.flashcard-container {
  perspective: 1000px;
  width: 100%;
  height: 52vh; /* Stable viewport height to prevent flexbox collapse on mobile */
  min-height: 380px; /* Safe minimum height to prevent text overflow */
  margin-bottom: 20px;
  cursor: pointer;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* Front & Back common card styling */
.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.card-face-front {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.card-face-back {
  background-color: #ffffff;
  transform: rotateY(180deg);
  overflow-y: auto;
}

/* Card content styles */
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.badge-year {
  background-color: #f1f5f9;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.badge-pos {
  background-color: var(--accent-blue-light);
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}

.badge-role {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

.badge-role.correct {
  background-color: var(--accent-green-light);
  color: var(--accent-green);
}

.badge-role.choice {
  background-color: #f8fafc;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.word-display {
  text-align: center;
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -1px;
  margin-bottom: 16px;
}

.card-divider {
  height: 1px;
  background-color: var(--border-color);
  width: 100%;
  margin: 16px 0;
}

.sentence-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sentence-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.sentence-text {
  font-size: 15px;
  color: var(--text-primary);
  font-style: italic;
  line-height: 1.6;
}

.sentence-text strong {
  color: var(--accent-blue);
  background-color: var(--accent-blue-light);
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
  font-style: normal;
}

.sentence-tr-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.card-hint-click {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: auto;
}

/* Back of Card styles */
.word-meaning-section {
  text-align: center;
  margin: 10px 0 20px 0;
}

.word-meaning-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-blue);
}

.reference-section {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 16px;
}

.reference-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.reference-body {
  font-size: 13px;
  color: var(--text-primary);
}

.reference-body strong {
  color: var(--accent-green);
}

/* Flashcard Action Buttons */
.study-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: auto; /* Pins buttons to the bottom on tall screens */
  padding-top: 16px;
}

.btn-again {
  background-color: #ffffff;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 16px;
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.btn-again:active {
  transform: scale(0.97);
  background-color: var(--bg-primary);
}

.btn-master {
  background-color: var(--accent-blue);
  color: #ffffff;
  border: none;
  padding: 16px;
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
  transition: all 0.2s ease;
}

.btn-master:active {
  transform: scale(0.97);
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.15);
}

/* Completion Screen */
.completion-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 40px 20px;
}

.completion-icon {
  font-size: 64px;
  color: var(--accent-green);
  background-color: var(--accent-green-light);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 24px;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.1);
  animation: scaleUp 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleUp {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.completion-container h2 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 12px;
}

.completion-container p {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 30px;
  max-width: 320px;
}

#confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99;
}

/* Install Banner for PWA */
.install-banner {
  background-color: var(--accent-blue-light);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: none;
  justify-content: space-between;
  align-items: center;
}

.install-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-blue);
}

.btn-install-now {
  background-color: var(--accent-blue);
  color: #ffffff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Offline badge in header */
.offline-badge {
  background-color: #fee2e2;
  color: #ef4444;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}

/* Media query for PC / Desktop (screens wider than mobile viewport) */
@media (min-width: 481px) {
  /* Center the app container as a premium card on desktop */
  body {
    align-items: center; /* Vertically center the app on PC */
    background-color: #f1f5f9;
  }

  .app-container {
    min-height: auto; /* Remove full-height on desktop */
    margin: 40px auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    background-color: var(--bg-secondary);
  }

  /* Keep cards at a beautiful compact size on PC */
  .flashcard-container {
    height: 440px !important; /* Fixed height for PC */
    flex: none !important;
  }

  /* Place control buttons directly below the cards on PC */
  .study-actions,
  .elim-actions {
    margin-top: 16px !important;
    padding-top: 0 !important;
  }
}
