/* ── Reset & Variables ──────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green-900: #00205b;
  --green-700: #00205b;
  --green-500: #A2AAAD;
  --green-200: #0085ca;
  --green-50:  #d8e9f3;
  --slate-50:  #f0f4f8;
  --slate-100: #e8edf3;
  --slate-200: #d4dce8;
  --slate-400: #8fa3b8;
  --slate-600: #5a7184;
  --slate-800: #2b3a4a;
  --white:     #ffffff;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.07);
  --shadow:    0 2px 12px rgba(0,0,0,.09);
  --shadow-md: 0 4px 24px rgba(0,0,0,.12);
  --radius:    12px;
  --radius-sm: 8px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--slate-50);
  color: var(--slate-800);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────── */

header {
  background: linear-gradient(135deg, var(--green-900) 0%, var(--green-700) 100%);
  color: var(--white);
  padding: 28px 24px;
  box-shadow: 0 2px 10px rgba(27,67,50,.4);
}

.header-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 2px;
}

.tagline {
  font-size: 0.9rem;
  opacity: 0.82;
  font-weight: 400;
}

.header-badge {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Main layout ────────────────────────────────────────────────────── */

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

/* ── Card base ──────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Scenario Card ──────────────────────────────────────────────────── */

.scenario-card {
  padding: 22px;
}

.section-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--slate-600);
  margin-bottom: 8px;
}

.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--slate-600);
  pointer-events: none;
}

#scenario-select {
  width: 100%;
  padding: 12px 40px 12px 14px;
  border: 2px solid var(--slate-200);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--white);
  color: var(--slate-800);
  cursor: pointer;
  appearance: none;
  transition: border-color 0.18s;
}

#scenario-select:focus {
  outline: none;
  border-color: var(--green-500);
}

/* Scenario info panel */
.scenario-info {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--slate-100);
}

.scenario-info.hidden { display: none; }

.scenario-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.scenario-meta h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green-900);
  flex: 1;
  min-width: 160px;
}

.tag {
  background: var(--green-50);
  color: var(--green-700);
  border: 1px solid var(--green-200);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.scenario-desc {
  font-size: 0.9rem;
  color: var(--slate-600);
  line-height: 1.65;
  margin-bottom: 14px;
}

.goals-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--slate-600);
  margin-bottom: 7px;
}

.goals-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.goals-list li {
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  color: var(--slate-800);
  font-size: 0.8rem;
  padding: 4px 11px;
  border-radius: 6px;
}

.role-note {
  background: #ebfbff;
  border: 1px solid #8ac9fd;
  color: #0f2878;
  font-size: 0.82rem;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

/* ── Chat Card ──────────────────────────────────────────────────────── */

.chat-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
  gap: 10px;
}

.chat-who {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--green-900);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

#chat-character-label {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--slate-800);
}

.practice-badge {
  background: var(--green-50);
  color: var(--green-700);
  border: 1px solid var(--green-200);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* Chat window scrollable area */
.chat-window {
  height: 420px;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-window::-webkit-scrollbar { width: 6px; }
.chat-window::-webkit-scrollbar-thumb {
  background: var(--slate-200);
  border-radius: 3px;
}

/* Empty state */
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--slate-400);
}

.chat-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.chat-empty p {
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.chat-empty-sub {
  font-size: 0.82rem;
  opacity: 0.75;
}

/* Messages */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

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

.msg-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--slate-400);
  margin-bottom: 3px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
}

.msg.user .msg-bubble {
  background: var(--green-700);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.msg.resident .msg-bubble {
  background: var(--slate-100);
  color: var(--slate-800);
  border: 1px solid var(--slate-200);
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.msg.typing .msg-bubble {
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  padding: 12px 16px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--slate-400);
  border-radius: 50%;
  animation: tdot 1.3s infinite ease-in-out;
}

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

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

/* Input row */
.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 13px 16px;
  border-top: 1px solid var(--slate-200);
  background: var(--white);
}

#message-input {
  flex: 1;
  padding: 10px 13px;
  border: 2px solid var(--slate-200);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font);
  resize: none;
  line-height: 1.4;
  transition: border-color 0.18s;
}

#message-input:focus {
  outline: none;
  border-color: var(--green-500);
}

#message-input:disabled {
  background: var(--slate-50);
  cursor: not-allowed;
  color: var(--slate-400);
}

#send-btn {
  padding: 10px 22px;
  background: var(--green-700);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  align-self: flex-end;
  transition: background 0.18s;
  white-space: nowrap;
}

#send-btn:hover:not(:disabled) { background: var(--green-900); }

#send-btn:disabled {
  background: var(--slate-200);
  color: var(--slate-400);
  cursor: not-allowed;
}

/* ── Feedback Section ────────────────────────────────────────────────── */

.feedback-trigger-btn {
  width: 100%;
  padding: 14px;
  background: var(--white);
  color: var(--green-700);
  border: 2px solid var(--green-700);
  border-radius: var(--radius);
  font-size: 0.98rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.feedback-trigger-btn:hover:not(:disabled) {
  background: var(--green-700);
  color: var(--white);
}

.feedback-trigger-btn:disabled {
  border-color: var(--slate-200);
  color: var(--slate-400);
  cursor: not-allowed;
}

.feedback-card {
  overflow: hidden;
  margin-top: 16px;
}

.feedback-card.hidden { display: none; }

.feedback-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--green-900);
  color: var(--white);
  gap: 12px;
}

.feedback-topbar h3 {
  font-size: 0.98rem;
  font-weight: 700;
}

.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 5px 13px;
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.18s;
  white-space: nowrap;
}

.btn-ghost:hover { background: rgba(255,255,255,0.22); }

.feedback-body {
  padding: 22px;
  font-size: 0.91rem;
  line-height: 1.75;
  color: var(--slate-800);
}

/* Rendered feedback markdown styles */
.feedback-body h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green-900);
  margin-top: 14px;
  margin-bottom: 6px;
}

.feedback-body h4:first-child { margin-top: 0; }

.feedback-body ul {
  list-style: none;
  margin-bottom: 10px;
}

.feedback-body ul li {
  padding: 4px 0 4px 20px;
  position: relative;
  color: var(--slate-800);
}

.feedback-body ul li::before {
  content: '•';
  position: absolute;
  left: 6px;
  color: var(--green-500);
  font-weight: 700;
}

.feedback-body p { margin-bottom: 8px; }

.feedback-body strong { color: var(--green-900); font-weight: 700; }

/* Loading spinner */
.feedback-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--slate-600);
  font-size: 0.88rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--slate-200);
  border-top-color: var(--green-500);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Footer ────────────────────────────────────────────────────────── */

footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 0.78rem;
  color: var(--slate-600);
  border-top: 1px solid var(--slate-200);
  background: var(--white);
  margin-top: auto;
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 500px) {
  header h1 { font-size: 1.4rem; }
  .header-badge { display: none; }
  .chat-window { height: 350px; }
  .msg { max-width: 88%; }
}
