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

:root {
  --primary-gradient: linear-gradient(135deg, #4F46E5, #06B6D4);
  --success: #10B981;
  --bg-light: #F9FAFB;
  --overlay-dark: rgba(0, 0, 0, 0.7);
  --accent-orange: #F59E0B;
  --masculine: #3B82F6;
  --feminine: #EC4899;
  --neuter: #8B5CF6;
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #0a0a0f;
  color: white;
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
}

/* Camera View */
.camera-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #0a0a0f;
  position: relative;
}

.camera-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  z-index: 100;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

.flash-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.flash-btn:hover {
  background: rgba(255,255,255,0.25);
}

.language-selector-container {
  position: relative;
}

.language-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: white;
  border: none;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #1f2937;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: all 0.2s;
}

.language-selector:hover {
  transform: scale(1.02);
}

.lang-source {
  color: #4F46E5;
}

.lang-arrow {
  color: #9CA3AF;
}

.lang-target {
  color: #1f2937;
}

.dropdown-arrow {
  margin-left: 4px;
  color: #9CA3AF;
  transition: transform 0.2s;
}

.language-dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  background: white;
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  z-index: 200;
  min-width: 180px;
}

.lang-option {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  border-radius: 10px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-option:hover {
  background: #F3F4F6;
}

.lang-option.active {
  background: linear-gradient(135deg, #4F46E5, #06B6D4);
  color: white;
}

.word-count-badge {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  font-weight: 800;
  font-size: 16px;
  color: white;
  border: 2px solid rgba(255,255,255,0.3);
}

/* Camera container */
.camera-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  border: 3px dashed rgba(255,255,255,0.3);
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.3s;
  margin: 20px;
}

.upload-zone:hover {
  border-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.05);
}

.upload-icon {
  color: rgba(255,255,255,0.5);
  margin-bottom: 16px;
}

.upload-zone p {
  color: rgba(255,255,255,0.7);
  font-size: 16px;
  font-weight: 600;
}

.upload-hint {
  font-size: 14px !important;
  opacity: 0.5;
  margin-top: 8px;
}

/* Focus reticle */
.focus-reticle {
  position: absolute;
  width: 180px;
  height: 180px;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.05); opacity: 1; }
}

.reticle-corner {
  position: absolute;
  width: 40px;
  height: 40px;
  border-color: white;
  border-style: solid;
  border-width: 0;
}

.reticle-corner.top-left {
  top: 0;
  left: 0;
  border-top-width: 4px;
  border-left-width: 4px;
  border-radius: 8px 0 0 0;
}

.reticle-corner.top-right {
  top: 0;
  right: 0;
  border-top-width: 4px;
  border-right-width: 4px;
  border-radius: 0 8px 0 0;
}

.reticle-corner.bottom-left {
  bottom: 0;
  left: 0;
  border-bottom-width: 4px;
  border-left-width: 4px;
  border-radius: 0 0 0 8px;
}

.reticle-corner.bottom-right {
  bottom: 0;
  right: 0;
  border-bottom-width: 4px;
  border-right-width: 4px;
  border-radius: 0 0 8px 0;
}

.reticle-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255,255,255,0.8);
}

.helper-text {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* Camera footer */
.camera-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 24px 40px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.footer-btn {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.footer-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.05);
}

.shutter-btn {
  width: 80px;
  height: 80px;
  background: white;
  border: 6px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.shutter-btn:hover:not(:disabled) {
  transform: scale(1.05);
  border-color: rgba(255,255,255,0.5);
}

.shutter-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.shutter-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.shutter-inner {
  width: 56px;
  height: 56px;
  background: white;
  border-radius: 50%;
}

.shutter-loading {
  width: 40px;
  height: 40px;
  border: 4px solid #E5E7EB;
  border-top-color: #4F46E5;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Scanning overlay */
.scan-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.scan-content {
  position: relative;
  width: 90%;
  max-width: 400px;
  aspect-ratio: 4/3;
  border-radius: 20px;
  overflow: hidden;
}

.scan-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, #06B6D4, transparent);
  box-shadow: 0 0 20px #06B6D4, 0 0 40px #06B6D4;
  animation: scanMove 1.5s ease-in-out infinite;
}

@keyframes scanMove {
  0%, 100% { top: 0; }
  50% { top: 100%; }
}

.scan-info {
  position: absolute;
  bottom: -60px;
  left: 0;
  right: 0;
  text-align: center;
}

.scan-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
}

.scan-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4F46E5, #06B6D4);
  transition: width 0.1s;
}

.scan-text {
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  font-weight: 600;
}

/* Model loading */
.model-loading {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(0,0,0,0.8);
  border-radius: 50px;
  z-index: 100;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.model-loading p {
  color: white;
  font-size: 14px;
  font-weight: 500;
}

/* Result View */
.result-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #0a0a0f;
}

.result-image-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

/* Bounding box */
.bounding-box {
  position: absolute;
  border: 3px dashed #06B6D4;
  border-radius: 8px;
  pointer-events: none;
  animation: boxPulse 2s ease-in-out infinite;
}

@keyframes boxPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.box-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: #06B6D4;
  border-style: solid;
  border-width: 0;
}

.box-corner.tl { top: -3px; left: -3px; border-top-width: 4px; border-left-width: 4px; }
.box-corner.tr { top: -3px; right: -3px; border-top-width: 4px; border-right-width: 4px; }
.box-corner.bl { bottom: -3px; left: -3px; border-bottom-width: 4px; border-left-width: 4px; }
.box-corner.br { bottom: -3px; right: -3px; border-bottom-width: 4px; border-right-width: 4px; }

/* Result card */
.result-card {
  position: absolute;
  bottom: 160px;
  left: 20px;
  right: 20px;
  background: white;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  animation: slideUp 0.4s ease-out;
}

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

.confidence-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 12px;
  background: var(--success);
  color: white;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 700;
}

.translation-content {
  text-align: center;
}

.target-word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.target-word {
  font-size: 28px;
  font-weight: 800;
  color: #1f2937;
}

.article {
  color: #6B7280;
}

.gender-badge {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: white;
}

.gender-badge.masculine { background: var(--masculine); }
.gender-badge.feminine { background: var(--feminine); }
.gender-badge.neuter { background: var(--neuter); }

.native-word {
  color: #9CA3AF;
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 16px;
  text-transform: capitalize;
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #4F46E5, #06B6D4);
  border: none;
  border-radius: 50px;
  color: white;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.speak-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
}

/* Flashcard hidden */
.flashcard-hidden {
  text-align: center;
  padding: 20px;
  cursor: pointer;
}

.blur-text {
  font-size: 28px;
  font-weight: 800;
  color: #1f2937;
  filter: blur(12px);
  user-select: none;
  margin-bottom: 12px;
}

.tap-reveal {
  color: #4F46E5;
  font-size: 14px;
  font-weight: 600;
}

.encouragement {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #E5E7EB;
  color: var(--accent-orange);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.easter-egg {
  margin-top: 12px;
  padding: 12px;
  background: linear-gradient(135deg, #FEE2E2, #FECACA);
  border-radius: 12px;
  color: #DC2626;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

/* Error card */
.error-card {
  text-align: center;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.error-text {
  font-size: 18px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 8px;
}

.error-hint {
  color: #9CA3AF;
  font-size: 14px;
}

/* Result actions */
.result-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 12px;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.95), rgba(0,0,0,0.8));
}

.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 16px;
  color: white;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-2px);
}

.save-btn.saved {
  background: var(--success);
  border-color: var(--success);
}

.flashcard-btn.active {
  background: var(--accent-orange);
  border-color: var(--accent-orange);
}

.back-btn {
  background: rgba(255,255,255,0.05);
}

/* Confetti */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* History View */
.history-view {
  min-height: 100vh;
  min-height: 100dvh;
  background: #0a0a0f;
  padding-bottom: 80px;
}

.history-header {
  display: flex;
  align-items: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
  position: sticky;
  top: 0;
  z-index: 100;
}

.back-arrow {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.back-arrow:hover {
  background: rgba(255,255,255,0.2);
}

.history-header h1 {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.word-total {
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  font-weight: 600;
}

/* Empty history */
.empty-history {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.empty-history p {
  font-size: 18px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
}

.empty-hint {
  color: rgba(255,255,255,0.5) !important;
  font-size: 14px !important;
  margin-top: 8px;
}

/* Word grid */
.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 20px;
}

.word-card {
  background: rgba(255,255,255,0.05);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  transition: all 0.2s;
}

.word-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255,255,255,0.2);
}

.word-image-container {
  aspect-ratio: 4/3;
  overflow: hidden;
}

.word-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.word-info {
  padding: 12px;
}

.word-target {
  font-size: 16px;
  font-weight: 800;
  color: white;
  margin-bottom: 4px;
}

.word-article {
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}

.word-english {
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  text-transform: capitalize;
}

.word-actions {
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.word-speak,
.word-delete {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.2s;
}

.word-speak:hover {
  background: rgba(79, 70, 229, 0.2);
  color: #4F46E5;
}

.word-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #EF4444;
}

/* Footer */
.berrry-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: #0a0a0f;
  text-align: center;
}

.berrry-footer a {
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  text-decoration: none;
  transition: color 0.2s;
}

.berrry-footer a:hover {
  color: rgba(255,255,255,0.7);
}

/* Responsive */
@media (min-width: 768px) {
  .camera-view,
  .result-view {
    max-width: 480px;
    margin: 0 auto;
  }
  
  .result-card {
    max-width: 440px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }
  
  .result-actions {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }
  
  .word-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}