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

:root {
  --navy:   #0d2b45;
  --navy2:  #163d5e;
  --gold:   #c9a227;
  --gold2:  #e8bc30;
  --bg:     #f0ede8;
  --card:   #ffffff;
  --text:   #1a1a1a;
  --muted:  #5a5a5a;
  --red:    #c0392b;
  --green:  #1e8449;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.10);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}
.header-brand { display: flex; flex-direction: column; gap: 2px; }
.header-title { font-size: 1.05rem; font-weight: 700; letter-spacing: .2px; line-height: 1.2; }
.header-sub   { font-size: .72rem; color: var(--gold); letter-spacing: .6px; text-transform: uppercase; }

/* user row (name + sessions + logout) */
.header-user-row  { display: flex; align-items: center; gap: 10px; }
.header-user-left { display: flex; align-items: center; gap: 8px; }

/* session bar — second row inside header */
.session-bar {
  max-width: 680px;
  margin: 0 auto;
  padding: 7px 16px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255,255,255,.1);
}
.session-bar-actions { display: flex; align-items: center; gap: 8px; }

/* buttons */
.btn-end {
  background: transparent;
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s, border-color .18s;
  white-space: nowrap;
}
.btn-end:hover        { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.6); }
.btn-end-sm           { padding: 4px 11px; font-size: .77rem; }
.btn-end-danger       { border-color: rgba(239,83,80,.55); color: #ff8a80; }
.btn-end-danger:hover { background: rgba(239,83,80,.15); border-color: #ef5350; color: #fff; }

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Welcome / idle ──────────────────────────────────────────────────────── */
.welcome-wrap {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.welcome-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  max-width: 460px;
  width: 100%;
  text-align: center;
}
.crest { font-size: 3rem; margin-bottom: 8px; }
.welcome-card h2 {
  font-size: 1.6rem;
  color: var(--navy);
  margin-bottom: 12px;
}
.welcome-desc {
  color: var(--muted);
  margin-bottom: 20px;
  font-size: .95rem;
}
.feature-list {
  list-style: none;
  text-align: left;
  margin: 0 0 28px;
  display: inline-block;
}
.feature-list li {
  padding: 4px 0 4px 24px;
  position: relative;
  font-size: .9rem;
  color: var(--muted);
}
.feature-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--gold);
  font-weight: 700;
}
.hint {
  margin-top: 14px;
  font-size: .78rem;
  color: var(--muted);
}

/* ── Subject picker ──────────────────────────────────────────────────────── */
.subject-section { margin: 20px 0 22px; text-align: left; }
.subject-prompt  { font-size: .85rem; font-weight: 600; color: var(--navy);
                   margin-bottom: 10px; text-align: center; }
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn-subject {
  background: #f0ede8;
  border: 1.5px solid #d4d0ca;
  border-radius: 8px;
  padding: 10px 8px;
  font-size: .88rem;
  font-weight: 500;
  color: var(--navy);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  text-align: center;
}
.btn-subject:hover    { background: #e4e0d8; }
.btn-subject.selected {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

/* Subject badge — shown in session bar */
.subject-badge {
  font-size: .78rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(201,162,39,.18);
  border-radius: 20px;
  padding: 3px 12px;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 20px 16px 28px;
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.7;
}
.app-footer strong { color: var(--text); }
.app-footer a { color: var(--navy); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ── Session screen layout ───────────────────────────────────────────────── */
#screen-session {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px 120px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  margin-bottom: 14px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold);
  text-transform: uppercase;
}
.q-num {
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  background: #f0ede8;
  border-radius: 20px;
  padding: 2px 10px;
}

/* Question text — large and readable */
.q-text {
  font-size: 1.12rem;
  line-height: 1.65;
  color: var(--navy);
  font-weight: 500;
  white-space: pre-wrap;
}

/* Feedback text */
.fb-text {
  font-size: .93rem;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--text);
}

/* Colour-code feedback keywords */
.fb-text .got-right { color: var(--green); font-weight: 600; }
.fb-text .got-wrong  { color: var(--red);   font-weight: 600; }
.fb-text .model-ans  { color: var(--navy);  font-weight: 600; }

.btn-next-q {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  font-size: 1rem;
}

/* ── Mode buttons (Start Session / Ask a Question) ───────────────────────── */
.mode-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Q&A screen ──────────────────────────────────────────────────────────── */
#screen-qa {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px 80px;
}
#qa-wrap { display: flex; flex-direction: column; gap: 14px; }

.qa-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 8px;
}
.btn-qa-back {
  background: none;
  border: none;
  color: var(--navy);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  white-space: nowrap;
}
.btn-qa-back:hover { text-decoration: underline; }
.qa-subject-label {
  font-size: .82rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(201,162,39,.15);
  border-radius: 20px;
  padding: 3px 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.qa-credit-note {
  font-size: .73rem;
  color: var(--muted);
  font-style: italic;
}
#qa-voice-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 0 4px;
}
/* ── Q&A conversation thread ──────────────────────────────────────────────── */
.qa-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e8e4de;
}
.qa-thread-title {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.qa-thread-actions { display: flex; gap: 8px; align-items: center; }
.btn-new-topic {
  font-size: .8rem;
  padding: 4px 12px;
}
.qa-copy-btn {
  background: none;
  border: 1px solid #d0cdc8;
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: .77rem;
  cursor: pointer;
  transition: background .15s;
}
.qa-copy-btn:hover { background: #f0ede8; color: var(--text); }

/* Each Q&A exchange */
.qa-turn { margin-bottom: 20px; }
.qa-bubble-q,
.qa-bubble-a {
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  font-size: .95rem;
  line-height: 1.6;
}
.qa-bubble-q {
  background: #eef2fb;
  border-left: 3px solid #5b7fcb;
  color: var(--text);
}
.qa-bubble-a {
  background: var(--card);
  border: 1px solid #e8e4de;
  border-left: 3px solid var(--gold);
}
.qa-label {
  display: block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.qa-answer-body { color: var(--text); }

.qa-streaming::after {
  content: "▋";
  display: inline-block;
  animation: blink .7s step-start infinite;
  color: var(--gold);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.qa-followup-hint {
  font-size: .83rem;
  color: var(--muted);
  text-align: center;
  padding: 8px 12px;
  background: #faf9f7;
  border-radius: 6px;
  margin: 6px 0 14px;
  border: 1px dashed #d8d4ce;
}

/* ── Session complete card ────────────────────────────────────────────────── */
.complete-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  padding: 24px 22px 22px;
  margin-bottom: 14px;
  border-top: 4px solid var(--gold);
}
.complete-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.complete-check-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #e8f5e9;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.complete-check {
  font-size: 1.6rem;
  color: var(--green);
  line-height: 1;
}
.complete-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}
.complete-meta {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 3px;
}
.complete-summary-text {
  font-size: .93rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  padding: 14px 16px;
  background: #fdf8f2;
  border-radius: 8px;
  border-left: 3px solid var(--gold);
  margin-bottom: 16px;
}
.complete-summary-text strong { color: var(--navy); }
.complete-another-offer {
  background: #f0f4ff;
  border: 1px solid #c5d1f0;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.complete-sessions-note {
  font-size: .87rem;
  color: #1a3a6e;
  margin-bottom: 10px;
  line-height: 1.5;
}
.btn-complete-continue {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-complete-continue:hover { background: var(--navy2); }
.complete-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-complete-print {
  flex: 1;
  background: transparent;
  border: 1.5px solid var(--navy);
  color: var(--navy);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-complete-print:hover { background: rgba(13,43,69,.07); }
.btn-complete-done {
  flex: 1;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-complete-done:hover { background: var(--navy2); }

.btn-listen {
  background: none;
  border: none;
  color: var(--navy2);
  font-size: .82rem;
  cursor: pointer;
  margin-top: 10px;
  padding: 4px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-listen:hover { color: var(--gold); }

/* ── Answer area ─────────────────────────────────────────────────────────── */
#answer-area {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* Transcript */
.transcript-wrap { margin-bottom: 14px; }
.transcript-wrap .card-label { margin-bottom: 8px; display: block; }
.transcript-text {
  min-height: 60px;
  background: #f8f7f4;
  border-radius: 8px;
  padding: 12px;
  font-size: .95rem;
  color: var(--text);
  border: 1px solid #e0ddd8;
}

/* Voice controls */
#voice-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Mic button */
.btn-mic {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: none;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 4px 16px rgba(13,43,69,.35);
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn-mic:active { transform: scale(.94); }
.btn-mic.recording {
  background: var(--red);
  animation: pulse 1.2s infinite;
}
.mic-icon  { font-size: 1.7rem; line-height: 1; }
.mic-label { font-size: .65rem; letter-spacing: .5px; text-transform: uppercase; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(192,57,43,.4); }
  50%       { box-shadow: 0 4px 28px rgba(192,57,43,.7); }
}

/* Text mode */
#text-area { display: flex; flex-direction: column; gap: 10px; }
textarea {
  width: 100%;
  border: 1px solid #d0cdc8;
  border-radius: 8px;
  padding: 12px;
  font-size: .95rem;
  font-family: inherit;
  resize: vertical;
  background: #fafaf8;
  color: var(--text);
}
textarea:focus { outline: none; border-color: var(--navy); }
.text-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--navy2); }

.btn-xl {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  border-radius: 10px;
}

.btn-secondary {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--navy);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: .88rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: rgba(13,43,69,.07); }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 28px;
  color: var(--muted);
  font-size: .9rem;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #ddd;
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: .88rem;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.toast.error { background: var(--red); }

/* ── Auth screen ─────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 14px 32px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px 24px;
  max-width: 480px;
  width: 100%;
}
.auth-card .crest { text-align: center; }
.auth-card h2 {
  font-size: 1.35rem;
  color: var(--navy);
  margin-bottom: 4px;
  text-align: center;
}
.auth-card .welcome-desc { text-align: center; margin-bottom: 22px; }

/* Stay-on-page notice */
.stay-notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #f0f7ee;
  border: 1px solid #b8ddb4;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 14px 0 4px;
  font-size: .88rem;
  line-height: 1.5;
  color: #2d5a27;
}
.stay-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 1px; }

/* Auto-poll status line */
.poll-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--muted);
  margin: 8px 0 12px;
  min-height: 22px;
}
.poll-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green, #4caf50);
  flex-shrink: 0;
  animation: pollPulse 1.4s ease-in-out infinite;
}
@keyframes pollPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .35; transform: scale(.7); }
}

/* Fields */
.auth-field {
  margin-bottom: 15px;
}
.auth-field label {
  display: block;
  font-size: .8rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.auth-field input[type="text"],
.auth-field input[type="tel"] {
  display: block;
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid #d0cdc8;
  border-radius: 9px;
  font-size: 1rem;
  font-family: inherit;
  background: #fafaf8;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.auth-field input:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(13,43,69,.1);
}
/* ── No-sessions / topup panel ───────────────────────────────────────────── */
.no-sessions-box {
  background: #fff8e1;
  border: 1.5px solid #e8bc3066;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  text-align: left;
}
.no-sessions-title {
  font-weight: 700;
  color: var(--navy);
  font-size: .95rem;
  margin-bottom: 5px;
}
.no-sessions-desc {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}
#topup-plan-grid { margin-bottom: 4px; }

.credits-note {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  margin: 14px 0 10px;
  line-height: 1.55;
  font-style: italic;
}
.auth-switch {
  margin-top: 18px;
  font-size: .88rem;
  color: var(--muted);
  text-align: center;
}
.auth-switch a { color: var(--navy); font-weight: 700; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* Plan grid — 2 col on desktop, 1 col on mobile */
.plan-grid {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 6px;
}
@media (min-width: 480px) {
  .plan-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }
}
.plan-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid #e0ddd8;
  border-radius: 10px;
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  background: #fafaf8;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.plan-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0; height: 0;
}
/* Custom radio dot */
.plan-card::before {
  content: "";
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #c0bdb8;
  background: #fff;
  transition: border-color .15s, background .15s;
}
.plan-card:active { background: #edeae5; }
.plan-card.selected {
  border-color: var(--navy);
  background: rgba(13,43,69,.05);
  box-shadow: 0 0 0 1px var(--navy);
}
.plan-card.selected::before {
  border-color: var(--navy);
  background: var(--navy);
  box-shadow: inset 0 0 0 4px #fff;
}
.plan-card.plan-group { border-color: #ddd8c4; }
.plan-card.plan-group.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
  background: rgba(201,162,39,.06);
}
.plan-card.plan-group.selected::before {
  border-color: var(--gold);
  background: var(--gold);
  box-shadow: inset 0 0 0 4px #fff;
}
.plan-info { flex: 1; min-width: 0; }
.plan-name   { font-size: .9rem;  font-weight: 700; color: var(--navy); }
.plan-price  { font-size: .88rem; font-weight: 600; color: var(--gold); margin-top: 1px; }
.plan-detail { font-size: .75rem; color: var(--muted); margin-top: 1px; }

/* Payment box */
.payment-box {
  background: #fffbee;
  border: 1.5px solid #e8bc3055;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 14px 0 2px;
  font-size: .88rem;
  color: var(--text);
  line-height: 1.65;
}
.payment-box p { margin-bottom: 6px; }
.payment-box p:last-child { margin-bottom: 0; }
.pay-title {
  font-weight: 700;
  color: var(--navy);
  font-size: .78rem;
  letter-spacing: .6px;
  text-transform: uppercase;
  margin-bottom: 8px !important;
}

/* User badge in header */
.user-badge {
  font-size: .82rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sessions-badge {
  font-size: .72rem;
  font-weight: 700;
  color: var(--navy);
  background: var(--gold);
  border-radius: 20px;
  padding: 2px 9px;
  white-space: nowrap;
}

/* ── Helpers ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
