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

:root {
  /* palette */
  --ink:          #1C1F2E;
  --ink-2:        #262A3E;
  --ink-3:        #3D4263;
  --paper:        #F7F4EE;
  --paper-2:      #EDE9DF;
  --paper-3:      #E2DDD3;
  --muted:        #8A8FA8;
  --muted-warm:   #9A9488;
  --signal:       #FFE03D;
  --signal-deep:  #D4A800;
  --signal-bg:    #FFF8CC;
  --white:        #FFFFFF;
  --bubble-user-bg:   #1C1F2E;
  --bubble-user-tx:   #F7F4EE;
  --bubble-asst-bg:   #FFFFFF;
  --bubble-asst-bd:   #E2DDD3;

  /* type scale */
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14.5px;
  --text-lg:   18px;
  --text-xl:   24px;
  --text-2xl:  30px;
  --text-3xl:  38px;

  /* spacing */
  --gap-xs:  4px;
  --gap-sm:  8px;
  --gap-md:  14px;
  --gap-lg:  24px;
  --gap-xl:  32px;

  /* radii */
  --r-sm:   8px;
  --r-md:   16px;
  --r-lg:   24px;
  --r-xl:   30px;
  --r-full: 9999px;
}

/* ─── Base ───────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--ink-2);
  color: var(--paper);
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─────────────────────────────────────────────────── */
.shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(130% 100% at 50% -5%, #2D3250 0%, var(--ink) 60%);
}

.reel {
  width: 100%;
  max-width: 440px;
  height: min(860px, 92dvh);
  background: var(--ink-2);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 40px 100px -30px rgba(0,0,0,0.7);
}

/* ─── Progress segments ──────────────────────────────────────── */
.segments {
  display: flex;
  gap: 5px;
  padding: 12px 16px 0;
  flex-shrink: 0;
}

.seg {
  flex: 1;
  height: 3px;
  border-radius: var(--r-full);
  background: rgba(255,255,255,0.12);
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.2s;
}
.seg:hover { opacity: 0.8; }
.seg.done { background: rgba(255,255,255,0.5); }
.seg.active { background: rgba(255,255,255,0.12); }
.seg.active::after {
  content: '';
  display: block;
  height: 100%;
  background: var(--signal);
  transform-origin: left;
  animation: seg-fill var(--seg-dur, 4s) linear forwards;
}
@keyframes seg-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ─── Header bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 8px 18px;
  flex-shrink: 0;
}

.topbar-dot {
  width: 5px; height: 5px;
  border-radius: var(--r-full);
  background: var(--signal);
  flex-shrink: 0;
}

.topbar-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #B0B4CC;
}

.topbar-spacer { flex: 1; }

/* ─── Stage (the chat area) ──────────────────────────────────── */
.stage {
  flex: 1;
  position: relative;
  margin: 0 12px 12px;
  border-radius: var(--r-lg);
  background: var(--paper);
  overflow: hidden;
  min-height: 0;
}

.scroll-area {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 20px 16px 90px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.scroll-area::-webkit-scrollbar { width: 0; }

/* ─── Overlay cards ──────────────────────────────────────────── */
.card {
  position: absolute;
  inset: 0;
  bottom: 78px;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: var(--gap-lg) 24px var(--gap-md);
  gap: var(--gap-sm);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 10;
}
.card.hidden {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

/* Title card */
.card-title h1 {
  font-family: ui-serif, Georgia, serif;
  font-size: var(--text-2xl);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.card-title p {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: #5A5C6A;
  max-width: 32ch;
}
.card-title .tap-hint {
  margin-top: var(--gap-xs);
  font-size: var(--text-xs);
  color: var(--muted-warm);
  letter-spacing: 0.04em;
}

/* Coaching card — centred */
.card-coach {
  justify-content: center;
  gap: var(--gap-md);
}
.card-coach .coach-eyebrow {
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--signal-deep);
}
.card-coach h2 {
  font-family: ui-serif, Georgia, serif;
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.coach-points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.coach-points li {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: #3A3C44;
  padding-left: 18px;
  position: relative;
}
.coach-points li::before {
  content: '';
  position: absolute;
  left: 0; top: 6px;
  width: 7px; height: 7px;
  border-radius: 2px;
  background: var(--signal-deep);
}
.coach-takeaway {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--r-md);
  padding: 11px 14px;
  font-size: var(--text-sm);
  line-height: 1.5;
}
.coach-takeaway strong {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--signal);
  margin-bottom: 5px;
}

/* ─── Chat rows ──────────────────────────────────────────────── */
.row {
  display: flex;
  margin-bottom: var(--gap-md);
  animation: row-rise 0.4s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}
.row.right { justify-content: flex-end; }
@keyframes row-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.col {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  position: relative;
}
.row.right .col { align-items: flex-end; }

.who {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-warm);
  margin: 0 4px 5px;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: var(--text-base);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble-assistant {
  background: var(--bubble-asst-bg);
  border: 1px solid var(--bubble-asst-bd);
  color: #222430;
  border-top-left-radius: 5px;
}
.bubble-user {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-tx);
  border-top-right-radius: 5px;
}

/* condensed tag */
.condensed-tag {
  align-self: flex-start;
  margin-top: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-warm);
  border: 1px dashed #CDC4AD;
  border-radius: var(--r-full);
  padding: 2px 8px;
}
.row.right .condensed-tag { align-self: flex-end; }

/* typing caret */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--signal-deep);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 0.9s steps(1) infinite;
}
.bubble-user .caret { background: var(--signal); }
@keyframes blink { 50% { opacity: 0; } }

/* ─── Highlight: the fix/move turn ──────────────────────────── */
.highlight-band {
  position: absolute;
  left: -4px; right: -4px;
  top: 50%;
  height: 85%;
  background: var(--signal);
  border-radius: var(--r-sm);
  transform: translateY(-50%) scaleX(0);
  transform-origin: left;
  z-index: 0;
  opacity: 0;
}
.highlight-band.go {
  animation: band-swipe 0.5s 0.1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes band-swipe {
  from { transform: translateY(-50%) scaleX(0); opacity: 0; }
  20%  { opacity: 0.9; }
  to   { transform: translateY(-50%) scaleX(1); opacity: 0.9; }
}
.row.highlight .bubble-user { position: relative; z-index: 1; }

.highlight-label {
  position: absolute;
  right: 0;
  top: -22px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--signal);
  padding: 3px 10px;
  border-radius: var(--r-full);
  transform: rotate(-3deg) scale(0);
  transform-origin: right center;
  box-shadow: 0 3px 10px -3px rgba(0,0,0,0.3);
  z-index: 2;
}
.highlight-label.go {
  animation: label-pop 0.35s 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
@keyframes label-pop {
  to { transform: rotate(-3deg) scale(1); }
}

/* ─── Controls (absolute overlay at bottom of stage) ────────── */
.controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 10px 16px 14px;
  background: linear-gradient(to bottom, transparent, var(--paper) 40%);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  z-index: 20;
}

.ctrl-btn {
  width: 40px; height: 40px;
  border-radius: var(--r-full);
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(0,0,0,0.04);
  color: var(--ink-3);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ctrl-btn:hover { background: rgba(0,0,0,0.08); }
.ctrl-btn svg { width: 16px; height: 16px; fill: currentColor; }

.play-btn {
  width: 52px; height: 52px;
  border-radius: var(--r-full);
  border: none;
  background: var(--signal);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.play-btn:hover { background: #FFD020; }
.play-btn:active { transform: scale(0.95); }
.play-btn svg { width: 20px; height: 20px; fill: currentColor; }

.ctrl-spacer { flex: 1; }

.status-label {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-warm);
}

/* ─── Error state ────────────────────────────────────────────── */
.error-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap-md);
  background: var(--paper);
  color: var(--ink);
  padding: var(--gap-xl);
  text-align: center;
  z-index: 10;
}
.error-card.hidden { display: none; }
.error-card h2 { font-size: var(--text-lg); font-weight: 700; }
.error-card p  { font-size: var(--text-sm); color: #666; max-width: 28ch; }

/* ─── Loading state ──────────────────────────────────────────── */
.loading-card {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  gap: var(--gap-sm);
  z-index: 10;
}
.loading-card.hidden { display: none; }
.loading-dot {
  width: 7px; height: 7px;
  border-radius: var(--r-full);
  background: var(--paper-3);
  animation: loading-pulse 1.2s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes loading-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1; }
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .shell { padding: 12px 12px 0; align-items: flex-end; }
  .reel  {
    max-width: 100%;
    height: 96dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
}

/* ─── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .row, .highlight-band.go, .highlight-label.go, .seg.active::after {
    animation: none !important;
  }
  .highlight-band.go { opacity: 0.9; transform: translateY(-50%) scaleX(1); }
  .highlight-label.go { transform: rotate(-3deg) scale(1); }
}

/* ─── Focus ──────────────────────────────────────────────────── */
button:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}
