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

:root {
  --bg:        #0d0d0f;
  --surface:   #18181c;
  --surface2:  #222228;
  --border:    #2e2e38;
  --accent:    #7c6af7;
  --accent-hi: #9e8fff;
  --red:       #e05555;
  --green:     #4caf7d;
  --text:      #f0f0f5;
  --text-dim:  #8888a0;
  --text-sub:  #555568;
  --safe-t: env(safe-area-inset-top,    0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left,   0px);
  --safe-r: env(safe-area-inset-right,  0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app { height: 100%; display: flex; flex-direction: column; }

/* ── Screen shell ──────────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
.screen.active { display: flex; }

.scroll-area { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.75rem 1.5rem;
  border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  min-height: 52px;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); }
.btn-sm      { padding: 0.5rem 1rem; font-size: 0.85rem; min-height: 38px; border-radius: 9px; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-full    { width: 100%; }

/* Icon button */
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--border); }

/* Back button */
.back-btn {
  background: none; border: none;
  color: var(--accent-hi); font-size: 0.95rem; font-weight: 600;
  cursor: pointer; padding: 0.2rem 0;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; gap: 0.25rem;
}

/* ── Form inputs ──────────────────────────────────────────────────────────── */
input[type="text"], input[type="number"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.65rem 0.9rem;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-sub); }

label {
  font-size: 0.78rem; color: var(--text-dim);
  font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  display: block; margin-bottom: 0.4rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field-row { display: flex; gap: 0.6rem; align-items: flex-end; }

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── HOME SCREEN ──────────────────────────────────────────────────────────── */

[data-screen="home"] {
  justify-content: space-between;
  padding: 1.2rem 1.6rem;
}

.home-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--safe-t);
}

.home-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
}

.home-title {
  font-size: clamp(2.8rem, 12vw, 5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.home-subtitle {
  font-size: 1.05rem;
  color: var(--text-dim);
  font-weight: 500;
}

.home-model {
  font-size: 0.8rem;
  color: var(--text-sub);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.7rem;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-bottom { padding-bottom: var(--safe-b); }

.start-btn {
  width: 100%;
  padding: 1.1rem;
  font-size: 1.4rem;
  font-weight: 800;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, opacity 0.15s;
  letter-spacing: 0.02em;
}
.start-btn:active { transform: scale(0.97); opacity: 0.85; }

.gen-status { font-size: 0.82rem; color: var(--text-dim); text-align: center; min-height: 1em; margin-top: 0.4rem; }
.gen-status.error { color: var(--red); }

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── SETTINGS SCREEN ──────────────────────────────────────────────────────── */

.settings-header {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.4rem 0.8rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-header h1 { font-size: 1.2rem; font-weight: 700; }

.settings-body { padding: 1.2rem 1.4rem; display: flex; flex-direction: column; gap: 1.4rem; }

/* Fetch status */
.fetch-info { font-size: 0.78rem; color: var(--text-sub); min-height: 1.1em; }
.fetch-info.ok    { color: var(--green); }
.fetch-info.error { color: var(--red); }

/* Model search + inline list */
.model-search-row { margin-bottom: 0.4rem; }

.model-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.model-list-empty {
  padding: 0.8rem; color: var(--text-sub); font-size: 0.85rem; text-align: center;
}

.model-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.model-item:last-child { border-bottom: none; }
.model-item:active { background: var(--surface2); }
.model-item.selected { background: rgba(124,106,247,0.12); }
.model-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-check { color: var(--accent-hi); font-weight: 700; flex-shrink: 0; margin-left: 0.5rem; }

/* Chip row */
.chip-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chip {
  padding: 0.45rem 0.9rem; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-dim); font-size: 0.9rem;
  cursor: pointer; transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Stepper */
.stepper { display: flex; align-items: center; gap: 0.8rem; }
.stepper-btn {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent; flex-shrink: 0;
}
.stepper-btn:active { background: var(--border); }
.stepper-val { font-size: 1.2rem; font-weight: 700; min-width: 2.5ch; text-align: center; }

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── LOADING SCREEN ───────────────────────────────────────────────────────── */

[data-screen="loading"] {
  align-items: center; justify-content: center;
}
.loading-center {
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem; text-align: center;
}
.spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label { font-size: 1.1rem; color: var(--text-dim); }

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── QUESTION SCREEN ──────────────────────────────────────────────────────── */

.q-top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.q-counter { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; }
.q-topic-badge {
  font-size: 0.75rem; color: var(--accent-hi);
  background: rgba(124,106,247,0.12);
  border-radius: 6px; padding: 0.2rem 0.5rem;
  font-weight: 600; letter-spacing: 0.03em;
}
.q-end-btn {
  font-size: 0.78rem; color: var(--text-dim);
  background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 0.3rem 0.6rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}

.q-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1.8rem; text-align: center; position: relative;
}

.q-text {
  font-size: clamp(1.7rem, 5.5vw, 2.5rem);
  font-weight: 700; line-height: 1.3; color: var(--text);
  transition: opacity 0.2s, transform 0.2s;
}
.q-text.slide-in-left  { animation: slideInLeft  0.2s ease forwards; }
.q-text.slide-in-right { animation: slideInRight 0.2s ease forwards; }
@keyframes slideInLeft  { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: none; } }

.q-transcript-preview {
  margin-top: 1rem; display: flex; flex-direction: column; gap: 0.3rem;
  max-height: 120px; overflow-y: auto; width: 100%;
}
.q-turn {
  background: var(--surface2); border-radius: 8px;
  padding: 0.4rem 0.7rem; font-size: 0.82rem; color: var(--text-dim); text-align: left;
}
.q-turn-speaker { font-weight: 700; margin-right: 0.35rem; }
.q-rec-hint { font-size: 0.78rem; color: var(--text-sub); margin-top: 0.5rem; }

.q-progress-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--border); }
.q-progress-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }

.q-nav-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.2rem 1rem; flex-shrink: 0; gap: 0.8rem;
}

.nav-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent; flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.nav-btn:active { background: var(--border); transform: scale(0.93); }
.nav-btn:disabled { opacity: 0.25; pointer-events: none; }

.mic-btn {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--surface2); border: 2px solid var(--border);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent; flex-shrink: 0;
  transition: all 0.15s;
}
.mic-btn svg { width: 28px; height: 28px; }
.mic-btn.recording {
  background: var(--red); border-color: var(--red); color: #fff;
  animation: mic-pulse 1s ease-in-out infinite;
}
.mic-btn.transcribing { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,85,85,0.5); }
  50%       { box-shadow: 0 0 0 14px rgba(224,85,85,0); }
}

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── END SCREEN ───────────────────────────────────────────────────────────── */

.end-header {
  padding: 1.4rem 1.4rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: center; flex-shrink: 0;
}
.end-header h1 { font-size: 1.4rem; }
.end-subtitle { font-size: 0.9rem; color: var(--text-dim); margin-top: 0.3rem; }
.end-body { padding: 1.2rem 1.4rem; }
.end-footer {
  padding: 1rem 1.4rem; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.6rem; flex-shrink: 0;
}
.save-status { font-size: 0.85rem; text-align: center; min-height: 1.2em; }
.save-status.success { color: var(--green); }
.save-status.error   { color: var(--red); }

.speaker-rename-item { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.6rem; }
.speaker-color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.speaker-color-0 { background: #7c6af7; }
.speaker-color-1 { background: #4caf7d; }
.speaker-color-2 { background: #e07755; }
.speaker-color-3 { background: #5ab4e0; }
.speaker-color-4 { background: #e0bb55; }

/* ── ═══════════════════════════════════════════════════════════════════════ */
/* ── HISTORY / SESSION-VIEW ───────────────────────────────────────────────── */

.history-list { padding: 0.8rem 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.history-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.9rem 1rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 0.15s;
}
.history-card:active { background: var(--surface2); }
.history-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.2rem; }
.history-card-meta  { font-size: 0.8rem; color: var(--text-dim); }
.history-empty { padding: 3rem 1.4rem; text-align: center; color: var(--text-dim); }

.session-view-body { padding: 1rem 1.4rem; display: flex; flex-direction: column; gap: 1.2rem; }
.sv-meta {
  font-size: 0.82rem; color: var(--text-dim);
  background: var(--surface); border-radius: 10px;
  padding: 0.7rem 0.9rem; border: 1px solid var(--border); line-height: 1.6;
}
.sv-question-block { border-left: 3px solid var(--border); padding-left: 0.9rem; }
.sv-question-block.has-answers { border-left-color: var(--accent); }
.sv-q-text { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.4rem; }
.sv-turn { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.2rem; }
.sv-turn-speaker { font-weight: 700; margin-right: 0.35rem; }
.sv-skipped { font-size: 0.82rem; color: var(--text-sub); font-style: italic; }

/* ── Shared ───────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); }

.speaker-text-0 { color: #9e8fff; }
.speaker-text-1 { color: #6fd4a0; }
.speaker-text-2 { color: #e09975; }
.speaker-text-3 { color: #7acae0; }
.speaker-text-4 { color: #e0cc75; }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: calc(1.5rem + var(--safe-b));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 0.5rem;
  align-items: center; z-index: 9999; pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 24px;
  padding: 0.6rem 1.2rem; font-size: 0.9rem;
  animation: toast-in 0.25s ease;
  white-space: nowrap;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
