/* ── Auth Gate ── */
.auth-card {
  margin: auto;
  text-align: center;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.auth-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.auth-question {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}
.auth-input-row {
  display: flex;
  gap: 10px;
  width: 100%;
}
.auth-input {
  flex: 1;
  text-align: center;
  font-size: 1.05rem;
}
.auth-error {
  font-size: 0.9rem;
  color: var(--danger);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}
.shake { animation: shake 0.4s ease; }

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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242736;
  --border: #2e3148;
  --text: #e8eaf0;
  --text-muted: #7b82a0;
  --primary: #5c6ef8;
  --primary-hover: #4a5ce6;
  --warning: #f5a623;
  --warning-hover: #e09418;
  --danger: #e05252;
  --success: #4caf7d;
  --timer-green: #4caf7d;
  --timer-yellow: #f5a623;
  --timer-red: #e05252;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

/* ── Panels ── */
.panel {
  display: none;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  padding: 24px;
}
.panel.active { display: flex; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}
.panel-header h2 {
  flex: 1;
  font-size: 1.4rem;
  font-weight: 600;
}

/* ── Home ── */
.home-card {
  margin: auto;
  text-align: center;
  max-width: 480px;
  width: 100%;
}
.home-card h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.subtitle {
  color: var(--text-muted);
  margin-bottom: 40px;
  font-size: 1.1rem;
}
.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-large {
  padding: 20px 32px;
  font-size: 1.2rem;
  font-weight: 600;
}
.btn-large small {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.75;
}
.btn-large .btn-icon {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

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

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

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

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #3d9e6a; }

/* ── Progress badge ── */
.progress-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Center content ── */
.center-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}
.lead {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 440px;
}

/* ── Timer ── */
.timer-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
}
.timer-ring { width: 120px; height: 120px; transform: rotate(-90deg); }

.timer-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 8;
}
.timer-progress {
  fill: none;
  stroke: var(--timer-green);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 327;   /* 2π × 52 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.5s ease;
}
.timer-progress.yellow { stroke: var(--timer-yellow); }
.timer-progress.red    { stroke: var(--timer-red); }

.timer-count {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 700;
  transition: color 0.5s ease;
}
.timer-count.yellow { color: var(--timer-yellow); }
.timer-count.red    { color: var(--timer-red); }

/* ── Question screen ── */
.question-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  box-shadow: var(--shadow);
}
.question-text {
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.5;
}

/* ── Hint box ── */
.hint-box {
  margin-top: 24px;
  padding: 16px;
  background: rgba(245, 166, 35, 0.08);
  border: 1px solid rgba(245, 166, 35, 0.3);
  border-radius: 8px;
  animation: fadeIn 0.3s ease;
}
.hint-label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warning);
  margin-bottom: 8px;
}
.hint-box p { color: var(--text-muted); font-size: 1rem; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Action row ── */
.action-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Topic badge ── */
.topic-badge {
  display: inline-block;
  background: rgba(92, 110, 248, 0.15);
  border: 1px solid rgba(92, 110, 248, 0.35);
  color: #9ba8fb;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

/* ── Question type badge ── */
.type-badge {
  display: inline-block;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}
.type-fill_in_blank {
  background: rgba(92, 110, 248, 0.12);
  border: 1px solid rgba(92, 110, 248, 0.35);
  color: #9ba8fb;
}
.type-describe {
  background: rgba(245, 166, 35, 0.1);
  border: 1px solid rgba(245, 166, 35, 0.35);
  color: var(--warning);
}
.type-match {
  background: rgba(76, 175, 125, 0.1);
  border: 1px solid rgba(76, 175, 125, 0.35);
  color: var(--success);
}

/* ── Match terms (shown during question, before reveal) ── */
.match-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.match-term {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ── Match pairs (shown in answer box after reveal) ── */
.match-pair {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(76, 175, 125, 0.15);
  font-size: 0.95rem;
}
.match-pair:last-child { border-bottom: none; }
.match-pair-term  { color: var(--success); font-weight: 600; min-width: 140px; }
.match-pair-arrow { color: var(--text-muted); flex-shrink: 0; }
.match-pair-match { color: var(--text); }

/* ── Form ── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.form-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.text-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.text-input:focus { border-color: var(--primary); }

/* ── Spinner ── */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / meta ── */
.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
  padding: 8px;
  background: rgba(224, 82, 82, 0.08);
  border-radius: 6px;
  border: 1px solid rgba(224, 82, 82, 0.25);
}
.meta-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Accordion screen ── */
.accordion-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  gap: 8px;
}

.accordion {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.accordion-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.accordion-item.open {
  border-color: var(--primary);
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
}
.accordion-header:hover { background: var(--surface-2); }

.accordion-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}
.accordion-item.open .accordion-num {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.accordion-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
}

.accordion-topic {
  flex-shrink: 0;
  background: rgba(92, 110, 248, 0.12);
  border: 1px solid rgba(92, 110, 248, 0.3);
  color: #9ba8fb;
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.accordion-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  font-size: 0.85rem;
}
.accordion-item.open .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}
.accordion-item.open .accordion-body {
  display: block;
  animation: fadeIn 0.2s ease;
}

.accordion-question {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.55;
  padding-top: 16px;
  margin-bottom: 16px;
}

/* ── Answer box ── */
.answer-box {
  margin-top: 16px;
  padding: 16px;
  background: rgba(76, 175, 125, 0.08);
  border: 1px solid rgba(76, 175, 125, 0.35);
  border-radius: 8px;
  animation: fadeIn 0.3s ease;
}
.answer-label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--success);
  margin-bottom: 8px;
}
.answer-box p { color: var(--text); font-size: 1rem; }

/* ── Batch Q&A ── */
.bqa-textarea {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}
.bqa-hint-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -4px;
}
.bqa-global-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: sticky;
  top: 0;
  z-index: 10;
}
.bqa-posts-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  gap: 16px;
}
.bqa-student-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bqa-student-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.bqa-student-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.bqa-student-status {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.bqa-status-done {
  color: var(--success);
  font-weight: 600;
}
.bqa-student-error {
  font-size: 0.82rem;
  color: var(--danger);
}
.bqa-posts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bqa-questions {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.bqa-accordion {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.btn-sm {
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* ── Posts selection screen ── */
.posts-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  gap: 12px;
}

.posts-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.post-item:hover { border-color: var(--primary); }
.post-item:has(.post-checkbox:checked) {
  border-color: var(--primary);
  background: rgba(92, 110, 248, 0.05);
}

.post-checkbox {
  margin-top: 3px;
  flex-shrink: 0;
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

.post-item-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.post-item-subject {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.post-item-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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