/* ==============================================
   Profiles Module - PIN-based Profile Switching
   ============================================== */

/* Profile button in header */
.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  min-height: var(--touch-target-min);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.profile-btn:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.profile-btn-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 600;
  flex-shrink: 0;
}

.profile-btn-name {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Simple profile link for header (compact version) */
.profile-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--font-sm);
  font-weight: 500;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  transition: color var(--transition-fast);
}

.profile-link:hover {
  color: var(--accent);
}

.profile-link-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xs);
  font-weight: 600;
  flex-shrink: 0;
}

.profile-link-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-btn-select {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Sign in button (for free users) */
.sign-in-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  min-height: var(--touch-target-min);
  border-radius: var(--radius-lg);
  border: 2px solid var(--accent);
  background: var(--accent);
  color: white;
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.sign-in-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-accent-sm);
}

.sign-in-btn svg {
  flex-shrink: 0;
}

.sign-in-btn span {
  font-size: var(--font-sm);
}

/* Modal overlay */
.profile-overlay {
  position: fixed;
  z-index: 10000;
}

/* Modal base - theme-aware */
.profile-modal {
  border: none;
  border-radius: var(--radius-xl, 16px);
  padding: 0;
  background: var(--bg-secondary, #1a222d);
  color: var(--text-primary, #e2e8f0);
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.profile-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.profile-modal-content {
  padding: 28px;
}

/* Title */
.profile-title {
  margin: 0 0 var(--space-sm, 8px);
  font-size: var(--font-xl, 20px);
  font-weight: 600;
  text-align: center;
  color: var(--text-primary, #e2e8f0);
}

/* Profile cards */
.profile-cards {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  justify-content: center;
}

.profile-card {
  flex: 1;
  max-width: 140px;
  padding: var(--space-lg) var(--space-md);
  border-radius: var(--radius-xl);
  border: 2px solid var(--border);
  background: var(--bg-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.profile-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xl);
  font-weight: 600;
}

.profile-name {
  font-size: var(--font-base);
  font-weight: 500;
  color: var(--text-primary);
}

/* PIN Section */
.pin-section {
  text-align: center;
  padding-top: var(--space-md);
}

.pin-label {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin: 0 0 var(--space-lg);
}

.pin-profile-name {
  color: var(--accent);
  font-weight: 600;
}

/* PIN dots */
.pin-dots {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all var(--transition-fast);
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

/* Shake animation for wrong PIN */
.pin-dots.shake {
  animation: shake 0.5s ease;
}

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

/* PIN error message */
.pin-error {
  color: var(--error);
  font-size: var(--font-sm);
  margin-bottom: var(--space-md);
}

/* PIN keypad */
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  max-width: 220px;
  margin: 0 auto var(--space-lg);
}

.pin-key {
  width: 60px;
  height: 52px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-lg);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-key:hover {
  background: var(--border);
}

.pin-key:active {
  transform: scale(0.95);
  background: var(--accent);
  color: white;
}

.pin-back,
.pin-clear {
  font-size: var(--font-base);
  color: var(--text-muted);
}

/* PIN cancel button */
.pin-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--font-sm);
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
}

.pin-cancel:hover {
  color: var(--text-primary);
}

/* Setup Modal */
.setup-content {
  max-width: 320px;
}

.setup-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-sm);
  margin: 0 0 var(--space-lg);
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.setup-profile {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.setup-profile label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setup-profile input[type="text"],
.setup-profile input[type="password"] {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
}

.setup-profile input:focus {
  outline: none;
  border-color: var(--accent);
}

.setup-pin-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.setup-pin-row span {
  font-size: var(--font-sm);
  color: var(--text-muted);
  min-width: 35px;
}

.setup-pin-row input {
  flex: 1;
  text-align: center;
  letter-spacing: 4px;
}

.setup-error {
  color: var(--error);
  font-size: var(--font-sm);
  text-align: center;
  margin-bottom: var(--space-md);
}

.setup-submit {
  width: 100%;
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  border: none;
  background: var(--gradient-primary);
  color: white;
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.setup-submit:hover {
  opacity: 0.9;
}

.setup-submit:active {
  transform: scale(0.98);
}

/* Edit Name Modal */
.edit-content {
  text-align: center;
}

.edit-content input {
  width: 100%;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
  margin: var(--space-md) 0;
  text-align: center;
  box-sizing: border-box;
}

.edit-content input:focus {
  outline: none;
  border-color: var(--accent);
}

.edit-actions {
  display: flex;
  gap: var(--space-md);
}

.edit-save {
  flex: 1;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.edit-cancel {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

/* Light mode adjustments - triggered by theme toggle checkbox */
body:has(#theme-toggle:checked) .profile-modal {
  background: #ffffff;
}

body:has(#theme-toggle:checked) .profile-card,
body:has(#theme-toggle:checked) .pin-key {
  background: #f8fafc;
}

body:has(#theme-toggle:checked) .setup-profile input,
body:has(#theme-toggle:checked) .edit-content input {
  background: #f8fafc;
}

/* ==============================================
   Profile Panel (dropdown with stats)
   ============================================== */

#profile-button-container {
  position: relative;
}

.profile-panel {
  position: absolute;
  top: calc(100% + var(--space-sm, 8px));
  right: 0;
  width: 280px;
  background: var(--bg-secondary, #1a222d);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-fast);
  z-index: 1000;
  overflow: hidden;
}

.profile-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.profile-panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.1));
  border-bottom: 1px solid var(--border);
}

.profile-panel-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-lg);
  font-weight: 600;
  flex-shrink: 0;
}

.profile-panel-info {
  flex: 1;
  min-width: 0;
}

.profile-panel-name {
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-panel-level {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

/* XP Bar in panel */
.profile-panel-xp {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.profile-xp-bar-container {
  height: 8px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-sm);
}

.profile-xp-bar {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-sm);
  transition: width var(--transition-normal);
  width: 0%;
}

.profile-xp-text {
  font-size: var(--font-xs);
  color: var(--text-muted);
  text-align: right;
}

/* Streak display */
.profile-panel-streak {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-sm);
  color: var(--warning);
  border-bottom: 1px solid var(--border);
  display: none;
}

/* Daily challenge */
.profile-panel-challenge {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  display: none;
}

.profile-panel-challenge .challenge-label {
  font-size: var(--font-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.profile-panel-challenge .challenge-text {
  font-size: var(--font-sm);
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.profile-panel-challenge .challenge-bar-container {
  height: 6px;
  background: var(--bg-card);
  border-radius: var(--radius-xs);
  overflow: hidden;
  margin-bottom: var(--space-xs);
}

.profile-panel-challenge .challenge-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #16a34a);
  border-radius: var(--radius-xs);
  transition: width var(--transition-normal);
}

.profile-panel-challenge .challenge-progress {
  font-size: var(--font-xs);
  color: var(--text-muted);
  text-align: right;
}

.profile-panel-challenge .challenge-complete {
  color: var(--success);
  font-size: var(--font-sm);
  font-weight: 500;
}

/* Badges */
.profile-panel-badges {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-lg);
  letter-spacing: 4px;
  border-bottom: 1px solid var(--border);
  display: none;
}

/* Action buttons */
.profile-panel-actions {
  padding: var(--space-md);
  display: flex;
  gap: var(--space-sm);
}

.profile-action-btn {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: var(--font-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.profile-action-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.profile-action-btn.profile-action-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.profile-action-btn.profile-action-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Light mode for profile panel */
body:has(#theme-toggle:checked) .profile-panel {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

body:has(#theme-toggle:checked) .profile-panel-header {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.05));
}

/* Responsive */
@media (max-width: 400px) {
  .profile-modal-content {
    padding: 24px 20px;
  }

  .profile-cards {
    gap: 12px;
  }

  .profile-card {
    padding: 16px 12px;
  }

  .profile-avatar {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .pin-key {
    width: 52px;
    height: 46px;
    font-size: 18px;
  }

  .pin-keypad {
    gap: 8px;
  }
}
