/* FirstMile — luxury dark, dawn-run energy.
   Ink night base · warm paper text · sunrise gradient accent.
   Serif (Fraunces) for moments, Inter for the machine. */

:root {
  --bg: #0A0B0E;
  --panel: #121318;
  --panel-2: #16181F;
  --line: rgba(255, 255, 255, 0.07);
  --text: #EFEDE8;
  --muted: #8E939C;
  --accent: #FF6A3D;
  --accent-2: #FFB35C;
  --grad: linear-gradient(92deg, var(--accent), var(--accent-2));
  --radius: 16px;
  --max: 720px;
  --tabbar-h: calc(62px + env(safe-area-inset-bottom));
}

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

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.view { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- shared ---------- */

.wordmark {
  font-family: "Inter", sans-serif;
  font-weight: 600;
  letter-spacing: 0.32em;
  font-size: 13px;
  color: var(--text);
}
.wordmark span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wordmark.sm { font-size: 11px; }

.btn-primary {
  background: var(--grad);
  color: #14080a;
  border: none;
  font: 600 15px "Inter", sans-serif;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 8px 28px rgba(255, 106, 61, 0.22);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 34px rgba(255, 106, 61, 0.32); }
.btn-primary:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font: 500 14px "Inter", sans-serif;
  padding: 12px 22px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.18); }
.btn-ghost.sm { padding: 8px 16px; font-size: 13px; }

.fine { font-size: 12.5px; color: var(--muted); }
.fine.center { text-align: center; }

.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- welcome ---------- */

#view-welcome {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(255, 106, 61, 0.10), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(255, 179, 92, 0.06), transparent 60%),
    var(--bg);
}
.welcome-wrap {
  max-width: 640px;
  padding: 48px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  animation: rise 0.7s ease both;
}
.hero {
  font-family: "Fraunces", serif;
  font-weight: 380;
  font-size: clamp(40px, 7vw, 64px);
  line-height: 1.06;
  letter-spacing: -0.01em;
}
.hero em { font-style: italic; font-weight: 430; }
.hero-sub { color: var(--muted); font-size: 16.5px; max-width: 48ch; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- onboarding ---------- */

#view-onboarding { align-items: center; justify-content: center; }
.ob-wrap {
  width: 100%;
  max-width: 560px;
  padding: 40px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 36px;
  min-height: 70dvh;
}
.ob-top { display: flex; flex-direction: column; gap: 22px; }
.ob-progress { height: 2px; background: var(--line); border-radius: 2px; overflow: hidden; }
.ob-bar { height: 100%; width: 0%; background: var(--grad); transition: width 0.35s ease; }

.ob-step { flex: 1; display: flex; flex-direction: column; gap: 22px; animation: rise 0.4s ease both; }
.ob-q {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: clamp(26px, 4.5vw, 34px);
  line-height: 1.15;
}
.ob-hint { color: var(--muted); font-size: 14.5px; margin-top: -12px; }
.ob-count { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }
.ob-count.flash { animation: countFlash 0.4s ease; }
@keyframes countFlash {
  0%, 100% { color: var(--muted); transform: none; }
  35% { color: var(--accent); transform: scale(1.06); }
}

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font: 500 14.5px "Inter", sans-serif;
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.chip:hover { border-color: rgba(255, 106, 61, 0.5); transform: translateY(-1px); }
.chip.selected {
  border-color: var(--accent);
  background: rgba(255, 106, 61, 0.10);
}

.ob-input, .ob-textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: 400 16px "Inter", sans-serif;
  padding: 16px 18px;
  outline: none;
  transition: border-color 0.15s;
}
.ob-textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.ob-input:focus, .ob-textarea:focus { border-color: rgba(255, 106, 61, 0.55); }
.ob-input::placeholder, .ob-textarea::placeholder { color: rgba(142, 147, 156, 0.6); }

.ob-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- loading ("getting your coach up to speed") ---------- */

#view-loading {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1000px 520px at 70% -10%, rgba(255, 106, 61, 0.10), transparent 60%),
    radial-gradient(820px 460px at 10% 110%, rgba(255, 179, 92, 0.06), transparent 60%),
    var(--bg);
}
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 40px 28px;
  text-align: center;
  animation: rise 0.6s ease both;
}
.loader-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  animation: spin 0.9s linear infinite;
  margin-top: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: clamp(24px, 4.5vw, 30px);
  line-height: 1.15;
}
.loading-label {
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.02em;
  min-height: 1.3em;
}
/* the user's own answer, floating + swapping with each beat */
.loading-answer {
  min-height: 1.5em;
  max-width: 22ch;
  animation: floaty 3.4s ease-in-out infinite;
}
.ans-text {
  display: inline-block;
  font-family: "Fraunces", serif;
  font-weight: 440;
  font-size: clamp(22px, 5vw, 30px);
  line-height: 1.15;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
}
.ans-text.show { animation: ansIn 0.6s ease both; }
@keyframes ansIn {
  0% { opacity: 0; transform: translateY(12px) scale(0.94); filter: blur(3px); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes floaty {
  0%, 100% { transform: translate(0, 0); }
  33% { transform: translate(5px, -7px); }
  66% { transform: translate(-5px, 4px); }
}

/* ---------- chat ---------- */

#view-chat {
  max-width: var(--max);
  margin: 0 auto;
  width: 100%;
  /* sit above the fixed tab bar; messages scroll internally (not the page) */
  height: calc(100dvh - var(--tabbar-h));
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(10, 11, 14, 0.85);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.key-banner {
  margin: 14px 20px 0;
  padding: 12px 16px;
  border: 1px solid rgba(255, 106, 61, 0.4);
  background: rgba(255, 106, 61, 0.07);
  border-radius: 12px;
  font-size: 13.5px;
  color: var(--text);
}
.key-banner code { font-size: 12.5px; color: var(--accent-2); }

.messages {
  flex: 1;
  min-height: 0; /* critical: lets the flex child actually scroll instead of growing */
  padding: 26px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

/* dated session grouping */
.day { display: flex; flex-direction: column; gap: 20px; }
.day-body { display: flex; flex-direction: column; gap: 20px; }
.day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font: 600 11px "Inter", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 2px 0;
}
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.day-divider:hover { color: var(--text); }
.day-meta { color: var(--muted); font-weight: 500; letter-spacing: 0.03em; text-transform: none; font-size: 11px; }

.msg { animation: rise 0.35s ease both; max-width: 92%; }
.msg.user {
  align-self: flex-end;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  font-size: 15.5px;
}
.msg.coach { align-self: flex-start; font-size: 15.5px; }
.msg.coach .coach-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  font-weight: 600;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 8px;
}

/* coach markdown */
.msg.coach h3 {
  font-family: "Fraunces", serif;
  font-weight: 480;
  font-size: 18px;
  margin: 16px 0 6px;
}
.msg.coach p { margin: 8px 0; }
.msg.coach ul, .msg.coach ol { margin: 8px 0 8px 20px; display: flex; flex-direction: column; gap: 5px; }
.msg.coach strong { color: #fff; font-weight: 600; }
.msg.coach em { color: var(--accent-2); font-style: italic; }

.caret {
  display: inline-block;
  width: 8px; height: 17px;
  background: var(--grad);
  border-radius: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.thinking { color: var(--muted); font-size: 14px; font-style: italic; }

.starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 20px 12px;
}
.chip.starter { font-size: 13.5px; padding: 10px 15px; }

/* composer */
.composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 10px 10px 18px;
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: rgba(255, 106, 61, 0.45); }
.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font: 400 15.5px "Inter", sans-serif;
  line-height: 1.45;
  max-height: 140px;
}
.composer textarea::placeholder { color: rgba(142, 147, 156, 0.6); }
.send {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--grad);
  color: #14080a;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s, opacity 0.15s;
}
.send:hover { transform: translateY(-1px); }
.send:disabled { opacity: 0.35; cursor: default; transform: none; }

/* composer is now the in-flow bottom row of the chat view (above the tab bar) */
#view-chat .composer-wrap { position: relative; bottom: auto; }

/* ---------- feature views (form / fuel) ---------- */

#view-form, #view-fuel {
  max-width: var(--max);
  margin: 0 auto;
  width: 100%;
  height: calc(100dvh - var(--tabbar-h));
  min-height: 0;
  overflow: hidden;
}

.feature-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.feature-intro { display: flex; flex-direction: column; gap: 10px; animation: rise 0.4s ease both; }
.feature-title {
  font-family: "Fraunces", serif;
  font-weight: 400;
  font-size: clamp(30px, 6vw, 40px);
  line-height: 1.05;
}
.feature-title em { font-style: italic; font-weight: 440; }
.feature-sub { color: var(--muted); font-size: 15.5px; max-width: 46ch; }

/* timing selector (fuel) */
.timing { display: flex; flex-direction: column; gap: 10px; }
.timing-label { font-size: 13px; color: var(--muted); letter-spacing: 0.02em; }

/* uploader card */
.uploader {
  display: block;
  border: 1.5px dashed rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.uploader:hover { border-color: rgba(255, 106, 61, 0.5); background: var(--panel-2); }
.uploader.dragging { border-color: var(--accent); background: var(--panel-2); border-style: solid; }
.uploader-error { color: #ff8a6a; font-size: 13.5px; font-weight: 500; }
.uploader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}
.uploader-icon { width: 38px; height: 38px; color: var(--accent); opacity: 0.9; }
.uploader-cta { font-weight: 600; font-size: 15.5px; }
.media-preview {
  display: block;
  width: 100%;
  max-height: 60vh;
  background: #000;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.replace-btn { align-self: flex-start; }

/* tap-to-watch timestamp chip inside coach text */
.seek {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(255, 106, 61, 0.12);
  border: 1px solid rgba(255, 106, 61, 0.4);
  color: var(--accent-2);
  font: 600 12.5px "Inter", sans-serif;
  padding: 1px 8px;
  border-radius: 999px;
  cursor: pointer;
  vertical-align: baseline;
  transition: background 0.15s, border-color 0.15s;
}
.seek:hover { background: rgba(255, 106, 61, 0.22); border-color: var(--accent); }

/* primary button, full width in feature flows */
.btn-primary.block { width: 100%; padding: 16px; font-size: 16px; }

/* coach result panel — reuses coach markdown styling */
.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  font-size: 15.5px;
  animation: rise 0.35s ease both;
}
.result .coach-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  font-weight: 600;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 8px;
}
.result h3 { font-family: "Fraunces", serif; font-weight: 480; font-size: 18px; margin: 16px 0 6px; }
.result p { margin: 8px 0; }
.result ul, .result ol { margin: 8px 0 8px 20px; display: flex; flex-direction: column; gap: 5px; }
.result strong { color: #fff; font-weight: 600; }
.result em { color: var(--accent-2); font-style: italic; }
.result .thinking { color: var(--muted); font-size: 14px; font-style: italic; }
.disclaimer { margin-top: 4px; }

/* follow-up reply thread under a form/fuel result */
.followup {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.35s ease both;
}
.followup-thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.followup-thread:empty { display: none; }
.followup-composer { width: 100%; }

/* ---------- account / auth ---------- */
.header-actions { display: flex; gap: 8px; }
.link-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font: 500 13.5px "Inter", sans-serif;
  text-decoration: underline; text-underline-offset: 3px; padding: 4px;
  transition: color 0.15s;
}
.link-btn:hover { color: var(--text); }

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  animation: rise 0.2s ease both;
}
.modal-card {
  position: relative; width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 22px 22px; display: flex; flex-direction: column; gap: 14px;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-family: "Fraunces", serif; font-weight: 440; font-size: 22px; }
.modal-sub { color: var(--muted); font-size: 14px; margin-top: -6px; }
.auth-step { display: flex; flex-direction: column; gap: 10px; }
.auth-msg { font-size: 13.5px; min-height: 1.2em; color: var(--muted); }
.auth-msg.err { color: #ff8a6a; }
.auth-msg.ok { color: var(--accent-2); }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(10, 11, 14, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 20;
  max-width: var(--max);
  margin: 0 auto;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font: 500 11px "Inter", sans-serif;
  letter-spacing: 0.04em;
  transition: color 0.15s;
}
.tab svg { width: 22px; height: 22px; }
.tab.selected { color: var(--text); }
.tab.selected svg { stroke: var(--accent); }

@media (max-width: 480px) {
  .messages { padding: 20px 14px 10px; }
  .msg { max-width: 100%; }
  .feature-scroll { padding: 20px 14px 28px; }
}

/* ---- Paywall ---- */
.paywall-plans { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 16px; }
.plan-option {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 2px 12px; text-align: left; padding: 14px 16px;
  background: var(--panel-2); border: 1.5px solid var(--line); border-radius: 14px;
  cursor: pointer; color: var(--text); transition: border-color 0.15s, background 0.15s;
}
.plan-option:hover { border-color: rgba(255, 255, 255, 0.18); }
.plan-option.selected { border-color: var(--accent); background: rgba(255, 106, 61, 0.07); }
.plan-name { font-weight: 600; font-size: 15px; }
.plan-price { font-family: "Fraunces", serif; font-weight: 480; font-size: 22px; grid-row: span 2; }
.plan-per { font-family: "Inter", sans-serif; font-size: 13px; color: var(--muted); font-weight: 500; }
.plan-note { grid-column: 1; font-size: 12.5px; color: var(--muted); }
.plan-tag {
  font-family: "Inter", sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-left: 6px;
}

/* ---- Quota nudge + Share button ---- */
.quota-nudge {
  font-size: 13px; color: var(--accent-2); margin: 10px 0 0;
  display: flex; align-items: center; gap: 6px;
}
.quota-nudge.hidden { display: none; }
.share-row { margin-top: 14px; display: flex; justify-content: flex-end; }
.btn-share {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.btn-share:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-share svg { width: 16px; height: 16px; }
