:root {
  --bg: #0b1f33;
  --bg-soft: rgba(11, 31, 51, 0.82);
  --fg: #e8f0f8;
  --muted: #9bb0c4;
  --accent: #3db8ff;
  --danger: #e53935;
  --ok: #2ecc71;
  --line: rgba(255, 255, 255, 0.78);
  --line-dim: rgba(255, 255, 255, 0.38);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: #000;
}

/* Landing panel: hidden on phone (camera-first) */
.landing-panel {
  display: none;
}

.tool-column {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  background: #000;
}

.mobile-only-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.top-bar {
  flex: 0 0 auto;
  padding: calc(0.65rem + var(--safe-top)) 1rem 0.55rem;
  background: var(--bg-soft);
  backdrop-filter: blur(8px);
  z-index: 3;
}

.top-bar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.instructions {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--muted);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #102030;
  overflow: hidden;
}

#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  transform: scaleX(1); /* rear camera — no mirror */
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* enabled via .can-drag when camera is live */
  z-index: 2;
  touch-action: none;
}

#overlay.can-drag {
  pointer-events: none; /* visual only; drag-layer captures gestures */
}

.drag-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
  cursor: ns-resize;
  background: transparent;
}

.drag-layer[hidden] {
  display: none !important;
}

.drag-hint {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0.9;
}

.drag-hint[hidden] {
  display: none !important;
}

.drag-hint.is-dragging {
  background: rgba(61, 184, 255, 0.25);
  color: var(--accent);
  border: 1px solid rgba(61, 184, 255, 0.45);
}

body.is-pitch-dragging {
  user-select: none;
  -webkit-user-select: none;
}

.camera-prompt {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(11,31,51,0.55), rgba(11,31,51,0.85));
}

.camera-prompt[hidden],
.error-banner[hidden],
#stopBtn[hidden],
#secureHint[hidden] {
  display: none !important;
}

.camera-prompt p {
  margin: 0;
  max-width: 22rem;
  color: var(--fg);
  font-size: 0.95rem;
}

.hint {
  font-size: 0.78rem !important;
  color: #ffcc80 !important;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}

.btn.primary {
  background: var(--accent);
  color: #042033;
  box-shadow: 0 4px 18px rgba(61, 184, 255, 0.35);
}

.btn.primary:active { transform: scale(0.98); }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
}

.error-banner {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 5;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  background: rgba(180, 40, 40, 0.92);
  font-size: 0.85rem;
  line-height: 1.3;
}

.level-wrap {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  padding: 0.45rem 0.55rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.level-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  align-self: stretch;
  text-align: center;
}

.level-gauge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.level-axis {
  font-size: 0.6rem;
  color: var(--muted);
  width: 2.2rem;
}

.level-track {
  position: relative;
  width: 72px;
  height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  overflow: hidden;
}

.level-track.vertical {
  width: 14px;
  height: 72px;
}

.level-center {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: 50%;
  width: 10px;
  margin-left: -5px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.35);
  pointer-events: none;
}

.level-track.vertical .level-center {
  left: 1px;
  right: 1px;
  top: 50%;
  width: auto;
  height: 10px;
  margin-left: 0;
  margin-top: -5px;
}

.level-bubble {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  top: 1px;
  left: 50%;
  margin-left: -6px;
  transition: background 0.15s ease;
  will-change: transform;
}

.level-track.vertical .level-bubble {
  top: 50%;
  left: 1px;
  margin-left: 0;
  margin-top: -6px;
}

.level-wrap.plumb .level-bubble {
  background: var(--ok);
}

.level-status {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  min-height: 1em;
}

.level-wrap.plumb .level-status {
  color: var(--ok);
}

.bottom-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem calc(0.65rem + var(--safe-bottom));
  background: var(--bg-soft);
  backdrop-filter: blur(8px);
  z-index: 3;
}

.selected {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg);
}

.selected .pitch-num {
  color: var(--accent);
}

.selected .pitch-num.is-12 {
  color: var(--danger);
}

/* Overlay SVG — roof-peak (Λ) guide for selected pitch */
#overlay .pitch-line {
  fill: none;
  stroke: var(--line);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.95;
  transition: stroke 0.15s, opacity 0.15s, stroke-width 0.15s;
}

#overlay .pitch-line.neighbor {
  stroke: var(--line-dim);
  stroke-width: 1.25;
  opacity: 0.28;
}

#overlay .pitch-line.highlight {
  stroke: var(--accent);
  stroke-width: 3.25;
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(61, 184, 255, 0.45));
}

#overlay .pitch-line.pitch-12.highlight {
  stroke: #ff6b68;
  stroke-width: 3.5;
  filter: drop-shadow(0 0 5px rgba(229, 57, 53, 0.5));
}

#overlay .plumb-line {
  stroke: rgba(61, 184, 255, 0.55);
  stroke-width: 1.25;
  stroke-dasharray: 5 6;
  fill: none;
}

#overlay .ridge-cap {
  fill: var(--accent);
  stroke: none;
  opacity: 0.95;
}

#overlay .ridge-cap.pitch-12 {
  fill: #ff6b68;
}

#overlay .pitch-label {
  fill: rgba(255,255,255,0.95);
  font-size: 13px;
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.6);
  stroke-width: 3.5px;
  stroke-linejoin: round;
  pointer-events: none;
}

#overlay .pitch-label.pitch-12 {
  fill: #ff6b68;
  font-size: 14px;
  font-weight: 800;
}

#overlay .pitch-label.neighbor {
  fill: rgba(255,255,255,0.35);
  font-size: 10px;
  font-weight: 600;
  stroke-width: 2px;
}

@media (min-width: 600px) {
  .mobile-only-title { font-size: 1.35rem; }
  .top-bar h1 { font-size: 1.35rem; }
  .instructions { font-size: 0.88rem; }
}

/* Wide desktop: how-it-works beside a phone-sized tool frame */
@media (min-width: 900px) {
  html, body {
    overflow: auto;
    background: #071521;
  }

  #app {
    flex-direction: row;
    align-items: stretch;
    max-width: 1120px;
    height: auto;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
    gap: 1.75rem;
    background: transparent;
  }

  .landing-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1 1 52%;
    min-width: 0;
    padding: 1.25rem 0.5rem 1.25rem 0.75rem;
    color: var(--fg);
  }

  .landing-eyebrow {
    margin: 0 0 0.45rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
  }

  .landing-title {
    margin: 0 0 0.75rem;
    font-size: clamp(2rem, 3.2vw, 2.75rem);
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1.1;
  }

  .landing-lead {
    margin: 0 0 1.35rem;
    font-size: 1.05rem;
    line-height: 1.45;
    color: var(--muted);
    max-width: 34rem;
  }

  .landing-lead strong {
    color: var(--accent);
  }

  .how-steps {
    list-style: none;
    margin: 0 0 1.35rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    max-width: 34rem;
  }

  .how-steps li {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .how-num {
    flex: 0 0 auto;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 800;
    background: rgba(61, 184, 255, 0.18);
    color: var(--accent);
    border: 1px solid rgba(61, 184, 255, 0.35);
  }

  .how-steps strong {
    display: block;
    font-size: 0.98rem;
    margin-bottom: 0.15rem;
    color: var(--fg);
  }

  .how-steps span {
    display: block;
    font-size: 0.88rem;
    line-height: 1.35;
    color: var(--muted);
  }

  .trust-line {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-width: 34rem;
  }

  .tool-column {
    flex: 0 0 min(420px, 42vw);
    width: min(420px, 42vw);
    max-width: 440px;
    height: min(860px, calc(100dvh - 3rem));
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    background: #000;
  }

  .mobile-only-title {
    /* Landing has the big title; keep a compact tool chrome title */
    font-size: 1.05rem;
  }

  .result-sheet {
    max-width: min(420px, 42vw);
    /* Align under the tool column on the right */
    left: auto;
    right: max(1.25rem, calc((100vw - 1120px) / 2 + 1.25rem));
  }
}

@media (min-width: 1100px) {
  #app {
    max-width: 1180px;
    gap: 2.25rem;
  }
  .tool-column {
    flex-basis: 440px;
    width: 440px;
    max-width: 440px;
  }
  .result-sheet {
    max-width: 440px;
  }
}

/* —— Result sheet + lead form —— */
.result-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 0.75rem calc(0.75rem + var(--safe-bottom));
  pointer-events: none;
}

.result-sheet[hidden] {
  display: none !important;
}

.result-sheet-inner {
  pointer-events: auto;
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px 18px 14px 14px;
  padding: 1rem 1rem 1.1rem;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.45);
  max-height: min(78dvh, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.result-head {
  position: relative;
  text-align: center;
  margin-bottom: 0.85rem;
  padding-right: 1.5rem;
}

.result-label {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.result-pitch {
  margin: 0.2rem 0 0;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1.1;
}

.result-pitch.is-12 {
  color: #ff6b68;
}

.result-close {
  position: absolute;
  top: -0.25rem;
  right: -0.15rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.result-close:active {
  background: rgba(255, 255, 255, 0.16);
}

.btn.full {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 0.55rem;
}

#resultActions .btn.primary {
  margin-top: 0;
}

.share-status {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
  color: var(--ok);
  text-align: center;
}

.share-status[hidden],
.lead-form[hidden],
.thank-you[hidden],
.form-error[hidden] {
  display: none !important;
}

.lead-intro {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.35;
}

.lead-intro strong {
  color: var(--accent);
}

.lead-form .field {
  display: block;
  margin-bottom: 0.65rem;
}

.lead-form .field span {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.28rem;
}

.optional {
  font-style: normal;
  font-weight: 400;
  opacity: 0.85;
}

.lead-form input {
  width: 100%;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.35);
  color: var(--fg);
  outline: none;
}

.lead-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 184, 255, 0.25);
}

.lead-form input::placeholder {
  color: rgba(155, 176, 196, 0.55);
}

.form-error {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: rgba(180, 40, 40, 0.85);
  font-size: 0.8rem;
  line-height: 1.3;
}

.thank-you {
  text-align: center;
  padding: 0.35rem 0 0.25rem;
}

.thank-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ok);
}

.thank-body {
  margin: 0.45rem 0 0.85rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.4;
}

#app.has-result .bottom-bar {
  /* Keep footer usable but sheet sits above */
  padding-bottom: calc(0.4rem + var(--safe-bottom));
}


/* —— Bottom bar: pitch pills + legal links —— */
.bottom-bar {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  padding-top: 0.55rem;
}

.pitch-toolbar {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  min-width: 0;
}

.pitch-pills-wrap {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.pitch-pills {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.pitch-pills::-webkit-scrollbar {
  height: 3px;
}

.pitch-pills::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
}

.pitch-pill {
  flex: 0 0 auto;
  appearance: none;
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  min-height: 44px;
  min-width: 3.35rem;
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  scroll-snap-align: start;
  touch-action: manipulation;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}

.pitch-pill:active {
  transform: scale(0.97);
}

.pitch-pill[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #042033;
  box-shadow: 0 2px 12px rgba(61, 184, 255, 0.35);
}

.pitch-pill.is-12 {
  border-color: rgba(229, 57, 53, 0.55);
}

.pitch-pill.is-12[aria-selected="true"] {
  background: #e53935;
  border-color: #ff6b68;
  color: #fff;
  box-shadow: 0 2px 12px rgba(229, 57, 53, 0.4);
}

.auto-stub {
  flex: 0 0 auto;
  appearance: none;
  align-self: center;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  min-height: 44px;
  padding: 0.35rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  cursor: not-allowed;
  opacity: 0.7;
  max-width: 3.6rem;
  text-align: center;
}

.auto-stub .auto-soon {
  display: block;
  font-weight: 500;
  font-size: 0.6rem;
  opacity: 0.85;
}

.bottom-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.legal-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.legal-links a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.legal-links a:hover,
.legal-links a:focus {
  color: var(--accent);
}

.form-privacy {
  margin: 0.65rem 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.form-privacy a {
  color: var(--accent);
}

.turnstile-wrap {
  margin: 0.35rem 0 0.65rem;
  min-height: 65px;
  display: flex;
  justify-content: center;
}

.turnstile-wrap[hidden] {
  display: none !important;
}

.cf-turnstile-host {
  width: 100%;
  max-width: 100%;
}

/* —— Legal pages (terms / privacy) —— */
body.legal-page {
  overflow: auto;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

.legal-wrap {
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(1rem + var(--safe-top)) 1.15rem calc(2.5rem + var(--safe-bottom));
  color: var(--fg);
  line-height: 1.5;
}

.legal-back {
  margin: 0 0 1rem;
  font-size: 0.85rem;
}

.legal-back a {
  color: var(--accent);
  text-decoration: none;
}

.legal-back a:hover {
  text-decoration: underline;
}

.legal-wrap h1 {
  margin: 0 0 0.35rem;
  font-size: 1.55rem;
  font-weight: 700;
}

.legal-meta {
  margin: 0 0 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.legal-wrap h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.legal-wrap h3 {
  margin: 1rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.legal-wrap p,
.legal-wrap li {
  font-size: 0.92rem;
  color: #d5e2ee;
}

.legal-wrap ul {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.2rem;
}

.legal-wrap a {
  color: var(--accent);
}

.legal-footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
}

.legal-footer-nav a {
  color: var(--muted);
}
