/* ==========================================================================
   IQ Gen — Stylesheet
   ========================================================================== */

/* --- Google Fonts --- */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Serif+Display&display=swap");

/* --- Design Tokens --- */
:root {
  --bg: #F5F4F0;
  --surface: #FFFFFF;
  --accent: #1A1A2E;
  --highlight: #E8642A;
  --highlight-hover: #d1561f;
  --muted: #6B6B6B;
  --border: #E2E0DC;
  --error: #c0392b;
  --error-bg: #fdf0ef;
  --success: #27ae60;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 16px rgba(26, 26, 46, 0.06);
  --shadow-lg: 0 8px 32px rgba(26, 26, 46, 0.10);
  --transition: 0.25s ease;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-heading: "DM Serif Display", Georgia, serif;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1E1E1E;
  --accent: #EAEAEA;
  --highlight: #E8642A;
  --highlight-hover: #F27841;
  --muted: #A0A0A0;
  --border: #333333;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--accent);
  background-color: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Layout --- */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

@media (min-width: 640px) {
  .container {
    padding: 4rem 2rem 6rem;
  }
}

/* ==========================================================================
   Header Controls (Theme Toggle)
   ========================================================================== */

.header-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(26, 26, 46, 0.05);
}

[data-theme="dark"] .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
}

.theme-toggle .sun-icon {
  display: none;
}

.theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* ==========================================================================
   Settings Panel
   ========================================================================== */

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 2.5rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--transition);
}

.settings-toggle:hover {
  color: var(--accent);
}

.settings-toggle__icon {
  display: inline-flex;
  transition: transform var(--transition);
  font-size: 1rem;
}

.settings-panel.is-open .settings-toggle__icon {
  transform: rotate(90deg);
}

.settings-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.35s ease;
  padding: 0 1.25rem;
}

.settings-panel.is-open .settings-body {
  max-height: 200px;
  padding: 0 1.25rem 1.25rem;
}

.settings-body label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.375rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.settings-row {
  display: flex;
  gap: 0.625rem;
  align-items: stretch;
}

.api-key-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: "DM Sans", monospace;
  font-size: 0.875rem;
  color: var(--accent);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.api-key-input:focus {
  border-color: var(--highlight);
  box-shadow: 0 0 0 3px rgba(232, 100, 42, 0.12);
}

.btn-save-key {
  padding: 0.625rem 1rem;
  background: var(--accent);
  color: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), transform var(--transition);
}

.btn-save-key:hover {
  background: #2d2d4a;
  transform: translateY(-1px);
}

.key-status {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--success);
  opacity: 0;
  transition: opacity var(--transition);
}

.key-status.is-visible {
  opacity: 1;
}

.key-status.is-error {
  color: var(--error);
}

/* ==========================================================================
   Hero / Header
   ========================================================================== */

.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 1.75rem;
}

.header-logo {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.3s ease;
  filter: drop-shadow(0 8px 24px rgba(232, 100, 42, 0.35));
}

.header-logo:hover {
  transform: scale(1.08) rotate(1.5deg);
  filter: drop-shadow(0 14px 36px rgba(232, 100, 42, 0.6));
}

.hero h1 {
  font-family: var(--font-heading);
  font-size: 2.75rem;
  font-weight: 400;
  color: var(--accent);
  line-height: 1.15;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
}

.hero h1 .accent-dot {
  color: var(--highlight);
}

.subtitle {
  font-size: 1.0625rem;
  color: var(--muted);
  font-weight: 400;
  max-width: 400px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .hero h1 {
    font-size: 3.25rem;
  }
}

/* ==========================================================================
   Form
   ========================================================================== */

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.375rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--accent);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  box-shadow: var(--shadow);
}

.form-input:focus {
  border-color: var(--highlight);
  box-shadow: 0 0 0 4px rgba(232, 100, 42, 0.10);
}

.form-input.has-error {
  border-color: var(--error);
  box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.08);
}

.validation-message {
  min-height: 1.25rem;
  font-size: 0.8125rem;
  color: var(--error);
  margin-top: 0.375rem;
  transition: opacity var(--transition);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-primary {
  flex: 1;
  padding: 0.875rem 1.5rem;
  background: var(--highlight);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(232, 100, 42, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--highlight-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(232, 100, 42, 0.30);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  padding: 0.875rem 1.5rem;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(26, 26, 46, 0.03);
  transform: translateY(-1px);
}

.btn-retry {
  padding: 0.625rem 1.25rem;
  background: var(--surface);
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.btn-retry:hover {
  background: var(--error);
  color: var(--surface);
}

/* ==========================================================================
   Results Area
   ========================================================================== */

#results {
  margin-top: 2rem;
}

/* ==========================================================================
   Question Cards
   ========================================================================== */

.question-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--highlight);
  box-shadow: var(--shadow);
  opacity: 0;
  animation: fadeInUp 0.5s ease forwards;
  transition: box-shadow var(--transition), transform var(--transition);
}

.question-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.question-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--primary-color);
  color: white;
  border-radius: 2rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-copy.is-success {
  background: #10b981;
  border-color: #10b981;
  color: white;
}

.question-number {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.question-text {
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--accent);
}

/* ==========================================================================
   Export Area
   ========================================================================== */

.export-container {
  display: flex;
  justify-content: center;
  margin-top: 2.5rem;
  opacity: 0;
  animation: fadeInUp 0.5s ease forwards;
}

.btn-export {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1.75rem;
  font-weight: 600;
  color: var(--accent);
  background-color: transparent;
  border: 2px solid var(--border);
}

.btn-export:hover {
  background-color: rgba(26, 26, 46, 0.03);
  border-color: var(--accent);
  color: var(--accent);
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

*:focus-visible {
  outline: 2px solid var(--highlight);
  outline-offset: 3px;
  border-radius: inherit;
}

/* ==========================================================================
   Skeleton Loading Cards
   ========================================================================== */

.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--border);
  box-shadow: var(--shadow);
  animation: pulse 1.8s ease-in-out infinite;
}

.skeleton-line {
  height: 0.75rem;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--border) 37%,
    var(--surface) 63%
  );
  background-size: 800px 100%;
  animation: shimmer 1.6s linear infinite;
  margin-bottom: 0.75rem;
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-line--long {
  width: 90%;
}

.skeleton-line--medium {
  width: 70%;
}

.skeleton-line--short {
  width: 45%;
}

/* ==========================================================================
   Error Banner
   ========================================================================== */

.error-banner {
  background: var(--error-bg);
  border: 1px solid rgba(192, 57, 43, 0.15);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  animation: fadeInUp 0.35s ease forwards;
}

.error-banner__content {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.error-banner__icon {
  flex-shrink: 0;
  color: var(--error);
  margin-top: 0.125rem;
}

.error-banner__message {
  font-size: 0.9375rem;
  color: var(--error);
  line-height: 1.5;
}

/* ==========================================================================
   Animations
   ========================================================================== */

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

@keyframes shimmer {
  0% {
    background-position: -400px 0;
  }
  100% {
    background-position: 400px 0;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  text-align: center;
  padding-top: 3rem;
  margin-top: 2rem;
  border-top: 1px solid var(--border);
}

.footer p {
  font-size: 0.8125rem;
  color: var(--muted);
}

.footer a {
  color: var(--highlight);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.footer a:hover {
  color: var(--highlight-hover);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
  .hero h1 {
    font-size: 2.25rem;
  }

  .subtitle {
    font-size: 0.9375rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
  }

  .question-card {
    padding: 1.25rem;
  }

  .settings-row {
    flex-direction: column;
  }
}

/* ==========================================================================
   Info Banners (Cache, Warnings) & Slow Network UX
   ========================================================================== */

.info-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
  animation: fadeInUp 0.35s ease forwards;
  box-shadow: var(--shadow);
}

.info-banner--cache {
  background: rgba(39, 174, 96, 0.08);
  border: 1px solid rgba(39, 174, 96, 0.2);
  color: var(--success);
}

[data-theme="dark"] .info-banner--cache {
  background: rgba(39, 174, 96, 0.12);
}

.info-banner--warning {
  background: rgba(232, 100, 42, 0.08);
  border: 1px solid rgba(232, 100, 42, 0.2);
  color: var(--highlight);
}

[data-theme="dark"] .info-banner--warning {
  background: rgba(232, 100, 42, 0.12);
}

.btn-text-action {
  background: none;
  border: none;
  color: var(--highlight);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-left: 0.5rem;
  transition: color var(--transition);
}

.btn-text-action:hover {
  color: var(--highlight-hover);
}

.slow-network-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  animation: fadeInUp 0.3s ease forwards;
}

.spinner-small {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--highlight);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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