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

:root {
  --rose:      #c0556a;
  --rose-lt:   #f5dde2;
  --rose-dk:   #8c3348;
  --gold:      #c8973a;
  --gold-lt:   #fdf3e3;
  --bg:        #fdf8f5;
  --surface:   #ffffff;
  --border:    #e8ddd6;
  --text:      #2d1f1a;
  --text-muted:#7a6560;
  --radius:    14px;
  --radius-sm: 8px;
  --shadow:    0 2px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.14);
  --font:      'Georgia', 'Times New Roman', serif;
  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────── */
header {
  background: var(--rose);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 10;
}

.logo { font-size: 22px; }

header h1 {
  font-family: var(--font);
  font-size: 18px;
  font-weight: normal;
  letter-spacing: .3px;
  flex: 1;
}

header h1 small {
  display: block;
  font-size: 11px;
  opacity: .8;
  font-family: var(--font-ui);
  letter-spacing: .5px;
  text-transform: uppercase;
}

#progress-toggle {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .2s;
}

#progress-toggle:hover { background: rgba(255,255,255,.3); }

/* ── Progress panel ───────────────────────────────────────────────────── */
#progress-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  transition: max-height .35s ease;
  flex-shrink: 0;
}

#progress-panel.open { max-height: 320px; overflow-y: auto; }

.progress-inner {
  padding: 16px;
}

.progress-bar-wrap {
  background: var(--rose-lt);
  border-radius: 20px;
  height: 10px;
  margin-bottom: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  background: linear-gradient(90deg, var(--rose), var(--gold));
  height: 100%;
  border-radius: 20px;
  transition: width .6s ease;
}

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
}

.unit-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.unit-chip.done {
  background: var(--rose-lt);
  border-color: var(--rose);
  color: var(--rose-dk);
}

.unit-chip.current {
  background: var(--gold-lt);
  border-color: var(--gold);
  font-weight: 600;
}

.unit-chip .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.unit-chip.done .dot   { background: var(--rose); }
.unit-chip.current .dot { background: var(--gold); }

/* ── Chat area ────────────────────────────────────────────────────────── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ── Message bubbles ──────────────────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  position: relative;
}

.msg.user .bubble {
  background: var(--rose);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

/* Persian script within bubbles */
.bubble .farsi {
  font-family: 'Arial', sans-serif;
  font-size: 17px;
  direction: rtl;
  display: inline-block;
}

/* Tip/cultural note formatting */
.bubble .tip {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--gold-lt);
  border-left: 3px solid var(--gold);
  padding: 6px 10px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg.assistant .bubble em {
  color: var(--rose-dk);
  font-style: normal;
  font-weight: 500;
}

/* Partner name label */
.msg-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Per-word speak button (next to phonetic) */
.word-speak-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1px 7px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-muted);
  vertical-align: middle;
  margin: 0 2px;
  transition: all .15s;
  line-height: 1.6;
}

.word-speak-btn:hover {
  background: var(--rose-lt);
  border-color: var(--rose);
  color: var(--rose);
}

.word-speak-btn.speaking {
  background: var(--rose-lt);
  color: var(--rose);
  border-color: var(--rose);
}

/* Whole-message speak button */
.speak-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all .15s;
}

.speak-btn:hover {
  background: var(--rose-lt);
  border-color: var(--rose);
  color: var(--rose);
}

.speak-btn.speaking {
  background: var(--rose-lt);
  color: var(--rose);
  animation: pulse-soft 1.2s ease-in-out infinite;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
  align-items: center;
}

.typing-dots span {
  width: 8px; height: 8px;
  background: var(--rose);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
  opacity: .5;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input bar ────────────────────────────────────────────────────────── */
#input-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

#mic-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--rose);
  background: var(--rose-lt);
  color: var(--rose);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .18s;
}

#mic-btn:hover {
  background: var(--rose);
  color: #fff;
}

#mic-btn.recording {
  background: var(--rose);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
  border-color: var(--rose-dk);
}

#mic-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

#text-input {
  flex: 1;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  font-family: var(--font-ui);
  color: var(--text);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color .18s;
}

#text-input:focus {
  outline: none;
  border-color: var(--rose);
}

#text-input::placeholder { color: var(--text-muted); }

#send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--rose);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .18s, transform .1s;
}

#send-btn:hover { background: var(--rose-dk); }
#send-btn:active { transform: scale(.93); }
#send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Mic overlay ──────────────────────────────────────────────────────── */
#mic-overlay {
  position: fixed;
  inset: 0;
  background: rgba(192, 85, 106, .92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 100;
  backdrop-filter: blur(4px);
}

#mic-overlay.active { display: flex; }

.mic-ring {
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  animation: pulse 1.2s ease-in-out infinite;
  border: 3px solid rgba(255,255,255,.5);
}

.mic-hint {
  color: #fff;
  font-size: 17px;
  text-align: center;
  opacity: .9;
}

#mic-transcript {
  color: #fff;
  font-size: 16px;
  font-style: italic;
  opacity: .85;
  max-width: 280px;
  text-align: center;
  min-height: 24px;
}

#mic-cancel {
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.5);
  color: #fff;
  border-radius: 24px;
  padding: 10px 28px;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s;
}

#mic-cancel:hover { background: rgba(255,255,255,.35); }

.mic-actions { display: flex; gap: 12px; }

#mic-done {
  background: #fff;
  border: 2px solid #fff;
  color: var(--rose-dk);
  border-radius: 24px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#mic-done:disabled { opacity: .6; cursor: default; }

/* Speaking-language toggle (Farsi / English) */
#lang-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--gold-lt);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Animations ───────────────────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.5); }
  50%       { box-shadow: 0 0 0 14px rgba(255,255,255,0); }
}

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50%       { opacity: .6; }
}

/* ── Welcome / empty state ────────────────────────────────────────────── */
#welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

#welcome .welcome-rose { font-size: 48px; margin-bottom: 12px; }

#welcome h2 {
  font-family: var(--font);
  font-size: 22px;
  color: var(--rose);
  margin-bottom: 8px;
  font-weight: normal;
}

#welcome p {
  font-size: 14px;
  line-height: 1.7;
  max-width: 300px;
  margin: 0 auto;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
main::-webkit-scrollbar { width: 5px; }
main::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile tweaks ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  header h1 { font-size: 16px; }
  .bubble { font-size: 14px; }
  .msg { max-width: 90%; }
  #progress-panel.open { max-height: 260px; }
}

/* ── Progress pop-up & fresh conversation ─────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  max-width: calc(100% - 32px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 50;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

#new-chat {
  margin-top: 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
