:root {
  --green: #2d6a4f;
  --green-dark: #1b4332;
  --green-light: #95d5b2;
  --gold: #c9a86b;
  --bg: #f4f7f3;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #16a34a;
  --error: #dc2626;
  --warn: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ============ HEADER ============ */
.topbar {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green) 100%);
  color: white;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { text-align: left; flex: 1; min-width: 0; }
.brand-tr { font-size: 1.1rem; font-weight: 700; line-height: 1.3; margin-bottom: 6px; }
.brand-ar {
  font-family: 'Amiri', 'Scheherazade New', serif;
  font-size: 1.5rem;
  direction: rtl;
  line-height: 1.4;
  margin-bottom: 2px;
}
.brand-sub { font-size: 0.78rem; opacity: 0.85; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.timer {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
}
.timer.warn { background: rgba(245, 158, 11, 0.3); border-color: var(--warn); }
.timer.danger { background: rgba(220, 38, 38, 0.4); border-color: var(--error); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

button.ghost {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
button.ghost:hover { background: rgba(255,255,255,0.12); }

/* ============ LAYOUT ============ */
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card + .card { margin-top: 20px; }
.card-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 6px;
}
.muted { color: var(--muted); font-size: 0.92rem; }
.section-h {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-dark);
  margin: 24px 0 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.hidden { display: none !important; }

/* ============ LOGIN ============ */
.login-card { max-width: 520px; margin: 24px auto 0; }
.role-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 22px;
}
.role-tabs.two-cols { grid-template-columns: repeat(2, 1fr); }
.role-tab {
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  color: var(--muted);
  font-size: 0.9rem;
  transition: all 0.15s;
}
.role-tab:hover { border-color: var(--green-light); }
.role-tab.active {
  background: white;
  border-color: var(--green);
  color: var(--green-dark);
}
.role-icon { display: block; font-size: 1.6rem; margin-bottom: 4px; }

.form-row { margin-bottom: 16px; }
.form-row label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.12);
}
textarea { resize: vertical; min-height: 80px; }
button.primary {
  background: var(--green);
  color: white;
  border: none;
  padding: 13px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  width: 100%;
}
button.primary:hover { background: var(--green-dark); }
button.primary:disabled { background: var(--muted); cursor: not-allowed; opacity: 0.6; }
button.primary.big { padding: 16px 24px; font-size: 1.05rem; margin-top: 20px; }

.alert { padding: 12px 14px; border-radius: 8px; margin: 12px 0; font-size: 0.875rem; }
.alert-error { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.hint-box {
  margin-top: 20px;
  background: var(--bg);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 0.88rem;
  border: 1px solid var(--border);
}
.hint-box summary { cursor: pointer; font-weight: 600; color: var(--green-dark); }
.hint-box ul { margin: 12px 0 0 18px; color: var(--muted); }
.hint-box li { margin-bottom: 4px; }

/* ============ STUDENT HOME ============ */
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0 8px;
}
.info-card {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  border: 1px solid var(--border);
}
.info-num { font-size: 1.8rem; font-weight: 700; color: var(--green-dark); line-height: 1; }
.info-num .info-unit { font-size: 0.9rem; color: var(--muted); margin-left: 2px; }
.info-label { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

/* ============ EXAM (tek soru tek sayfa) ============ */
.exam-toolbar {
  position: sticky;
  top: 100px;
  background: var(--bg);
  padding: 12px 0;
  z-index: 40;
  margin-bottom: 20px;
}
.exam-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
}
.meta-section {
  background: var(--green-light);
  color: var(--green-dark);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
}
.meta-counter {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.meta-counter b { color: var(--green-dark); font-size: 1rem; }
.progress-line { display: flex; align-items: center; gap: 12px; }
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green-light), var(--green));
  transition: width 0.3s;
  width: 0%;
}
.progress-text { font-size: 0.8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Tek soru stage */
#questionStage .question-card {
  padding: 32px;
  min-height: 400px;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
#questionStage .q-prompt { font-size: 1.1rem; line-height: 1.7; }
#questionStage .q-arabic { font-size: 1.85rem; padding: 18px 22px; }
#questionStage .choice { padding: 14px 18px; font-size: 1rem; }
#questionStage .choice .ar { font-size: 1.4em; }

/* Navigasyon barı */
.nav-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  margin-top: 20px;
  padding: 16px 0;
  position: sticky;
  bottom: 0;
  background: var(--bg);
}
.nav-bar button { width: 100%; }
.nav-bar .nav-next { background: var(--green); }
.nav-bar .nav-next.finish { background: var(--gold); }
.nav-bar .nav-next.finish:hover { background: #b8945e; }
.nav-bar button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Soru ızgarası (modal) */
.question-grid {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.question-grid.hidden { display: none; }
.question-grid-inner {
  background: white;
  border-radius: 16px;
  padding: 24px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.question-grid h3 { margin-bottom: 14px; color: var(--green-dark); }
.grid-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 8px;
}
.grid-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  background: white;
  color: var(--muted);
  font-family: inherit;
}
.grid-item:hover { border-color: var(--green); }
.grid-item.answered { background: var(--green-light); border-color: var(--green); color: var(--green-dark); }
.grid-item.current { background: var(--green); color: white; border-color: var(--green-dark); }
.grid-item.flagged { background: #fef3c7; border-color: var(--warn); }
.grid-close {
  margin-top: 16px;
  background: var(--green);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  width: 100%;
}

.question-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  scroll-margin-top: 180px;
}
.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.82rem;
}
.q-num {
  background: var(--green-light);
  color: var(--green-dark);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
}
.q-section { color: var(--muted); font-weight: 600; }
.q-points {
  background: var(--bg);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.75rem;
}
.q-prompt {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 14px;
  color: var(--text);
}
.ar, .arabic {
  font-family: 'Amiri', 'Scheherazade New', serif;
  direction: rtl;
  unicode-bidi: embed;
}
.q-prompt .ar { font-size: 1.45em; display: inline; }
.q-arabic {
  font-family: 'Amiri', serif;
  direction: rtl;
  font-size: 1.6rem;
  line-height: 1.9;
  padding: 14px 18px;
  background: #fafdfb;
  border-right: 4px solid var(--green-light);
  border-radius: 6px;
  margin-bottom: 14px;
}
.q-sub-prompt {
  font-family: 'Amiri', serif;
  direction: rtl;
  font-size: 1.3rem;
  font-weight: 700;
  margin: 10px 0;
  color: var(--green-dark);
}

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.choice:hover { border-color: var(--green-light); background: #fafffe; }
.choice input { margin: 0; cursor: pointer; }
.choice input:checked + span { color: var(--green-dark); font-weight: 600; }
.choice:has(input:checked) { border-color: var(--green); background: #f0fdf4; }
.choice .ar { font-size: 1.3em; flex: 1; }
.choice-text { flex: 1; }

input.ar, textarea.ar {
  font-size: 1.3rem;
  font-family: 'Amiri', serif;
  text-align: right;
  padding: 14px 16px;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 8px;
  font-style: italic;
}

.submit-bar {
  position: sticky;
  bottom: 0;
  background: white;
  border-top: 2px solid var(--green-light);
  padding: 16px 20px;
  margin: 24px -20px -80px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.submit-bar button { width: auto; min-width: 180px; }

/* ============ RESULT ============ */
.result-head { text-align: center; margin-bottom: 24px; }
.score-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  align-items: center;
  margin-bottom: 24px;
}
.score-circle {
  --pct: 0%;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0% var(--pct), var(--border) var(--pct) 100%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.score-circle::before {
  content: '';
  position: absolute;
  inset: 12px;
  background: white;
  border-radius: 50%;
}
.score-circle > * { position: relative; z-index: 1; }
.score-text { font-size: 2.2rem; font-weight: 700; color: var(--green-dark); line-height: 1; }
.score-sub { font-size: 1rem; color: var(--muted); margin-top: 2px; }
.score-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--bg);
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.stat-label { font-size: 0.75rem; color: var(--muted); }
.stat-val { font-size: 1.15rem; font-weight: 700; color: var(--green-dark); margin-top: 2px; }
.result-message {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
  font-size: 0.95rem;
  text-align: center;
  font-weight: 500;
}

.review-item {
  padding: 14px 16px;
  border-radius: 8px;
  border-left: 4px solid;
  margin-bottom: 10px;
  background: white;
  border: 1px solid var(--border);
}
.review-item.correct { border-left-color: var(--success); background: #f8fef9; }
.review-item.wrong { border-left-color: var(--error); background: #fef8f8; }
.review-item.review { border-left-color: var(--warn); background: #fffbf5; }
.review-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 8px;
  gap: 8px;
}
.review-head strong { font-size: 0.88rem; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: #dcfce7; color: var(--success); }
.badge-error { background: #fee2e2; color: var(--error); }
.badge-warn { background: #fef3c7; color: #92400e; }
.review-prompt { font-size: 0.9rem; margin-bottom: 6px; color: var(--text); }
.review-prompt .ar { font-size: 1.3em; }
.review-row { font-size: 0.82rem; margin-top: 4px; color: var(--muted); }
.review-row b { color: var(--text); font-weight: 600; }
.review-row .ar { font-size: 1.3em; color: var(--text); }

.action-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  justify-content: center;
}
.action-row button { width: auto; min-width: 160px; }
button.ghost.dark {
  color: var(--green-dark);
  border-color: var(--green);
}
button.ghost.dark:hover { background: var(--bg); }

/* ============ DASHBOARD ============ */
.dash-head { margin-bottom: 20px; }
.dash-actions { margin-bottom: 16px; }
.dash-actions button { width: auto; }
.result-row-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.result-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.result-row-title { font-weight: 700; color: var(--green-dark); font-size: 1.05rem; }
.result-row-meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.score-badge {
  background: var(--green);
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}
.score-badge.low { background: var(--error); }
.score-badge.mid { background: var(--warn); }

.expand-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--green-dark);
  margin-right: 8px;
}
.expand-btn:hover { background: var(--green-light); }
.delete-btn {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
}
.delete-btn:hover { background: #fef2f2; }

.teacher-review-box {
  margin-top: 14px;
  padding: 14px;
  background: #fffbf5;
  border: 1px solid #fbd38d;
  border-radius: 8px;
}
.teacher-review-box label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.teacher-review-box input[type="number"] { width: 100px; margin-right: 12px; }
.teacher-review-box .save-btn {
  background: var(--warn);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}

/* ============ FOOTER ============ */
.footer {
  text-align: center;
  padding: 24px 20px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 700px) {
  .brand-tr { font-size: 1rem; }
  .brand-ar { font-size: 1.3rem; }
  .topbar-inner { padding: 12px 16px; gap: 8px; }
  .card { padding: 20px; }
  .card-title { font-size: 1.2rem; }
  .page { padding: 16px 14px 80px; }
  .score-row { grid-template-columns: 1fr; text-align: center; }
  .score-circle { margin: 0 auto; }
  .score-stats { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr 1fr; }
  .info-num { font-size: 1.4rem; }
  .submit-bar { flex-direction: column; align-items: stretch; }
  .submit-bar button { width: 100%; }
  .exam-toolbar { top: 78px; }
  .question-card { scroll-margin-top: 200px; }
}
