/* ── Variables ─────────────────────────────────────── */
:root {
  --bg:         #0d1117;
  --bg-card:    #161b22;
  --bg-input:   #1c2128;
  --bg-hover:   #21262d;
  --border:     #30363d;
  --border-light: #40474f;
  --text:       #f0ece3;
  --text-dim:   #8b949e;
  --text-muted: #4a5568;
  --accent:     #d4962a;
  --accent-dim: rgba(212, 150, 42, 0.15);
  --accent-hover: #e5a73a;
  --success:    #3fb950;
  --success-dim: rgba(63, 185, 80, 0.12);
  --danger:     #f85149;
  --radius:     10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
  --font-head:  "Playfair Display", Georgia, serif;
  --font-body:  "DM Sans", system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
#app { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
button { font-family: var(--font-body); cursor: pointer; border: none; outline: none; }
textarea, input { font-family: var(--font-body); outline: none; }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 100px var(--bg-input) inset !important; -webkit-text-fill-color: var(--text) !important; }

/* ── Splash ─────────────────────────────────────────── */
.splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 32px; background: var(--bg); z-index: 999;
}
.splash-logo { display: flex; align-items: center; gap: 12px; font-family: var(--font-head); font-size: 1.8rem; font-weight: 700; }
.splash-spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page transitions ───────────────────────────────── */
.page-enter { animation: pageIn 0.25s ease both; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.page-exit { animation: pageOut 0.15s ease both; }
@keyframes pageOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ── Layout ─────────────────────────────────────────── */
.page { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 900px; margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo-mark {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-head); font-size: 1.15rem; font-weight: 700;
  color: var(--text); cursor: pointer;
}
.logo-mark svg { flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 12px; }

.page-body { flex: 1; max-width: 900px; margin: 0 auto; width: 100%; padding: 40px 24px; }
.page-body--narrow { max-width: 680px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  transition: background var(--transition), transform 0.1s, opacity var(--transition);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-hover); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-light); }

.btn-ghost {
  background: transparent; color: var(--text-dim);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger {
  background: rgba(248,81,73,0.1); color: var(--danger);
  border: 1px solid rgba(248,81,73,0.2);
}
.btn-danger:hover { background: rgba(248,81,73,0.2); }

.btn-lg { padding: 12px 28px; font-size: 1rem; border-radius: var(--radius-lg); }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover); color: var(--text-dim);
  border: 1px solid var(--border); font-size: 1rem;
  transition: all var(--transition);
}
.btn-icon:hover { color: var(--text); border-color: var(--border-light); }

.btn-back {
  display: flex; align-items: center; gap: 6px;
  background: none; color: var(--text-dim); font-size: 0.875rem;
  padding: 6px 10px; border-radius: 8px;
  transition: color var(--transition), background var(--transition);
}
.btn-back:hover { color: var(--text); background: var(--bg-hover); }

/* ── XP Badge ────────────────────────────────────────── */
.xp-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 99px;
  background: var(--accent-dim);
  border: 1px solid rgba(212,150,42,0.3);
  font-size: 0.8rem; font-weight: 600;
}
.xp-level { color: var(--accent); }
.xp-points { color: var(--text-dim); }

/* ── Login ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(212,150,42,0.08), transparent);
}
.login-card {
  width: 100%; max-width: 400px;
  padding: 48px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 36px; text-align: center;
}
.login-logo h1 { font-family: var(--font-head); font-size: 2rem; font-weight: 700; }
.login-logo p { color: var(--text-dim); font-size: 0.9rem; }
.login-logo svg { margin-bottom: 4px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: var(--text-dim); margin-bottom: 7px; letter-spacing: 0.04em; text-transform: uppercase;
}
.form-input {
  width: 100%; padding: 11px 14px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; transition: border-color var(--transition);
}
.form-input:focus { border-color: var(--accent); }
.error-msg {
  color: var(--danger); font-size: 0.85rem;
  padding: 10px 14px; margin-bottom: 16px;
  background: rgba(248,81,73,0.08); border-radius: 8px;
  border: 1px solid rgba(248,81,73,0.2);
}

/* ── Courses grid ────────────────────────────────────── */
.page-hero {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 32px; gap: 16px;
}
.page-hero h2 { font-family: var(--font-head); font-size: 2rem; font-weight: 700; }

.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.course-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex; flex-direction: column; gap: 16px;
  position: relative; overflow: hidden;
}
.course-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent); opacity: 0;
  transition: opacity var(--transition);
}
.course-card:hover { border-color: var(--border-light); transform: translateY(-2px); box-shadow: var(--shadow); }
.course-card:hover::before { opacity: 1; }

.course-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.course-card h3 { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.progress-ring { flex-shrink: 0; position: relative; width: 44px; height: 44px; }
.progress-ring svg { width: 44px; height: 44px; transform: rotate(-90deg); }
.progress-ring-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 600; color: var(--accent);
}
.course-card-meta { font-size: 0.8rem; color: var(--text-dim); }
.course-card-footer { display: flex; align-items: center; gap: 8px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 99px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-accent  { background: var(--accent-dim);  color: var(--accent); }

/* skeleton */
.skeleton { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.skeleton-card { height: 160px; animation: shimmer 1.5s ease infinite; }
@keyframes shimmer {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

/* empty / error state */
.empty-state, .error-state {
  text-align: center; padding: 64px 24px;
  color: var(--text-dim); grid-column: 1/-1;
}
.empty-icon { font-size: 3rem; display: block; margin-bottom: 16px; }
.empty-state h3 { font-family: var(--font-head); font-size: 1.4rem; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 24px; }

/* ── Course wizard ───────────────────────────────────── */
.wizard { display: flex; flex-direction: column; gap: 20px; }
.wizard-header { margin-bottom: 4px; }
.wizard-header h2 { font-family: var(--font-head); font-size: 1.8rem; margin-bottom: 6px; }
.wizard-header p { color: var(--text-dim); }

.wizard-chat { display: flex; flex-direction: column; gap: 12px; }
.wizard-msg {
  max-width: 80%; padding: 12px 16px;
  border-radius: 14px; font-size: 0.9rem; line-height: 1.5; word-break: break-word;
}
.wizard-msg-user {
  align-self: flex-end;
  background: var(--accent); color: white;
  border-bottom-right-radius: 4px;
}
.wizard-msg-assistant {
  align-self: flex-start;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.wizard-msg-thinking { color: var(--text-dim); font-style: italic; }

.wizard-preview {
  background: var(--bg-card); border: 1px solid var(--accent);
  border-radius: var(--radius-lg); padding: 24px;
  animation: pageIn 0.2s ease;
}
.preview-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.preview-head h3 { font-family: var(--font-head); font-size: 1.25rem; flex: 1; }
.preview-sessions { display: flex; flex-direction: column; gap: 10px; }
.preview-session {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 12px; background: var(--bg-input); border-radius: 8px;
  border: 1px solid var(--border);
}
.preview-session-num {
  width: 24px; height: 24px; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; margin-top: 1px;
}
.preview-session strong { font-size: 0.9rem; display: block; margin-bottom: 2px; }
.preview-session p { font-size: 0.8rem; color: var(--text-dim); }

.wizard-input-area { display: flex; flex-direction: column; gap: 12px; }
.wizard-input-row { display: flex; gap: 10px; align-items: flex-end; }
.wizard-textarea {
  flex: 1; padding: 12px 14px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  resize: none; font-size: 0.95rem; line-height: 1.5;
  transition: border-color var(--transition);
  min-height: 56px; max-height: 160px;
}
.wizard-textarea:focus { border-color: var(--accent); }
.wizard-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-send {
  padding: 0 20px; height: 56px; flex-shrink: 0;
  background: var(--accent); color: white;
  border-radius: var(--radius); font-size: 1.1rem;
  transition: background var(--transition);
}
.btn-send:hover { background: var(--accent-hover); }

/* ── Session list ────────────────────────────────────── */
.session-list-header { margin-bottom: 28px; }
.session-list-header h2 { font-family: var(--font-head); font-size: 1.8rem; margin-bottom: 4px; }
.session-list-sub { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 16px; }
.progress-bar-wrap { }
.progress-bar {
  height: 4px; background: var(--bg-hover);
  border-radius: 99px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.6s ease; }

.sessions-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 40px; }
.session-item {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition), transform var(--transition), background var(--transition);
  text-decoration: none; color: var(--text);
}
.session-item--active { cursor: pointer; }
.session-item--active:hover { border-color: var(--border-light); transform: translateX(4px); background: var(--bg-hover); }
.session-item--completed { opacity: 0.55; cursor: default; }

.session-item-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}
.session-item-icon--active { background: var(--accent-dim); color: var(--accent); border: 1.5px solid var(--accent); }
.session-item-icon--done   { background: var(--success-dim); color: var(--success); font-size: 1rem; }

.session-item-text { flex: 1; }
.session-item-text strong { display: block; font-size: 0.95rem; font-weight: 500; margin-bottom: 2px; }
.session-item-text span { font-size: 0.82rem; color: var(--text-dim); }
.session-item-arrow { color: var(--text-muted); font-size: 1rem; }
.session-item--active:hover .session-item-arrow { color: var(--accent); }

.extend-section { padding: 16px 0; text-align: center; }
.btn-extend {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 32px; border-radius: var(--radius-xl);
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); font-size: 0.95rem; font-weight: 500;
  transition: all var(--transition);
  width: 100%; justify-content: center;
}
.btn-extend:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ── Session chat ────────────────────────────────────── */
.chat-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.chat-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.session-title-sm { font-size: 0.85rem; color: var(--text-dim); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
  /* thin scrollbar */
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg--user { align-self: flex-end; align-items: flex-end; }
.chat-msg--assistant { align-self: flex-start; align-items: flex-start; max-width: 90%; }

.chat-bubble {
  padding: 14px 18px; border-radius: 18px;
  font-size: 0.93rem; line-height: 1.65; word-break: break-word;
}
.chat-msg--user .chat-bubble {
  background: var(--accent); color: white; border-bottom-right-radius: 4px;
}
.chat-msg--assistant .chat-bubble {
  background: var(--bg-card); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; color: var(--text);
}

/* Markdown inside chat bubble */
.chat-bubble h1,.chat-bubble h2,.chat-bubble h3 {
  font-family: var(--font-head); margin: 16px 0 8px; font-weight: 700;
}
.chat-bubble h1 { font-size: 1.3rem; }
.chat-bubble h2 { font-size: 1.1rem; }
.chat-bubble h3 { font-size: 1rem; }
.chat-bubble h1:first-child,.chat-bubble h2:first-child,.chat-bubble h3:first-child { margin-top: 0; }
.chat-bubble p { margin-bottom: 10px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul,.chat-bubble ol { padding-left: 20px; margin-bottom: 10px; }
.chat-bubble li { margin-bottom: 4px; }
.chat-bubble code {
  font-size: 0.85em; padding: 1px 6px;
  background: var(--bg-input); border-radius: 4px; border: 1px solid var(--border);
  font-family: "Menlo", "Consolas", monospace;
}
.chat-bubble pre {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; overflow-x: auto;
  margin-bottom: 10px;
}
.chat-bubble pre code { background: none; border: none; padding: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble em { font-style: italic; color: var(--text-dim); }
.chat-bubble blockquote {
  border-left: 3px solid var(--accent); padding-left: 14px;
  color: var(--text-dim); margin: 8px 0;
}
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Typing indicator */
.typing-indicator {
  display: flex; gap: 5px; align-items: center;
  padding: 16px 20px !important;
}
.typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%; background: var(--text-dim);
  animation: typing 1.2s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%,80%,100% { transform: scale(0.7); opacity: 0.4; }
  40%          { transform: scale(1);   opacity: 1; }
}

/* Completion banner */
.completion-banner {
  border-top: 1px solid var(--border);
  background: linear-gradient(to right, rgba(212,150,42,0.06), transparent);
  padding: 20px 24px;
  display: flex; align-items: center; justify-content: center;
}
.completion-content {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  justify-content: center; text-align: center;
}
.completion-icon { font-size: 1.8rem; }
.completion-content p { color: var(--text-dim); font-size: 0.9rem; }

/* Chat input */
.chat-input-wrap {
  border-top: 1px solid var(--border);
  padding: 16px 24px; background: var(--bg);
}
.chat-input-row {
  display: flex; gap: 10px; align-items: flex-end;
  max-width: 900px; margin: 0 auto;
}
.chat-textarea {
  flex: 1; padding: 12px 16px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px;
  resize: none; font-size: 0.93rem; line-height: 1.5;
  min-height: 48px; max-height: 140px;
  transition: border-color var(--transition);
}
.chat-textarea:focus { border-color: var(--accent); }
.btn-send-chat {
  width: 48px; height: 48px; flex-shrink: 0;
  background: var(--accent); color: white; border-radius: 14px;
  font-size: 1.2rem; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), transform 0.1s;
}
.btn-send-chat:hover { background: var(--accent-hover); }
.btn-send-chat:active { transform: scale(0.95); }
.btn-send-chat:disabled { opacity: 0.4; pointer-events: none; }

/* Disabled input area */
.input-disabled { opacity: 0.5; pointer-events: none; }
