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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3d;
  --accent: #00e676;
  --accent2: #7c4dff;
  --text: #e0e0e0;
  --muted: #888;
  --good: #00e676;
  --fair: #ffeb3b;
  --poor: #f44336;
  --radius: 12px;
  --bottom-safe: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px; /* prevent iOS auto-zoom */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Welcome carousel (Flutter start_assessment_screen_v2) ─────────────── */

#screen-welcome {
  /* light theme scoped */
  --wbg: #fafaf7;
  --wtext: #111;
  --wmuted: #4a4a4a;

  background: var(--wbg);
  color: var(--wtext);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 540px;
  margin: 0 auto;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0 calc(1rem + var(--bottom-safe));
}

/* Dots indicator — SmoothPageIndicator SlideEffect */
.welcome-dots {
  display: flex;
  gap: 8px;
  padding: 0.5rem 1.5rem 0.75rem;
}

.welcome-dot {
  flex: 1;
  height: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  transition: background 0.25s;
}

.welcome-dot.active { background: #111; }

/* Content area */
.welcome-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0 1.5rem;
}

.welcome-image {
  display: block;
  width: 80%;
  max-width: 320px;
  margin: 1rem auto 0;
  aspect-ratio: 1/1;
  object-fit: contain;
}

.welcome-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--wtext);
  margin-top: 1.5rem;
  text-align: left;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.welcome-desc {
  font-size: 1rem;
  color: var(--wmuted);
  margin-top: 0.75rem;
  line-height: 1.5;
  text-align: left;
  white-space: pre-line;
}

.welcome-actions {
  padding: 0.75rem 1.5rem 0;
}

#screen-welcome .btn-primary {
  width: 100%;
  background: #111;
  color: #fff;
  height: 54px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
}

/* ── Landing ──────────────────────────────────────────────────────────────── */

#screen-landing {
  --lbg: #fafaf7;
  --ltext: #111;
  --lmuted: #4a4a4a;

  background: var(--lbg);
  color: var(--ltext);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 540px;
  margin: 0 auto;
  padding: calc(1rem + env(safe-area-inset-top, 0px)) 1.5rem calc(1rem + var(--bottom-safe));
}

.landing-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem 0;
}

.landing-title {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ltext);
  margin-bottom: 0.75rem;
}

.landing-sub {
  font-size: 1rem;
  line-height: 1.5;
  color: var(--lmuted);
  margin-bottom: 2rem;
}

.landing-points {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.landing-point {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
}

.landing-point span {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}

.landing-point p {
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--ltext);
}

.landing-actions {
  padding-top: 0.5rem;
}

#screen-landing .btn-primary {
  width: 100%;
  background: #111;
  color: #fff;
  height: 54px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
}

/* ── Loader (analyzing) ───────────────────────────────────────────────────── */

#screen-loader {
  background: #fff;
  color: #111;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.loader-wrap {
  text-align: center;
  max-width: 320px;
}

.loader-gif {
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 1.5rem;
  display: block;
}

.loader-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #111;
  margin-bottom: 0.4rem;
  letter-spacing: -0.01em;
}

.loader-sub {
  font-size: 0.95rem;
  color: #6b7280;
}

/* ── Modals ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff;
  color: #111;
  border-radius: 16px;
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 0.4rem;
}

.modal-sub {
  font-size: 0.9rem;
  color: #6b7280;
  line-height: 1.4;
  margin-bottom: 1.25rem;
}

/* Gender picker */
.gender-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.gender-btn {
  width: 100%;
  height: 52px;
  border: 1.5px solid #d1d5db;
  background: #fff;
  color: #111;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.gender-btn:hover,
.gender-btn:focus-visible { border-color: #111; background: #fafaf7; outline: none; }
.gender-btn:active { transform: scale(0.98); }

/* Email form */
#form-email {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#form-email input[type="text"],
#form-email input[type="email"] {
  height: 48px;
  padding: 0 1rem;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  font-size: 1rem;
  color: #111;
  background: #fff;
  font-family: inherit;
  -webkit-appearance: none;
}

#form-email input[type="text"]:focus,
#form-email input[type="email"]:focus { border-color: #111; outline: none; }

.consent-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #374151;
  cursor: pointer;
}

.consent-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: #111;
  cursor: pointer;
}

.consent-row a { color: #111; text-decoration: underline; }

#btn-email-submit {
  margin-top: 0.4rem;
  background: #111;
  color: #fff;
  border: none;
  height: 54px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

#btn-email-submit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#btn-email-submit:not(:disabled):active { transform: scale(0.98); }

/* ── Capture ─────────────────────────────────────────────────────────────── */

#screen-capture {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.progress-bar {
  display: flex;
  gap: 4px;
  padding: 0.6rem 1rem 0.4rem;
  background: var(--bg);
  flex-shrink: 0;
}

.progress-bar .bar {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  position: relative;
  transition: background 0.25s;
}

.progress-bar .bar.done   { background: var(--accent); }
.progress-bar .bar.active { background: var(--accent); animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { opacity: 0.45; } }

.progress-bar .bar::after {
  content: attr(data-label);
  position: absolute;
  top: -14px; left: 0;
  font-size: 0.55rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.camera-wrapper {
  position: relative;
  flex: 1;
  min-height: 0; /* allow shrinking in flex */
  background: #000;
  overflow: hidden;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

#overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  transform: scaleX(-1);
}

/* Body silhouette guide — helps user frame themselves */
.body-guide {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 38%;
  height: 85%;
  border: 2px dashed rgba(255,255,255,0.18);
  border-radius: 60% 60% 40% 40% / 30% 30% 10% 10%;
  pointer-events: none;
}

/* Bottom panel: step info + button */
.capture-bottom {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.9rem 1.25rem calc(0.9rem + var(--bottom-safe));
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  flex-shrink: 0;
}

.step-info {
  text-align: center;
}

.step-info .step-count {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.15rem;
}

.step-info h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.step-info p {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.3;
}

#capture-status {
  font-size: 1.4rem;
  font-weight: 700;
  min-height: 2rem;
  text-align: center;
  color: var(--accent);
  line-height: 1;
}

/* ── Results (light theme, Flutter-style) ────────────────────────────────── */

#screen-results {
  /* Scoped light-theme overrides */
  --rbg: #fafaf7;
  --rsurface: #ffffff;
  --rtext: #111;
  --rmuted: #6b7280;
  --rborder: #e7e5df;
  --rgreen: #00a468;
  --rred: #dc2626;
  --ryellow: #f5b94a;

  min-height: 100dvh;
  background: var(--rbg);
  color: var(--rtext);
  padding: 0;
  max-width: 540px;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.results-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--rbg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn {
  background: none;
  border: none;
  color: var(--rtext);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  touch-action: manipulation;
}
.back-btn:active { background: rgba(0,0,0,0.05); }

.header-title {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
}

.header-spacer { width: 36px; }

/* Score intro */
.summary-section {
  padding: 0.5rem 1.25rem 1.5rem;
}

.score-intro {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--rtext);
  margin-bottom: 0.25rem;
}

#screen-results .score-value {
  font-size: 4.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ryellow);
  margin-bottom: 1rem;
}

#screen-results .score-value.good { color: var(--rgreen); }
#screen-results .score-value.fair { color: var(--ryellow); }
#screen-results .score-value.poor { color: var(--rred); }

.deviations-count {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--rtext);
  margin-bottom: 1.25rem;
  line-height: 1.3;
}

/* 2×2 captured photo grid */
.captured-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.photo-thumb {
  display: block; /* labels off — match Flutter clean grid */
}

.photo-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}

.photo-wrap img,
.photo-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror to read as natural selfie */
}
.photo-wrap canvas { pointer-events: none; }
.photo-thumb span { display: none; } /* hide caption per Flutter layout */

/* Share + Proceed buttons */
.btn-share, .btn-proceed {
  width: 100%;
  height: 52px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 0.75rem;
  touch-action: manipulation;
  transition: transform 0.1s, opacity 0.15s;
}
.btn-share  { background: #fff; color: #111; border: 1.5px solid #111; }
.btn-proceed{ background: #111; color: #fff; border: none; }
.btn-share:active, .btn-proceed:active { transform: scale(0.98); }

/* Diagnoses section */
.diagnoses-section {
  padding: 0.5rem 1.25rem 0.5rem;
  background: var(--rbg);
  border-top: 1px solid var(--rborder);
}

.diagnosis-cards {
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
  padding: 1rem 0;
}

.diag-card h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--rtext);
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

.diag-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.compare-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.compare-col figcaption {
  font-size: 0.95rem;
  font-weight: 700;
  order: -1; /* caption above image */
}
.compare-col.ideal figcaption { color: var(--rgreen); }
.compare-col.user  figcaption { color: var(--rtext); }

.compare-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #f0efec;
}

.compare-col.ideal .compare-img-wrap { border-color: var(--rgreen); background: #f4fbf7; }
.compare-col.user  .compare-img-wrap { border-color: var(--rred); background: #000; }

.compare-img-wrap img,
.compare-img-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
}

.compare-col.user .compare-img-wrap img,
.compare-col.user .compare-img-wrap canvas {
  object-fit: cover;
  transform: scaleX(-1);
}

.diag-desc {
  color: var(--rtext);
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 1rem;
}

.diag-info {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.diag-info strong {
  display: block;
  font-size: 0.95rem;
  color: var(--rtext);
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.diag-info p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #374151;
  white-space: pre-line;
}

.no-issues-big {
  text-align: center;
  padding: 2rem;
  background: var(--rsurface);
  border: 1px solid var(--rborder);
  border-radius: 12px;
  color: var(--rgreen);
  font-weight: 700;
  font-size: 1.05rem;
}

/* Score breakdown (dev-only, gated in JS) */
.breakdown-section {
  padding: 1rem 1.25rem 0.5rem;
  background: var(--rbg);
  border-top: 1px solid var(--rborder);
}

#screen-results .section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--rmuted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-tag {
  font-size: 0.6rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #ffeb3b;
  color: #111;
  letter-spacing: 0.05em;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--rborder);
  background: var(--rsurface);
  margin-bottom: 1.25rem;
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 320px;
  color: var(--rtext);
}

.breakdown-table th {
  text-align: left;
  padding: 0.55rem 0.75rem;
  background: #f5f4f0;
  color: var(--rmuted);
  font-weight: 600;
  border-bottom: 1px solid var(--rborder);
  white-space: nowrap;
}

.breakdown-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--rborder);
}

.breakdown-table tr:last-child td { border-bottom: none; }

.breakdown-table .score-cell { font-weight: 700; text-align: right; white-space: nowrap; }
.breakdown-table .score-cell.ok  { color: var(--rgreen); }
.breakdown-table .score-cell.bad { color: var(--rred); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 0;
  height: 52px;
  width: 100%;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-font-smoothing: antialiased;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 52px;
  width: 100%;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s;
}

.btn-secondary:active { border-color: var(--muted); }

/* ── Desktop overrides (≥ 600px) ─────────────────────────────────────────── */

@media (min-width: 600px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
  }

  #screen-capture {
    height: auto;
    max-width: 720px;
    width: 100%;
    gap: 1rem;
    padding: 1.5rem;
    overflow: visible;
  }

  .camera-wrapper {
    flex: none;
    aspect-ratio: 4/3;
    border-radius: var(--radius);
    border: 2px solid var(--border);
  }

  .body-guide { display: none; }

  .capture-bottom {
    background: transparent;
    border-top: none;
    padding: 0;
    gap: 0.75rem;
  }

  #capture-status { font-size: 2rem; min-height: 2.5rem; }

  .step-info h2 { font-size: 1.4rem; }
  .step-info p  { font-size: 0.95rem; }

  .btn-primary, .btn-secondary {
    width: auto;
    padding: 0 2.5rem;
    display: block;
    margin: 0 auto;
  }

  #screen-results {
    padding: 2rem;
  }
}
