/* ===== PSL Note — Design System ===== */
:root {
  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition: 200ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-display: 'Sora', 'Inter', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

/* ===== Dark theme (default) ===== */
[data-theme='dark'] {
  --bg: #0d0d0f;
  --surface: #161618;
  --surface-2: #1c1c20;
  --surface-offset: #222226;
  --border: #2e2e34;
  --divider: #2a2a30;
  --text: #f0f0f2;
  --text-muted: #8a8a92;
  --text-faint: #5a5a62;
  --accent: #f5c542;
  --accent-hover: #ffd755;
  --accent-dim: #d4a017;
  --accent-soft: rgba(245, 197, 66, 0.12);
  --danger: #e5484d;
  --success: #46a758;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 40px rgba(245, 197, 66, 0.15);
}

/* ===== Light theme ===== */
[data-theme='light'] {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f3f0ec;
  --surface-offset: #edeae5;
  --border: #d4d1ca;
  --divider: #dcd9d5;
  --text: #1a1a1d;
  --text-muted: #6a6a72;
  --text-faint: #9a9aa2;
  --accent: #b8860b;
  --accent-hover: #9a7209;
  --accent-dim: #d4a017;
  --accent-soft: rgba(184, 134, 11, 0.10);
  --danger: #c92a30;
  --success: #2d7a3a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 40px rgba(184, 134, 11, 0.10);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

img, picture, svg, canvas { display: block; max-width: 100%; height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; text-wrap: balance; }
p, li { text-wrap: pretty; }

a, button, input, textarea, select {
  transition: color var(--transition), background var(--transition),
              border-color var(--transition), box-shadow var(--transition);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

::selection { background: var(--accent-soft); color: var(--text); }

.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Layout ===== */
#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  padding: var(--space-6) var(--space-5);
  animation: fadeIn 0.3s var(--transition);
}

.screen.active { display: flex; }

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

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--divider);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
}

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:active { transform: scale(0.95); }

/* ===== Welcome Screen ===== */
.welcome-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-6);
  padding: var(--space-8) var(--space-4);
}

.welcome-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  border: 1px solid var(--accent-dim);
}

.welcome-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.welcome-title .accent { color: var(--accent); }

.welcome-desc {
  font-size: var(--text-base);
  color: var(--text-muted);
  max-width: 36ch;
  line-height: 1.65;
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 340px;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  text-align: left;
}

.feature-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.feature-text { flex: 1; }
.feature-text strong { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: 2px; }
.feature-text span { font-size: var(--text-xs); color: var(--text-muted); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  letter-spacing: -0.01em;
  transition: all var(--transition);
  min-height: 52px;
}

.btn-primary {
  background: var(--accent);
  color: #0d0d0f;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-lg), var(--shadow-glow); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary:active { transform: scale(0.98); }

.btn-ghost {
  color: var(--text-muted);
  padding: var(--space-3) var(--space-4);
}

.btn-ghost:hover { color: var(--accent); }

.btn-block { width: 100%; }

/* ===== Progress Bar ===== */
.progress-container {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: var(--radius-full);
  transition: width 0.4s var(--transition);
  width: 0%;
}

.progress-text {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ===== Question Screen ===== */
.category-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: var(--space-2);
}

.question-text {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
  line-height: 1.3;
}

.question-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  line-height: 1.5;
}

.question-body { flex: 1; }

/* Rating options */
.rating-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.rating-option {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}

.rating-option:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.rating-option:active { transform: scale(0.99); }

.rating-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rating-number {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--surface-offset);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  font-family: var(--font-display);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all var(--transition);
}

.rating-option.selected .rating-number {
  background: var(--accent);
  color: #0d0d0f;
}

.rating-option-label {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: 500;
}

.rating-option-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

/* ===== Photo Screen ===== */
.photo-instructions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}

.photo-instructions h3 {
  font-size: var(--text-base);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.photo-tips {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.photo-tips li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.photo-tips li::before {
  content: "✓";
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.photo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  margin-bottom: var(--space-4);
}

.photo-upload-area:hover { border-color: var(--accent); background: var(--surface-2); }
.photo-upload-area:active { transform: scale(0.99); }

.photo-upload-area.has-image { padding: var(--space-4); border-style: solid; border-color: var(--accent); }

.photo-upload-icon {
  color: var(--text-faint);
  margin-bottom: var(--space-3);
  display: flex;
  justify-content: center;
}

.photo-upload-area.has-image .photo-upload-icon { display: none; }

.photo-upload-title { font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--space-1); }
.photo-upload-desc { font-size: var(--text-xs); color: var(--text-muted); }

.photo-preview { width: 100%; max-height: 280px; object-fit: cover; border-radius: var(--radius-md); }

.photo-section-title {
  font-size: var(--text-base);
  font-weight: 700;
  font-family: var(--font-display);
  margin-bottom: var(--space-2);
}

.photo-section-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.photo-label-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: var(--space-2);
}

/* ===== Results Screen ===== */
.results-score-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.score-circle {
  width: 180px;
  height: 180px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-6);
}

.score-circle svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.score-circle .track { stroke: var(--surface-offset); }
.score-circle .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s var(--transition); }

.score-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 3.5rem;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
}

.score-value .max { font-size: 1.2rem; color: var(--text-muted); font-weight: 500; }

.psl-tier {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--text);
  margin-bottom: var(--space-1);
}

.psl-range {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.disclaimer {
  font-size: var(--text-xs);
  color: var(--text-faint);
  max-width: 32ch;
  line-height: 1.5;
  text-align: center;
}

/* Category breakdown */
.category-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.category-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.category-row-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.category-row-name { font-size: var(--text-sm); font-weight: 600; }
.category-row-score { font-size: var(--text-sm); font-weight: 700; font-family: var(--font-display); color: var(--accent); }

.category-bar {
  height: 8px;
  background: var(--surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: var(--radius-full);
  transition: width 0.8s var(--transition);
  width: 0%;
}

/* Potential score */
.potential-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}

.potential-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.potential-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.potential-title { font-size: var(--text-sm); font-weight: 700; font-family: var(--font-display); }
.potential-subtitle { font-size: var(--text-xs); color: var(--text-muted); }

.potential-score-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.potential-current { text-align: center; }
.potential-arrow { color: var(--text-faint); }
.potential-max { text-align: center; }

.potential-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-xl);
  line-height: 1;
}

.potential-num.current { color: var(--text); }
.potential-num.max { color: var(--accent); }

.potential-label { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }

/* Improvement suggestions */
.improvement-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.improvement-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.improvement-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
  font-size: var(--text-sm);
}

.improvement-text { flex: 1; }
.improvement-text strong { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: 2px; }
.improvement-text span { font-size: var(--text-xs); color: var(--text-muted); }

/* ===== Nav buttons ===== */
.nav-buttons {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--divider);
}

.nav-buttons .btn { flex: 1; }

/* ===== Analyzing overlay ===== */
.analyzing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 13, 15, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-8);
}

.analyzing-overlay.active { display: flex; }

.analyzing-spinner {
  width: 56px;
  height: 56px;
  border: 3px solid var(--surface-offset);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

.analyzing-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  text-align: center;
}

.analyzing-subtext {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  max-width: 30ch;
}

/* ===== Footer note ===== */
.footer-note {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: 1.5;
  max-width: 36ch;
  margin: 0 auto;
}

/* ===== Responsive ===== */
@media (min-width: 520px) {
  #app { box-shadow: var(--shadow-lg); }
}

@media (max-width: 360px) {
  .welcome-title { font-size: var(--text-xl); }
  .score-value { font-size: 2.8rem; }
  .score-circle { width: 150px; height: 150px; }
}
