:root {
  --bg: #0F0F0F;
  --card: #1A1A1A;
  --card-2: #161616;
  --border: #2A2A2A;
  --border-soft: #1F1F1F;
  --text: #FAFAF9;
  --text-dim: #B0B0B0;
  --text-muted: #7A7A7A;
  --accent: #D97757;
  --accent-soft: rgba(217, 119, 87, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

*, *::before, *::after {
  -webkit-tap-highlight-color: rgba(217, 119, 87, 0.18);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.tag::before {
  content: '';
  width: 4px;
  height: 14px;
  background: var(--accent);
  display: inline-block;
}

/* ── Welcome screen ────────────────────────────────────────────── */

.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(clamp(24px, 5vw, 40px), var(--safe-top))
    max(clamp(18px, 5vw, 28px), var(--safe-right))
    max(clamp(24px, 5vw, 40px), var(--safe-bottom))
    max(clamp(18px, 5vw, 28px), var(--safe-left));
}

.welcome-inner {
  max-width: 620px;
  width: 100%;
}

.welcome h1 {
  font-size: clamp(28px, 7.5vw, 44px);
  font-weight: 700;
  line-height: 1.08;
  margin: 0 0 18px 0;
  letter-spacing: -0.02em;
  min-height: calc(1.08em * 2);
}

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

.welcome p {
  color: var(--text-dim);
  font-size: clamp(15px, 2.2vw, 17px);
  line-height: 1.6;
  margin: 0 0 32px 0;
  min-height: 1.6em;
}

.welcome-cta {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.welcome-cta.visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.tw-cursor {
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: tw-blink 0.9s steps(2, start) infinite;
  font-weight: 400;
  transform: translateY(-1px);
}

@keyframes tw-blink {
  to { visibility: hidden; }
}

.btn-primary {
  background: var(--accent);
  color: #0F0F0F;
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 28px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Chat screen ───────────────────────────────────────────────── */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  padding:
    max(clamp(14px, 3vw, 24px), var(--safe-top))
    max(clamp(14px, 4vw, 20px), var(--safe-right))
    0
    max(clamp(14px, 4vw, 20px), var(--safe-left));
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 18px;
}

.chat-header .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.2);
  flex-shrink: 0;
}

.chat-header .title {
  font-size: clamp(11.5px, 1.7vw, 13px);
  color: var(--text-dim);
  letter-spacing: 0.5px;
  /* Long title shouldn't push elements off-screen on narrow phones */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
  min-height: 0;
  overscroll-behavior: contain;
  scroll-behavior: auto;
}

.msg {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.msg .who {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.msg.assistant .who {
  color: var(--accent);
}

.msg .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(12px, 2vw, 14px) clamp(13px, 2.2vw, 16px);
  font-size: clamp(14.5px, 2vw, 15px);
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  /* Long URLs / unbreakable strings won't overflow */
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--card-2);
  border-color: var(--border-soft);
  color: var(--text-dim);
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out both;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(14px + var(--safe-bottom)) 0;
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}

.composer-inner {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
}

.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  /* 16px minimum prevents iOS Safari from zooming the page on focus.
     Desktop visuals stay tight via line-height. */
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  max-height: 200px;
  padding: 6px 0;
  min-width: 0;
}

.composer textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  background: var(--accent);
  color: #0F0F0F;
  border: none;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: filter 0.15s ease;
}

.send-btn:hover { filter: brightness(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Loading screen ────────────────────────────────────────────── */

.loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(clamp(24px, 5vw, 40px), var(--safe-top))
    max(clamp(18px, 5vw, 28px), var(--safe-right))
    max(clamp(24px, 5vw, 40px), var(--safe-bottom))
    max(clamp(18px, 5vw, 28px), var(--safe-left));
}

.loading-inner {
  max-width: 540px;
  width: 100%;
}

.loading h2 {
  font-size: clamp(22px, 4.5vw, 28px);
  font-weight: 700;
  margin: 0 0 14px 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.loading > .loading-inner > p {
  color: var(--text-dim);
  font-size: clamp(14px, 2vw, 15px);
  margin: 0 0 28px 0;
}

.substep {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 14px);
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 14px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: border-color 0.2s ease, opacity 0.2s ease;
  opacity: 0.45;
}

.substep.active {
  border-color: var(--accent);
  opacity: 1;
}

.substep.done {
  opacity: 1;
}

.substep-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1.5px;
  width: 28px;
  flex-shrink: 0;
}

.substep-text {
  flex: 1;
  font-size: clamp(13px, 1.9vw, 14px);
  color: var(--text);
  overflow-wrap: anywhere;
}

.substep-icon {
  font-size: 14px;
  color: var(--accent);
  width: 16px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Download screen ───────────────────────────────────────────── */

.download {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(clamp(24px, 5vw, 40px), var(--safe-top))
    max(clamp(18px, 5vw, 28px), var(--safe-right))
    max(clamp(24px, 5vw, 40px), var(--safe-bottom))
    max(clamp(18px, 5vw, 28px), var(--safe-left));
}

.download-inner {
  max-width: 580px;
  width: 100%;
}

.download h2 {
  font-size: clamp(26px, 6.5vw, 38px);
  font-weight: 700;
  margin: 0 0 12px 0;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.download h2 span { color: var(--accent); }

.download p {
  color: var(--text-dim);
  font-size: clamp(15px, 2vw, 16px);
  margin: 0 0 32px 0;
  line-height: 1.6;
}

.download .btn-primary {
  font-size: clamp(15px, 2vw, 16px);
  padding: clamp(14px, 3vw, 16px) clamp(22px, 4.5vw, 32px);
  /* Full-width on narrow phones, inline otherwise */
  width: 100%;
  max-width: 360px;
}

.download .footer-note {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 22px;
}

/* ── Error inline ──────────────────────────────────────────────── */
.inline-error {
  color: #ef9a8b;
  font-size: 13px;
  margin-top: 10px;
}

/* ── Narrow-phone tweaks that clamp() can't express ────────────── */

@media (max-width: 420px) {
  /* Hide the chat title text on very narrow screens — the dot is enough
     of an indicator; the title was getting cut off anyway. */
  .chat-header .title {
    font-size: 11.5px;
  }

  /* Tighter composer spacing so the textarea has more room */
  .composer-inner {
    padding: 6px 6px 6px 12px;
    gap: 8px;
  }

  .send-btn {
    width: 42px;
    height: 42px;
  }
}

/* ── Landscape phones: avoid the welcome screen scrolling off ─── */

@media (max-height: 480px) and (orientation: landscape) {
  .welcome,
  .loading,
  .download {
    align-items: flex-start;
    padding-top: max(20px, var(--safe-top));
  }
  .welcome h1 {
    font-size: clamp(24px, 5vw, 34px);
    min-height: 0;
  }
}
