input, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Password Toggle */
.password-toggle {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--text-secondary);
  transition: color 0.2s ease;
  min-height: 32px;
  min-width: 32px;
}

@media (hover: hover) {
  .password-toggle:hover {
    color: var(--text-primary);
  }
}

.input-group {
  position: relative;
}

/* Error Messages - Desktop: Icon only, Mobile: Text */
@media (min-width: 769px) {
  /* Desktop: Hide text error messages to prevent layout shifts */
  #authModal .error-message {
    display: none !important;
  }
  
  /* Error states handled by modal CSS with icons */
}

@media (max-width: 768px) {
  /* Mobile: Keep text error messages for better accessibility */
  .error-message {
    display: block;
    color: var(--color-rust);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  
  .error-message.visible {
    opacity: 1;
  }
}

input.error {
  border-color: var(--color-rust);
}

/* Password Strength Indicator */
.password-strength-indicator {
  margin-top: var(--space-2);
}

.password-strength-bar {
  height: 4px;
  background: var(--color-sage-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-1);
}

.password-strength-fill {
  height: 100%;
  width: 0;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.password-strength-fill.strength-weak {
  background-color: var(--color-rust);
}

.password-strength-fill.strength-medium {
  background-color: var(--color-gold);
}

.password-strength-fill.strength-strong {
  background-color: var(--color-sage);
}

.password-strength-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* Loading State */
.loading input,
.loading button {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  margin-right: var(--space-2);
}

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

/* Story Form */
.story-form-section {
  max-width: 800px;
  margin: 0 auto;
}

.story-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.form-step {
  opacity: 1;
  transform: translateY(0);
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: var(--space-12);
}

.form-step:first-of-type {
  padding-top: var(--space-1);
}

.form-step.hidden {
  display: none;
}

.step-title {
  font-size: var(--text-xl);
  text-align: center;
  color: var(--color-charcoal);
  margin-bottom: var(--space-8);
  font-family: var(--font-heading);
}

/* When keywords are shown above, add breathing room before the title */
.form-step .keywords-section-compact + .step-title {
  margin-top: var(--space-6);
}

/* Legacy form support */
.form-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  position: relative;
  margin-bottom: var(--space-8);
  transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.section-title {
  font-size: var(--text-2xl);
  text-align: center;
  color: var(--color-charcoal);
  margin-bottom: var(--space-2);
}

/* Input Groups */
.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.input-group label {
  font-weight: 500;
  color: var(--color-charcoal);
}

.input-group input {
  padding: var(--space-3);
  border: 2px solid var(--color-stone);
  border-radius: var(--radius-lg);
  background: var(--color-linen);
  transition: border-color 0.2s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--color-sage);
  box-shadow: 0 0 0 3px rgba(168, 181, 160, 0.1);
}

.input-help {
  font-size: var(--text-xs);
  color: var(--color-gray-soft);
}

.magical-label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.label-text {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-charcoal);
}

.character-guidance {
  font-size: var(--text-sm);
  color: var(--color-sage);
  font-style: italic;
  min-height: var(--text-sm);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.magical-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.magical-input {
  width: 100%;
  padding: var(--space-5) var(--space-6);
  border: 2px solid var(--color-stone);
  border-radius: var(--radius-xl);
  background: var(--color-cream);
  font-size: var(--text-lg);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  position: relative;
}

.magical-input:focus {
  outline: none;
  border-color: var(--color-sage);
  background: rgba(253, 251, 247, 0.98);
  box-shadow: 
    0 0 0 4px rgba(168, 181, 160, 0.2),
    0 0 16px rgba(168, 181, 160, 0.15),
    inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Enhanced focus state for desktop only */
@media (min-width: 768px) and (hover: hover) {
  .magical-input:focus {
    box-shadow: 
      0 0 0 4px rgba(168, 181, 160, 0.2),
      0 8px 24px rgba(168, 181, 160, 0.15),
      inset 0 2px 4px rgba(0, 0, 0, 0.05);
  }
}

.input-clear-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-gray-soft);
  color: white;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.3s ease;
  opacity: 0.7;
}

@media (hover: hover) {
  .input-clear-btn:hover {
    background: var(--color-charcoal);
    opacity: 1;
    transform: scale(1.1);
  }
}

.input-clear-btn.visible {
  display: flex;
}

.magical-help {
  margin-top: var(--space-3);
  color: var(--color-gray-warm);
  font-style: italic;
}

.personalisation-label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.personalisation-note {
  font-size: var(--text-sm);
  color: var(--color-gray-soft);
  font-weight: 400;
}

.name-input {
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.name-input:focus {
  border-color: var(--color-sage);
  box-shadow: 0 0 0 3px rgba(168, 181, 160, 0.15);
}

#authForm {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

#authForm .input-group {
  margin-bottom: 0; /* Remove any default margin */
}

/* Desktop Auth Form - Simple and Clean */
@media (min-width: 769px) {
  /* Simplified input groups */
  #authForm .input-group {
    position: relative;
    margin-bottom: var(--space-3);
  }
  
  #authForm .input-group input {
    width: 100%;
    box-sizing: border-box;
    /* Styles handled in modal CSS */
  }
  
}

#authNameGroup {
  animation: slideIn 0.3s ease-out;
}

.settings-form, .contact-form {
  max-width: 400px;
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 500;
  color: var(--color-charcoal);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--color-stone);
  border-radius: var(--radius);
  font-size: var(--text-base);
  transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-sage);
}

.form-group textarea {
  resize: vertical;
  min-height: 120px;
}

.form-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-6);
}

/* Mobile touch target optimization for forms - 48px minimum */
@media (max-width: 768px) {
  .password-toggle {
    min-height: 48px;
    min-width: 48px;
    padding: var(--space-3);
  }
  
  .input-clear-btn {
    width: 48px;
    height: 48px;
    font-size: 16px;
    position: absolute;
    right: var(--space-2);
    top: 50%;
    transform: translateY(-50%);
  }
  
  .form-group input,
  .form-group select,
  .form-group textarea,
  .magical-input,
  .name-input {
    min-height: 48px;
    padding: var(--space-4) var(--space-4);
    font-size: var(--text-mobile-button);
  }
  
  .magical-input {
    padding: var(--space-4) var(--space-5);
    min-height: 56px;
  }
  
  /* Enhanced touch feedback for mobile form elements */
  .form-group input:active,
  .form-group select:active,
  .magical-input:active {
    transform: scale(0.99);
    transition: transform 0.1s ease;
  }
  
  /* Better spacing between form elements on mobile */
  .form-group {
    margin-bottom: var(--space-5);
  }
  
  .input-group {
    gap: var(--space-2);
  }
}
