/**
 * SPAS v3.1 — Scalp Part-line Adaptive System
 * Mobile-first, Apple-inspired, camera-first design
 */

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

:root {
  --bg: #000;
  --surface: #1c1c1e;
  --card: #2c2c2e;
  --ink: #ffffff;
  --body: #b0b0b5;
  --caption: #8e8e93;
  --border: rgba(255,255,255,0.08);
  --accent: #30d158;
  --accent-dim: #248a3d;
  --warn: #ff9f0a;
  --danger: #ff453a;
  --blue: #0a84ff;
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  background: var(--bg);
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap;
}

.hidden { display: none !important; }

/* ── Brand ── */
.brand {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 28px;
  transition: all 0.35s ease;
}

.brand.compact {
  position: relative;
  top: 0; left: 0;
  margin: 16px 16px 0;
  background: var(--card);
}

.brand-mark {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #34c759);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand strong { font-size: 15px; font-weight: 600; display: block; line-height: 1.1; }
.brand small { font-size: 11px; color: var(--caption); display: block; }

/* ── Camera Error ── */
.camera-error {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
}

.error-card {
  text-align: center;
  max-width: 320px;
}

.error-icon { font-size: 64px; margin-bottom: 16px; }
.error-card h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.error-card p { color: var(--body); font-size: 15px; line-height: 1.5; margin-bottom: 24px; }

/* ── Scan View ── */
.scan-view {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex; flex-direction: column;
}

.camera-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-container canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0; pointer-events: none;
}

/* ── Scan Overlay ── */
.scan-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}

.scan-frame {
  position: absolute;
  width: min(280px, 78vw);
  height: min(360px, 88vh);
  border-radius: 20px;
}

.scan-corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: rgba(255,255,255,0.55);
  border-style: solid;
  transition: border-color 0.3s;
}

.scan-corner.tl { top: 0; left: 0; border-width: 2.5px 0 0 2.5px; border-radius: 20px 0 0 0; }
.scan-corner.tr { top: 0; right: 0; border-width: 2.5px 2.5px 0 0; border-radius: 0 20px 0 0; }
.scan-corner.bl { bottom: 0; left: 0; border-width: 0 0 2.5px 2.5px; border-radius: 0 0 0 20px; }
.scan-corner.br { bottom: 0; right: 0; border-width: 0 2.5px 2.5px 0; border-radius: 0 0 20px 0; }

/* Guidance */
.guidance-arrow {
  font-size: 32px;
  color: rgba(255,255,255,0.9);
  margin-bottom: 8px;
  transition: all 0.3s ease;
  text-shadow: 0 0 20px rgba(48,209,88,0.4);
}

.guidance-arrow.good { color: var(--accent); }
.guidance-arrow.center { color: var(--accent); animation: pulse 0.8s ease-in-out infinite; }
.guidance-arrow.looking { animation: spin 2s linear infinite; }
.guidance-arrow.slow { color: var(--warn); }
.guidance-arrow.far, .guidance-arrow.close { color: var(--warn); }

.guidance-text {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-align: center;
  max-width: 260px;
  line-height: 1.4;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

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

/* ── Stats Bar ── */
.stats-bar {
  position: absolute;
  bottom: max(100px, env(safe-area-inset-bottom, 100px) + 20px);
  left: 16px; right: 16px;
  display: flex; align-items: center;
  gap: 12px;
}

.stat {
  display: flex; flex-direction: column;
  align-items: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-width: 64px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
}

.stat-value.low { color: var(--warn); }

.stat-label {
  font-size: 11px;
  color: var(--caption);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.progress-wrap {
  flex: 1;
  display: flex; align-items: center;
}

.progress-track {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #34c759);
  border-radius: 2px;
  transition: width 0.25s ease;
}

/* ── Stop Button ── */
.stop-button {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 14px 28px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 32px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  white-space: nowrap;
}

.stop-button:active { background: rgba(255,255,255,0.2); transform: translateX(-50%) scale(0.97); }

/* ── Primary Button ── */
.primary-button {
  padding: 14px 32px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.primary-button:active { background: #2db84d; transform: scale(0.97); }

/* ── Secondary Button ── */
.secondary-button {
  padding: 13px 28px;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid rgba(48,209,88,0.4);
  border-radius: 30px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  display: block;
  margin: 0 auto;
}

.secondary-button:active { background: rgba(48,209,88,0.1); }

/* ── Result View ── */
.result-view {
  padding: 16px 16px max(40px, env(safe-area-inset-bottom, 40px));
  animation: fadeIn 0.4s ease;
}

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

/* Profile overview */
.profile-overview {
  text-align: center;
  padding: 24px 0 20px;
}

.confidence-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

.confidence-badge.high { background: rgba(48,209,88,0.15); color: var(--accent); }
.confidence-badge.medium { background: rgba(255,159,10,0.15); color: var(--warn); }
.confidence-badge.low { background: rgba(255,69,58,0.15); color: var(--danger); }

.profile-overview h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.profile-summary { color: var(--caption); font-size: 14px; }

/* Result sections */
.result-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.section-title { margin-bottom: 16px; }
.section-title span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--accent); font-weight: 600; display: block; margin-bottom: 4px; }
.section-title h2 { font-size: 18px; font-weight: 600; }

/* SCV Grid */
.scv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.scv-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex; flex-direction: column;
  gap: 8px;
}

.scv-bar-wrap { width: 100%; height: 5px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
.scv-bar { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

.scv-item:nth-child(1) .scv-bar { background: linear-gradient(90deg, #30d158, #34c759); }
.scv-item:nth-child(2) .scv-bar { background: linear-gradient(90deg, #ff9f0a, #ffb340); }
.scv-item:nth-child(3) .scv-bar { background: linear-gradient(90deg, #ff453a, #ff6b60); }
.scv-item:nth-child(4) .scv-bar { background: linear-gradient(90deg, #0a84ff, #40a0ff); }
.scv-item:nth-child(5) .scv-bar { background: linear-gradient(90deg, #bf5af2, #d080ff); }
.scv-item:nth-child(6) .scv-bar { background: linear-gradient(90deg, #30d158, #5ee880); }

.scv-label { font-size: 12px; color: var(--caption); }
.scv-value { font-size: 20px; font-weight: 700; }

/* Insight Cards */
.insight-grid { display: flex; flex-direction: column; gap: 12px; }

.insight-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  border-left: 3px solid var(--accent);
}

.insight-icon { font-size: 24px; margin-bottom: 8px; }
.insight-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.insight-card p { font-size: 13px; color: var(--body); line-height: 1.5; }

/* Action List */
.action-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.action-list li {
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
  position: relative;
  padding-left: 36px;
}

.action-list li::before {
  content: '→';
  position: absolute; left: 12px;
  color: var(--accent);
  font-weight: 700;
}

/* Observation Grid */
.observation-grid { display: flex; flex-direction: column; gap: 14px; }

.obs-row {
  display: flex; align-items: center;
  gap: 12px;
}

.obs-label { font-size: 13px; color: var(--body); width: 100px; flex-shrink: 0; text-align: right; }
.obs-bar-wrap { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
.obs-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.6s ease; }
.obs-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; color: var(--accent); }

/* Disclaimer */
.disclaimer {
  text-align: center;
  color: var(--caption);
  font-size: 12px;
  line-height: 1.5;
  padding: 16px;
  margin: 16px 0;
}

/* Build version */
.build-version {
  text-align: center;
  padding: 12px 0 24px;
  color: var(--caption);
  font-size: 11px;
  opacity: 0.5;
}

/* ── Responsive ── */
@media (min-width: 768px) {
  .result-view {
    max-width: 600px;
    margin: 0 auto;
    padding-top: 24px;
  }
  .scan-frame {
    width: 320px;
    height: 400px;
  }
}

@media (min-width: 1024px) {
  .result-view { max-width: 680px; }
  .scv-grid { grid-template-columns: 1fr 1fr 1fr; }
}
