:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(79,70,229,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
header span { font-size: 0.75rem; opacity: 0.7; }

nav {
  display: flex;
  gap: 2px;
}
nav button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
}
nav button:hover { background: rgba(255,255,255,0.1); color: #fff; }
nav button.active { background: rgba(255,255,255,0.2); color: #fff; }

/* ── Layout ─────────────────────────────── */
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.section { display: none; }
.section.active { display: block; }

/* ── Page header ─────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.page-header h2 { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.page-header .subtitle { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* ── Cards ─────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }

/* ── Form row ─────────────────────────────── */
.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}
.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-group input,
.form-group select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

.form-group input[type="file"] { padding: 0.4rem 0.75rem; }

/* ── Buttons ─────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Tables ─────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead { background: #f8fafc; }
th { padding: 0.65rem 1rem; text-align: left; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ── Badges ─────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-yellow { background: var(--warning-light); color: var(--warning); }
.badge-gray { background: #f1f5f9; color: var(--muted); }

/* ── Score circle ─────────────────────────── */
.score-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.score-ring.big { width: 100px; height: 100px; }
.score-ring .score-num { font-size: 1.5rem; line-height: 1; }
.score-ring.big .score-num { font-size: 1.8rem; }
.score-ring .score-lbl { font-size: 0.6rem; font-weight: 500; text-transform: uppercase; opacity: 0.8; }

.score-high { background: var(--success-light); color: var(--success); border: 3px solid var(--success); }
.score-mid { background: var(--warning-light); color: var(--warning); border: 3px solid var(--warning); }
.score-low { background: var(--danger-light); color: var(--danger); border: 3px solid var(--danger); }

/* ── Analysis card ─────────────────────────── */
.analysis-header {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.analysis-header .meta { flex: 1; }
.analysis-header .meta h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.25rem; }
.analysis-header .meta p { color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 0.5rem; }
.tag {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}
.tag-red { background: var(--danger-light); color: var(--danger); }
.tag-yellow { background: var(--warning-light); color: var(--warning); }
.tag-blue { background: var(--primary-light); color: var(--primary); }
.tag-green { background: var(--success-light); color: var(--success); }

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.section-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}
.section-card h4 { font-size: 0.8rem; font-weight: 700; color: var(--text); margin-bottom: 0.4rem; }
.section-card .score-line { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.progress-bar { height: 6px; background: var(--border); border-radius: 999px; flex: 1; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; }

.recommendations-list { list-style: none; margin-top: 0.5rem; }
.recommendations-list li {
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  border-radius: 0 6px 6px 0;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
}

.priority-box {
  background: #fef9c3;
  border: 1px solid #fde047;
  border-radius: 8px;
  padding: 0.9rem;
  margin-top: 0.75rem;
}
.priority-box h4 { font-size: 0.75rem; font-weight: 700; color: #854d0e; text-transform: uppercase; margin-bottom: 0.3rem; }
.priority-box p { font-size: 0.875rem; color: #78350f; }

/* ── Answer input ─────────────────────────── */
.section-input-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.section-input-card .sec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.section-input-card .sec-name { font-weight: 600; font-size: 0.9rem; }
.section-input-card .sec-count { font-size: 0.75rem; color: var(--muted); }
.section-input-card input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: #fff;
  outline: none;
}
.section-input-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.section-input-card .input-hint { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

/* ── Toast ─────────────────────────────── */
#toast-container {
  position: fixed;
  top: 70px;
  right: 1rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.toast-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.toast-info { background: var(--primary-light); color: var(--primary); border: 1px solid #a5b4fc; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ── Loading ─────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--muted);
  gap: 0.75rem;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────── */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.empty .empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.empty h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 0.25rem; }
.empty p { font-size: 0.85rem; }

/* ── Steps ─────────────────────────────── */
.steps {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}
.step.active { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.step.done { background: var(--success-light); border-color: var(--success); color: var(--success); }
.step-num {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: currentColor;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
}

/* ── Overall analysis ─────────────────────── */
.study-plan-week {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
  margin-bottom: 0.5rem;
}
.study-plan-week .week-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}
.study-plan-week h4 { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.2rem; }
.study-plan-week p { font-size: 0.8rem; color: var(--muted); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

.attempt-row { cursor: pointer; }
.attempt-detail { display: none; padding: 1rem; background: var(--bg); border-top: 1px solid var(--border); }
.attempt-detail.open { display: block; }

.score-trend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.trend-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  color: var(--muted);
}
.trend-dot .dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}
