/* ==========================================================================
   Home page — "Ask about Alex's work" AI field and answer panel
   Loaded on index.html only, after base.css. Design-system tokens only.
   ========================================================================== */

/* ---- hero action row: AI field first, case studies beside it; suggestions underneath ---- */
.hero-cta { display: flex; flex-direction: column; align-items: center; gap: var(--pm-space-4); width: 100% }
.hero-actions {
  display: flex; align-items: stretch;   /* field and button share one height */ justify-content: center; flex-wrap: wrap;
  gap: var(--pm-space-4); width: 100%; max-width: 780px; margin-top: var(--pm-space-6);   /* more room under the intro copy */
}
.ask-or { flex-shrink: 0; align-self: center; font-size: var(--pm-type-small-size); color: var(--pm-color-text-tertiary) }
.hero-actions .pm-btn { flex-shrink: 0 }

/* ---- the field: one line, gradient edge, soft glow ---- */
.ask { flex: 1 1 420px; max-width: 520px; position: relative; display: flex; align-items: center; gap: var(--pm-space-3) }
.ask .ask-field { flex: 1; min-width: 0 }   /* lets the field shrink to the space available on phones */
.ask-field {
  position: relative; display: flex; align-items: center; gap: var(--pm-space-3);
  min-height: var(--pm-button-min-height);
  padding: var(--pm-space-1) var(--pm-space-1) var(--pm-space-1) var(--pm-space-2);
  border: 1px solid transparent; border-radius: var(--pm-button-radius);   /* same corners as the buttons */
  /* gradient border: the fill paints the padding box, the brand gradient shows through the transparent border */
  background: linear-gradient(var(--pm-color-surface-raised), var(--pm-color-surface-raised)) padding-box, var(--pm-gradient-brand) border-box;
  box-shadow: 0 0 0 0 transparent, var(--pm-shadow-glow-accent);
  transition: box-shadow var(--pm-duration-base) ease;
  text-align: left;
}
.ask-field::before {               /* the ambient glow behind the field */
  content: ''; position: absolute; inset: -6px; z-index: -1; border-radius: inherit;
  background: var(--pm-gradient-brand); filter: blur(18px); opacity: .22;
  transition: opacity var(--pm-duration-base) ease;
}
.ask-field:hover::before { opacity: .32 }
.ask-field:focus-within::before { opacity: .45 }
.ask-field:focus-within { box-shadow: 0 0 0 var(--pm-focus-ring-width) var(--pm-color-accent-secondary-subtle), var(--pm-shadow-glow-accent-hover) }

.ask-spark { flex-shrink: 0; width: 18px; height: 18px; color: var(--pm-color-text-accent-secondary) }
@media (prefers-reduced-motion: no-preference) {
  .ask-spark { animation: askTwinkle 3.2s ease-in-out infinite }
  @keyframes askTwinkle { 0%, 100% { transform: scale(1) rotate(0); opacity: 1 } 50% { transform: scale(.82) rotate(18deg); opacity: .75 } }
}

.ask-input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: var(--pm-type-body-size); color: var(--pm-color-text-primary);
  padding: var(--pm-space-2) 0;
}
.ask-input::placeholder { color: var(--pm-color-text-tertiary); transition: opacity var(--pm-duration-fast) ease }
.ask-input.is-swapping::placeholder, .ask-input:focus::placeholder { opacity: 0 }   /* example text fades out when you click in */

.ask-kbd {
  flex-shrink: 0; font: inherit; font-size: var(--pm-type-caption-size); color: var(--pm-color-text-tertiary);
  border: 1px solid var(--pm-color-border-subtle); border-radius: var(--pm-radius-sm); padding: 0 var(--pm-space-2); line-height: var(--pm-font-line-height-relaxed);
}
.ask-field:focus-within .ask-kbd, .ask-input:not(:placeholder-shown) ~ .ask-kbd { display: none }

.ask-clear {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: var(--pm-space-8); height: var(--pm-space-8); border: 0; border-radius: var(--pm-radius-sm);
  background: transparent; color: var(--pm-color-text-tertiary); cursor: pointer;
  transition: color var(--pm-duration-fast) ease, background var(--pm-duration-fast) ease;
}
.ask-clear[hidden] { display: none }
.ask-clear:hover { color: var(--pm-color-text-primary); background: var(--pm-color-surface-tint) }
.ask-clear svg { width: 16px; height: 16px }

.ask-send {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: var(--pm-space-10); height: var(--pm-space-10); border: 0; border-radius: var(--pm-radius-sm);
  background: var(--pm-gradient-brand); color: var(--pm-button-primary-text); cursor: pointer;
  transition: transform var(--pm-duration-fast) ease, opacity var(--pm-duration-fast) ease;
}
.ask-send:disabled { opacity: .35; cursor: default }
@media (prefers-reduced-motion: no-preference) { .ask-send:not(:disabled):hover { transform: translateY(-1px) scale(1.06) } }
.ask-send svg { width: 18px; height: 18px }

/* ---- suggested questions ---- */
/* always one line: ask.js shows only the chips that fit. Raised above the field's glow
   (which lives in .hero-actions, z-index 2) so the glow never shows through the chips. */
.ask-suggest { display: flex; flex-wrap: nowrap; justify-content: center; gap: var(--pm-space-2); width: 100%; max-width: 780px; position: relative; z-index: 3 }
.ask-chip {
  font: inherit; font-size: var(--pm-type-small-size); color: var(--pm-color-text-secondary); cursor: pointer;
  background: var(--pm-color-surface-page);   /* solid, so the backdrop glow doesn't show through */
  border: 1px solid var(--pm-color-border-subtle); border-radius: var(--pm-radius-full);
  padding: var(--pm-space-1) var(--pm-space-3); min-height: var(--pm-space-8);
  transition: border-color var(--pm-duration-fast) ease, color var(--pm-duration-fast) ease;
  flex-shrink: 0; white-space: nowrap;
}
.ask-chip:hover { border-color: var(--pm-color-accent-secondary); color: var(--pm-color-text-primary) }

/* ---- answer panel ---- */
.ask-panel {
  width: 100%; max-width: 760px; text-align: left;
  background: var(--pm-color-surface-card); border: 1px solid var(--pm-color-border-subtle); border-radius: var(--pm-radius-lg);
  padding: var(--pm-space-6); position: relative; overflow: hidden;
}
.ask-panel[hidden] { display: none }
.ask-panel::before {               /* thin brand line across the top: marks the panel as AI output */
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--pm-gradient-brand);
}
@media (prefers-reduced-motion: no-preference) {
  .ask-panel:not([hidden]) { animation: askIn var(--pm-duration-slow) var(--pm-easing-emphasized) }
  @keyframes askIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
}
.ask-panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--pm-space-4); margin-bottom: var(--pm-space-4) }
.ask-label { display: inline-flex; align-items: center; gap: var(--pm-space-2); font-size: var(--pm-type-caption-size); letter-spacing: var(--pm-font-tracking-caps); text-transform: uppercase; color: var(--pm-color-text-tertiary) }
.ask-label .ask-spark { width: 14px; height: 14px; animation: none }
.ask-q { font-size: var(--pm-type-body-size); color: var(--pm-color-text-primary); font-weight: var(--pm-font-weight-semibold); margin: 0 0 var(--pm-space-3) }
.ask-close {
  font: inherit; font-size: var(--pm-type-small-size); color: var(--pm-color-text-tertiary); background: transparent; border: 0; cursor: pointer;
  padding: var(--pm-space-1) var(--pm-space-2); border-radius: var(--pm-radius-sm);
}
.ask-close:hover { color: var(--pm-color-text-primary) }

.ask-answer { color: var(--pm-color-text-secondary); font-size: var(--pm-type-body-size); line-height: var(--pm-font-line-height-relaxed) }
.ask-answer p { margin: 0 0 var(--pm-space-3) }
.ask-answer p:last-child { margin-bottom: 0 }
.ask-answer ul { margin: 0 0 var(--pm-space-3); padding-left: var(--pm-space-5) }
.ask-answer li { margin-bottom: var(--pm-space-1) }
.ask-answer.is-streaming > :last-child::after {   /* blinking caret while the answer streams in */
  content: ''; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: text-bottom; background: var(--pm-color-accent-secondary);
  animation: askCaret 1s steps(1) infinite;
}
@keyframes askCaret { 50% { opacity: 0 } }

/* thinking state: shimmering placeholder lines */
.ask-thinking { display: grid; gap: var(--pm-space-2) }
.ask-thinking span { display: block; height: 12px; border-radius: var(--pm-radius-full); background: var(--pm-color-surface-tint-strong) }
.ask-thinking span:nth-child(2) { width: 86% }
.ask-thinking span:nth-child(3) { width: 62% }
@media (prefers-reduced-motion: no-preference) {
  .ask-thinking span { background: linear-gradient(90deg, var(--pm-color-surface-tint) 0%, var(--pm-color-accent-secondary-subtle) 50%, var(--pm-color-surface-tint) 100%); background-size: 200% 100%; animation: askShimmer 1.4s linear infinite }
  @keyframes askShimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }
}

.ask-sources { display: flex; flex-wrap: wrap; align-items: center; gap: var(--pm-space-2); margin-top: var(--pm-space-5); padding-top: var(--pm-space-4); border-top: 1px solid var(--pm-color-border-subtle) }
.ask-sources[hidden] { display: none }
.ask-sources-label { font-size: var(--pm-type-caption-size); color: var(--pm-color-text-tertiary); margin-right: var(--pm-space-1) }
.ask-source {
  display: inline-flex; align-items: center; gap: var(--pm-space-1);
  font-size: var(--pm-type-small-size); color: var(--pm-color-text-secondary);
  border: 1px solid var(--pm-color-border-subtle); border-radius: var(--pm-radius-full); padding: var(--pm-space-1) var(--pm-space-3);
}
a.ask-source { color: var(--pm-color-text-accent-secondary); border-color: var(--pm-color-accent-secondary-subtle); background: var(--pm-color-accent-secondary-subtle) }
a.ask-source:hover { border-color: var(--pm-color-accent-secondary) }

.ask-note { margin: var(--pm-space-4) 0 0; font-size: var(--pm-type-caption-size); color: var(--pm-color-text-tertiary); line-height: var(--pm-font-line-height-relaxed) }
.ask-note a { color: var(--pm-color-text-secondary); text-decoration: underline; text-underline-offset: 3px }

/* ---- help icon inside the field, where the sparkle used to be: how answers are sourced and that questions are logged ---- */
.ask-help { flex-shrink: 0; display: inline-flex }
.hero-cta .hero-actions { position: relative; z-index: 2 }   /* lets the tip sit over the suggestion chips */
/* while the help tip is open, lift the action row above the chips so the tip stays on top */
.hero-cta .hero-actions:has(.ask-help:hover, .ask-help.is-open, .ask-help-btn:focus-visible) { z-index: 4 }
.ask-help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--pm-space-8); height: var(--pm-space-8); padding: 0; border: 0; border-radius: var(--pm-radius-full);
  background: transparent; color: var(--pm-color-text-accent-secondary); cursor: default;
  transition: color var(--pm-duration-fast) ease, background var(--pm-duration-fast) ease;
}
.ask-help-btn svg { width: 18px; height: 18px }
.ask-help:hover .ask-help-btn, .ask-help.is-open .ask-help-btn { background: var(--pm-color-accent-secondary-subtle) }
.ask-help-tip {   /* same look as the "Email copied" tip, wrapped to a few lines */
  position: absolute; left: 0; top: calc(100% + var(--pm-space-2)); width: max-content; max-width: min(300px, 100%);
  background: var(--pm-color-surface-card); border: 1px solid var(--pm-color-border-subtle); color: var(--pm-color-text-primary);
  padding: var(--pm-space-3) var(--pm-space-4); border-radius: var(--pm-radius-lg); box-shadow: var(--pm-shadow-elevation-1);
  font-size: var(--pm-type-caption-size); line-height: var(--pm-font-line-height-relaxed); text-align: left;
  opacity: 0; visibility: hidden; transform: translateY(4px); pointer-events: none;
  transition: opacity var(--pm-duration-fast) ease, transform var(--pm-duration-fast) ease, visibility 0s linear var(--pm-duration-fast);
  z-index: var(--pm-z-toast);
}
.ask-help:hover .ask-help-tip, .ask-help.is-open .ask-help-tip, .ask-help-btn:focus-visible + .ask-help-tip {
  opacity: 1; visibility: visible; transform: none; transition-delay: 0s;
}
.ask-error { color: var(--pm-color-status-error) }

/* focus moves to the panel when an answer appears (it isn't a control, so no ring; the brand line already marks it) */
.ask-panel:focus, .ask-panel:focus-visible { outline: none }

.ask-top {
  display: inline-flex; align-items: center; gap: var(--pm-space-1); margin-top: var(--pm-space-4);
  font-size: var(--pm-type-small-size); color: var(--pm-color-text-secondary); text-decoration: underline; text-underline-offset: 3px;
}
.ask-top:hover { color: var(--pm-color-text-primary) }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0 }

/* ---- mobile: field and button stack, full width ---- */
@media (max-width: 860px) {
  /* tighter hero so the AI field sits higher and stays in view on small phones */
  /* the hero title starts at the same height as the other top-level pages (About, Case Studies, Lab) */
  .pg-index .hero { padding-top: calc(var(--pm-space-16) + var(--pm-space-4)); gap: var(--pm-space-5) !important }
  .pg-index .hero > p { font-size: var(--pm-type-body-size) !important }
  /* phones: field, then suggestions, then "or" and the case studies button */
  .hero-cta { margin-top: var(--pm-space-1); gap: var(--pm-space-3); align-items: stretch }
  .hero-actions { display: contents }
  .hero-cta .ask { order: 1 }
  .hero-cta .ask-suggest { order: 2 }
  .hero-cta .ask-or { order: 3; text-align: center }
  .hero-cta .pm-btn { order: 4 }
  .ask { flex: none; max-width: none; width: 100% }
  .ask-kbd { display: none }
  .ask-panel { padding: var(--pm-space-5) }
}
