/* ============================================
   WHO IS IT? - Main Stylesheet
   Cute-minimalist, Kahoot-inspired design
   ============================================ */

/* CSS Variables */
:root {
  /* Primary colors */
  --primary: #7C3AED;
  --primary-dark: #6D28D9;
  --primary-light: #A78BFA;
  
  /* Secondary colors */
  --secondary: #F59E0B;
  --secondary-dark: #D97706;
  --secondary-light: #FCD34D;
  
  /* Feedback colors */
  --success: #10B981;
  --success-light: #34D399;
  --error: #EF4444;
  --error-light: #F87171;
  
  /* Neutrals */
  --white: #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  
  /* Grade backgrounds */
  --grade-1-bg: linear-gradient(135deg, #94A3B8 0%, #CBD5E1 100%);
  --grade-2-bg: linear-gradient(135deg, #14B8A6 0%, #5EEAD4 100%);
  --grade-3-bg: linear-gradient(135deg, #F59E0B 0%, #FCD34D 100%);
  --grade-4-bg: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
  --grade-5-bg: linear-gradient(135deg, #A855F7 0%, #E879F9 100%);
  --grade-6-bg: linear-gradient(135deg, #EAB308 0%, #FDE047 50%, #F59E0B 100%);
  
  /* Typography */
  --font-family: 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  
  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;
  
  /* Border radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 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);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--gray-800);
  line-height: 1.5;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
}

/* Screen Management */
.screen {
  display: none;
  width: 100%;
  max-width: 420px;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

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

/* ============================================
   START SCREEN
   ============================================ */

.start-container {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-2xl) var(--spacing-lg);
  box-shadow: var(--shadow-xl);
  text-align: center;
}

.logo-wrapper {
  margin-bottom: var(--spacing-xl);
}

.logo-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-md);
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.game-title {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: var(--spacing-sm);
  letter-spacing: -0.5px;
}

.game-subtitle {
  font-size: 1rem;
  color: var(--gray-500);
  font-weight: 500;
}

.start-form {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.name-input {
  width: 100%;
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: 1.125rem;
  font-family: var(--font-family);
  font-weight: 500;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  text-align: center;
}

.name-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.name-input::placeholder {
  color: var(--gray-400);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  font-family: var(--font-family);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-radius: var(--radius-lg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: var(--radius-lg);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

.btn-large {
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: 1.125rem;
  width: 100%;
}

.btn-icon {
  font-size: 1.25rem;
}

.btn-submit {
  width: 56px;
  height: 56px;
  background: var(--primary);
  color: var(--white);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

.btn-submit:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.btn-submit:disabled {
  background: var(--gray-300);
}

.submit-arrow {
  font-size: 1.5rem;
}

.btn-skip {
  background: transparent;
  color: var(--gray-500);
  font-size: 0.9rem;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  align-self: center;
}

.btn-skip:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* ============================================
   GAME SCREEN
   ============================================ */

.game-container {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-xl);
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--spacing-md);
  flex-shrink: 0;
}

.score-display {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.score-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.score-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.progress-wrapper {
  text-align: right;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--gray-500);
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.progress-bar {
  width: 120px;
  height: 8px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
  width: 10%;
}

/* Photo Section */
.photo-section {
  text-align: center;
  margin-bottom: var(--spacing-sm);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.photo-container {
  flex: 1;
  min-height: 150px;
  max-height: 50vh;
  margin: 0 auto var(--spacing-sm);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--gray-100);
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.person-photo {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: none;
}

.person-photo.loaded {
  display: block;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: var(--gray-400);
}

.photo-placeholder.hidden {
  display: none;
}

.photo-container.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}

.question-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-800);
}

/* Hearts Display */
.hearts-display {
  display: flex;
  justify-content: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
  flex-shrink: 0;
}

.heart {
  font-size: 1.75rem;
  transition: all var(--transition-fast);
}

.heart.lost {
  filter: grayscale(1);
  opacity: 0.4;
  transform: scale(0.9);
}

.heart.losing {
  animation: heartBreak 0.4s ease;
}

@keyframes heartBreak {
  0% { transform: scale(1); }
  25% { transform: scale(1.3); }
  50% { transform: scale(0.8) rotate(-10deg); }
  75% { transform: scale(0.9) rotate(5deg); }
  100% { transform: scale(0.9); filter: grayscale(1); opacity: 0.4; }
}

/* Guess Section */
.guess-section {
  display: flex;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
  flex-shrink: 0;
}

.autocomplete-wrapper {
  flex: 1;
  position: relative;
}

.guess-input {
  width: 100%;
  padding: var(--spacing-md);
  font-size: 1rem;
  font-family: var(--font-family);
  font-weight: 500;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.guess-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.guess-input::placeholder {
  color: var(--gray-400);
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.autocomplete-dropdown.hidden {
  display: none;
}

.autocomplete-item {
  padding: var(--spacing-sm) var(--spacing-md);
  cursor: pointer;
  font-weight: 500;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--gray-100);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--primary-light);
  color: var(--white);
}

.autocomplete-item.selected {
  background: var(--primary);
}

/* Point Popup */
.point-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--success);
  color: var(--white);
  font-size: 1.5rem;
  font-weight: 700;
  padding: var(--spacing-md) var(--spacing-xl);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: 200;
  pointer-events: none;
}

.point-popup.hidden {
  display: none;
}

.point-popup.show {
  animation: popIn 0.6s ease forwards;
}

@keyframes popIn {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  70% { transform: translate(-50%, -70%) scale(1); }
  100% { transform: translate(-50%, -100%) scale(0.8); opacity: 0; }
}

/* ============================================
   FINISH SCREEN
   ============================================ */

.finish-container {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-2xl) var(--spacing-lg);
  box-shadow: var(--shadow-xl);
  text-align: center;
}

.finish-container.grade-1 { background: var(--grade-1-bg); }
.finish-container.grade-2 { background: var(--grade-2-bg); }
.finish-container.grade-3 { background: var(--grade-3-bg); }
.finish-container.grade-4 { background: var(--grade-4-bg); }
.finish-container.grade-5 { background: var(--grade-5-bg); }
.finish-container.grade-6 { background: var(--grade-6-bg); }

.finish-container[class*="grade-"] {
  color: var(--white);
}

.finish-container[class*="grade-"] .btn-primary {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
}

.finish-container[class*="grade-"] .btn-primary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.35);
}

.finish-illustration {
  margin-bottom: var(--spacing-lg);
}

.finish-emoji {
  font-size: 5rem;
  animation: celebrate 1s ease infinite;
}

@keyframes celebrate {
  0%, 100% { transform: rotate(-5deg) scale(1); }
  50% { transform: rotate(5deg) scale(1.1); }
}

.grade-name {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: var(--spacing-md);
}

.score-result {
  margin-bottom: var(--spacing-md);
}

.final-score {
  font-size: 4rem;
  font-weight: 700;
  display: block;
  line-height: 1;
}

.score-unit {
  font-size: 1.125rem;
  opacity: 0.8;
}

.finish-message {
  font-size: 1rem;
  opacity: 0.9;
  margin-bottom: var(--spacing-xl);
}

/* ============================================
   LEADERBOARD SCREEN
   ============================================ */

.leaderboard-container {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-xl);
}

.leaderboard-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--gray-800);
  margin-bottom: var(--spacing-lg);
}

/* Podium */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-xl);
  padding: 0 var(--spacing-md);
}

.podium-item {
  text-align: center;
  flex: 1;
  max-width: 100px;
}

.podium-avatar {
  font-size: 2.5rem;
  margin-bottom: var(--spacing-xs);
}

.podium-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: var(--spacing-xs);
}

.podium-score {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: var(--spacing-sm);
}

.podium-stand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--white);
  padding: var(--spacing-sm);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.podium-item.first .podium-stand {
  background: linear-gradient(135deg, #EAB308 0%, #FCD34D 100%);
  padding: var(--spacing-lg) var(--spacing-sm);
}

.podium-item.second .podium-stand {
  background: linear-gradient(135deg, #94A3B8 0%, #CBD5E1 100%);
  padding: var(--spacing-md) var(--spacing-sm);
}

.podium-item.third .podium-stand {
  background: linear-gradient(135deg, #D97706 0%, #F59E0B 100%);
  padding: var(--spacing-sm);
}

/* Leaderboard Table */
.leaderboard-table-wrapper {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: var(--spacing-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
}

.leaderboard-table th {
  background: var(--gray-50);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.leaderboard-table td {
  border-top: 1px solid var(--gray-100);
  font-weight: 500;
}

.leaderboard-table tr.current-player {
  background: rgba(124, 58, 237, 0.1);
}

.leaderboard-table tr.current-player td {
  color: var(--primary);
  font-weight: 700;
}

.leaderboard-table .rank-cell {
  font-weight: 700;
  color: var(--gray-400);
  width: 50px;
}

.leaderboard-table .score-cell {
  text-align: right;
  font-weight: 700;
  color: var(--primary);
}

.progress-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--gray-500);
  margin-left: var(--spacing-xs);
}

.current-player .progress-badge {
  background: rgba(124, 58, 237, 0.15);
  color: var(--primary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
  :root {
    font-size: 15px;
  }
  
  body {
    background: var(--white);
  }
  
  #app {
    padding: 0;
    align-items: stretch;
  }
  
  .screen {
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  /* Game screen full height on mobile */
  #game-screen.active {
    display: flex;
    flex-direction: column;
  }
  
  .game-container {
    border-radius: 0;
    box-shadow: none;
    padding: var(--spacing-md);
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  .photo-container {
    max-height: 45vh;
    border-radius: var(--radius-lg);
  }
  
  .question-text {
    font-size: 1.25rem;
  }
  
  .game-header {
    margin-bottom: var(--spacing-md);
  }
  
  .hearts-display {
    margin-bottom: var(--spacing-md);
  }
  
  .heart {
    font-size: 1.5rem;
  }
  
  /* Start screen */
  .start-container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  
  /* Finish screen */
  .finish-container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  
  /* Leaderboard screen */
  .leaderboard-container {
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--spacing-md);
  }
  
  .leaderboard-table-wrapper {
    max-height: 35vh;
  }
  
  .podium-item {
    max-width: 90px;
  }
  
  .podium-avatar {
    font-size: 2rem;
  }
  
  .podium-name {
    font-size: 0.75rem;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  :root {
    font-size: 14px;
  }
  
  .photo-container {
    max-height: 40vh;
  }
  
  .btn-submit {
    width: 48px;
    height: 48px;
  }
  
  .guess-input {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

