:root {
  --primary-color: #4F46E5;
  --primary-hover: #4338CA;
  --bg-color: #F3F4F6;
  --card-bg: #FFFFFF;
  --text-main: #1F2937;
  --text-muted: #6B7280;
  --success: #10B981;
  --danger: #EF4444;
  --border: #E5E7EB;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 0.5rem;
  --radius-lg: 1rem;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Loading Screen */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgb(23, 23, 27);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out;
}
.loader-content {
  text-align: center;
}
.pulse-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: pulse 1.5s infinite;
}
.loader-content p {
  color: var(--primary-color);
  font-weight: 600;
  letter-spacing: 0.05em;
}
@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Utilities */
.hidden { display: none !important; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.875rem;
}
.btn-primary {
  background-color: var(--primary-color);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}
.btn-secondary {
  background-color: white;
  color: var(--text-main);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background-color: #F9FAFB;
}
.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-success {
  background-color: var(--success);
  color: white;
}
.btn-full {
  width: 100%;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  font-size: 1rem;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  font-size: 2rem;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background-color 0.2s;
  z-index: 100;
}
.fab:hover {
  background-color: var(--primary-hover);
  transform: scale(1.1);
}
.fab.hidden {
  display: none;
}

/* App Container */
#app {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
  padding-bottom: 6rem;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
h1 { font-size: 1.875rem; font-weight: 700; color: var(--primary-color); }

/* Forms */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.btn-toggle-pw {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
}

.error-box {
  background-color: #FEF2F2;
  border: 1px solid #FEE2E2;
  color: var(--danger);
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  text-align: center;
}

/* Login View */
#login-view {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.auth-switch {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.auth-switch a {
  color: var(--primary-color);
  cursor: pointer;
  text-decoration: underline;
}

/* Vocab List View */
.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}
.filters-actions-container {
  width: 100%;
}
.search-container {
  width: 100%;
}
.search-container input {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>');
  background-repeat: no-repeat;
  background-position: 0.75rem center;
  padding-left: 2.5rem;
}
.filter-chips {
  display: flex;
  gap: 0.5rem;
}
.chip {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  background-color: var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.chip.active {
  background-color: var(--primary-color);
  color: white;
}
.language-filters .chip.active {
  background-color: var(--success);
}

.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.vocab-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.vocab-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  z-index: 2;
}
.vocab-card.menu-open {
  z-index: 100 !important;
}
.vocab-card.status-archived {
  opacity: 0.6 !important;
  filter: grayscale(1) !important;
  box-shadow: none !important;
  border: 1px dashed var(--border) !important;
  background-color: #F9FAFB !important;
}
.vocab-card.status-archived h3 {
  color: var(--text-muted);
}
.vocab-card.status-archived p {
  color: #9CA3AF;
}
.vocab-card.status-archived:hover {
  opacity: 0.95 !important;
  filter: grayscale(0) !important;
  box-shadow: var(--shadow-sm) !important;
  background-color: var(--card-bg) !important;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.card-content h3 {
  font-size: 1.125rem;
  margin: 0 0 0.25rem 0;
  word-break: break-word;
}
.card-content p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.vocab-card .badge {
  position: static;
}
.vocab-card .card-menu-container {
  position: static;
  margin-top: -0.25rem;
  margin-right: -0.25rem;
}
.badge {
  position: absolute;
  top: 1rem;
  right: 2.5rem;
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  color: white;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-oneway {
  font-size: 0.75rem;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  background-color: var(--bg-color);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: bold;
}

/* Language Badge Colors */
.badge-english { background-color: #3B82F6; }
.badge-spanish { background-color: #EF4444; }
.badge-french { background-color: #10B981; }
.badge-italian { background-color: #F59E0B; }
.badge-portuguese { background-color: #8B5CF6; }
.badge-romanian { background-color: #EC4899; }
.badge-default { background-color: var(--text-muted); }

/* Ellipsis Menu */
.card-menu-container {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}
.menu-trigger {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  border-radius: 50%;
  transition: background 0.2s;
}
.menu-trigger:hover {
  background: var(--bg-color);
  color: var(--text-main);
}
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 160px;
  display: none;
  padding: 0.5rem 0;
  margin-top: 0.25rem;
}
.dropdown-menu.show {
  display: block;
}
.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  background: none;
  border: none;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-main);
}
.dropdown-item:hover {
  background: var(--bg-color);
}
.dropdown-item.danger {
  color: var(--danger);
}
.dropdown-item.danger:hover {
  background: #FEF2F2;
}

.progress-bar {
  height: 8px; /* Taller */
  background: var(--border);
  border-radius: 4px;
  margin-top: 1.25rem;
  position: relative;
  overflow: visible; /* Allow ticks to overhang */
}
.progress-inner {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden; /* Clip the colored bars */
  border-radius: 4px;
}
.progress-correct { background: var(--success); height: 100%; }
.progress-wrong { background: var(--danger); height: 100%; }

.progress-tick {
  position: absolute;
  top: -3px; /* Overhang top by 3px */
  bottom: -3px; /* Overhang bottom by 3px */
  width: 1.5px;
  background-color: #000000; /* Solid black */
  z-index: 5;
  pointer-events: none;
}
.progress-tick-weighted {
  width: 3px; /* Slightly wider for the gold tick */
  background-color: #D4AF37; /* Solid Gold */
  box-shadow: 0 0 2px rgba(0,0,0,0.2);
}

/* Toggle Switch */
.switch-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}
.switch {
  position: relative;
  display: inline-block;
  width: 2.5rem;
  height: 1.4rem;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border);
  transition: .3s;
  border-radius: 1.4rem;
}
.slider:before {
  position: absolute;
  content: "";
  height: 1rem;
  width: 1rem;
  left: 0.2rem;
  bottom: 0.2rem;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}
input:checked + .slider {
  background-color: var(--success);
}
input:checked + .slider:before {
  transform: translateX(1.1rem);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal-backdrop.show .modal-content {
  transform: translateY(0);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Flashcard View */
#review-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 0;
}
.review-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.card-container {
  width: 100%;
  max-width: 400px;
  height: 250px;
  perspective: 1000px;
  margin-bottom: 2rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.flashcard {
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  position: relative;
}
.flashcard.flipped {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.card-front h2 { font-size: 2rem; color: var(--text-main); }
.card-back {
  transform: rotateY(180deg);
  background: #FAFAFA;
}
.card-back h2 { font-size: 1.5rem; color: var(--text-main); font-weight: 500; }
.hint {
  position: absolute;
  bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.review-actions {
  display: flex;
  gap: 1rem;
}
.review-actions button {
  padding: 1rem 2rem;
  font-size: 1.125rem;
  border-radius: 9999px;
}
.review-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Completion Screen */
#completion-view {
  text-align: center;
  padding: 3rem 2rem;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
#completion-view h2 { font-size: 1.75rem; margin-bottom: 2rem; color: var(--text-main); }
#completion-view p { color: var(--text-muted); margin-bottom: 2rem; }

.score-container {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 2rem;
}
.score-chart {
  width: 100%;
  height: 100%;
  transform: rotate(135deg); /* Start 3/4 circle correctly */
}
.chart-bg {
  fill: none;
  stroke: var(--bg-color);
  stroke-width: 8;
  stroke-dasharray: 212 283; /* 3/4 of circumference (2 * pi * 45) */
  stroke-linecap: round;
}
.chart-fill {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 8;
  stroke-dasharray: 0 283;
  stroke-linecap: round;
  transition: stroke-dasharray 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.score-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
}
#score-percent {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary-color);
  line-height: 1;
}
#score-fraction {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Perfect State Effects */
.perfect-score .chart-fill {
  stroke: var(--success);
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.4));
  animation: shimmer 2s infinite linear;
}
.perfect-score #score-percent {
  color: var(--success);
}

@keyframes shimmer {
  0% { opacity: 1; }
  50% { opacity: 0.7; stroke-width: 10; }
  100% { opacity: 1; }
}

.completion-actions { display: flex; justify-content: center; gap: 1rem; }
