:root {
  --bg: #0f141f;
  --bg-soft: rgba(30, 37, 53, 0.84);
  --panel: rgba(27, 34, 50, 0.9);
  --panel-2: rgba(35, 44, 63, 0.94);
  --text: #f7f7fb;
  --muted: #aeb8cc;
  --line: rgba(255,255,255,0.10);
  --accent: #c9a66b;
  --accent-2: #7cc1c7;
  --danger: #ef4444;
  --blue: #3b82f6;
  --shadow: 0 20px 60px rgba(0,0,0,0.28);
  --radius: 24px;
}

html[data-theme='light'] {
  --bg: #f4f2ee;
  --bg-soft: rgba(255,255,255,0.84);
  --panel: rgba(255,255,255,0.92);
  --panel-2: rgba(247,250,255,0.98);
  --text: #1c2333;
  --muted: #627089;
  --line: rgba(16, 32, 58, 0.1);
  --shadow: 0 18px 60px rgba(17, 33, 61, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top, rgba(201, 166, 107, 0.14), transparent 34%), var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 28px);
  backdrop-filter: blur(18px);
  background: rgba(15, 20, 31, 0.72);
  border-bottom: 1px solid var(--line);
}
html[data-theme='light'] .topbar { background: rgba(238, 244, 251, 0.82); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo-wrap {
  width: 44px; height: 44px; border-radius: 14px; overflow: hidden;
  display: grid; place-items: center; background: linear-gradient(135deg, rgba(201,166,107,.28), rgba(124,193,199,.2));
  border: 1px solid var(--line);
}
.brand-logo { width: 26px; height: 26px; object-fit: contain; }
.brand-title { font-weight: 800; }
.brand-subtitle { font-size: 13px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.page-shell { padding: 20px clamp(16px, 3vw, 28px) 120px; }
.app-root { display: grid; gap: 18px; }
.panel, .panel-sub, .hero-card, .auth-panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.panel, .hero-card { padding: 20px; }
.panel-sub { padding: 16px; }
.hero-card {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; flex-wrap: wrap;
}
.compact-hero { padding-block: 18px; }
.eyebrow { color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, h3 { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: clamp(20px, 2.6vw, 28px); }
h3 { font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt16 { margin-top: 16px; }
.stretch { flex: 1 1 auto; }
.break-all { word-break: break-all; }

.hero-badges, .toolbar-inline, .row-wrap, .lesson-row-actions, .review-card-body {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.badge, .mini-chip, .rank-pill, .average-badge {
  padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); font-size: 13px;
}
.average-badge { background: rgba(124, 193, 199, 0.16); }
.rank-pill { background: rgba(201, 166, 107, 0.2); }

.icon-btn, .primary-btn, .ghost-btn, .ghost-link, .tool-btn, .attendance-btn {
  border: 1px solid var(--line); color: var(--text); border-radius: 14px; transition: .18s ease; cursor: pointer;
}
.icon-btn, .ghost-link, .ghost-btn, .tool-btn, .attendance-btn { background: rgba(255,255,255,.05); }
.primary-btn {
  background: linear-gradient(135deg, rgba(201,166,107,0.95), rgba(124,193,199,0.88));
  color: #03111d; font-weight: 700;
}
.icon-btn { width: 42px; height: 42px; }
.primary-btn, .ghost-btn, .tool-btn, .attendance-btn, .ghost-link { padding: 11px 14px; }
.ghost-link { display: inline-flex; align-items: center; }
.primary-btn:hover, .ghost-btn:hover, .tool-btn:hover, .attendance-btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.attendance-btn.yes.active { background: rgba(52, 211, 153, .18); }
.attendance-btn.no.active { background: rgba(239, 68, 68, .20); }
.tool-btn.active { background: rgba(201, 166, 107, .2); }

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100% - 20px));
  z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; padding: 10px; border-radius: 24px; background: rgba(15,20,31,.86); border: 1px solid var(--line); backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
html[data-theme='light'] .bottom-tabs { background: rgba(255,255,255,.8); }
.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 10px; border-radius: 14px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600;
}
.tab-btn.active { background: rgba(255,255,255,.09); color: var(--text); border-color: var(--line); }
.tab-btn span { font-size: 15px; }
.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 18px; }

.stats-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat-card {
  padding: 18px; border-radius: 22px; background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 10px; font-size: 28px; font-weight: 800; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.student-grid, .lesson-list { display: grid; gap: 12px; }
.student-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.student-card, .lesson-row, .review-card {
  width: 100%; padding: 16px; border-radius: 20px; border: 1px solid var(--line);
  background: rgba(255,255,255,.05); color: var(--text); text-align: left;
}
.student-card { cursor: pointer; }
.student-card-top, .review-card-top, .detail-hero, .key-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.student-card-meta, .lesson-row-meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.lesson-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lesson-row-main { min-width: 180px; }

.table-head, .table-row {
  padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line);
}
.table-head { background: rgba(255,255,255,.06); color: var(--muted); font-size: 13px; }
.table-row { background: rgba(255,255,255,.03); }
.table-grid { display: grid; gap: 12px; align-items: center; }
.ranking-grid { grid-template-columns: 56px minmax(120px, 1.4fr) repeat(5, minmax(70px, .8fr)); }
.session-grid { grid-template-columns: 56px 1fr 1fr 1fr 120px 110px; }

.auth-shell { max-width: 440px; margin: 7vh auto 0; }
.auth-form { display: grid; gap: 12px; margin-top: 18px; }
.text-input, .select-input, .number-input {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); color: var(--text);
}
.number-input { max-width: 104px; }
.error-text { color: #fca5a5; margin-top: 14px; }

.detail-hero { padding: 14px 0; }
.surah-grid {
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  max-height: 420px; overflow: auto; padding-right: 4px;
}
.surah-pill {
  display: grid; gap: 6px; align-content: start; padding: 10px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255,255,255,.04);
}
button.surah-pill { cursor: pointer; text-align: left; color: var(--text); }
.surah-pill.idle { opacity: .72; }
.surah-pill.learning { background: rgba(59,130,246,.14); }
.surah-pill.ok { background: rgba(52,211,153,.14); }
.surah-pill.repeat { background: rgba(245,158,11,.14); }
.surah-pill-number { font-weight: 800; }
.surah-pill-name { font-size: 12px; color: var(--muted); line-height: 1.35; }

.mushaf-layout { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
.mushaf-stage {
  position: relative; overflow: hidden; border-radius: 24px; border: 1px solid var(--line); background: rgba(255,255,255,.04);
}
.mushaf-image { display: block; width: 100%; height: auto; }
.mushaf-canvas {
  position: absolute; inset: 0; z-index: 2;
}
.mushaf-canvas.readonly { pointer-events: none; }
.mushaf-canvas.editable { cursor: crosshair; }
.mushaf-side { display: grid; gap: 10px; position: sticky; top: 148px; }
.toolbar-vertical { display: grid; gap: 10px; }
.side-stat {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line);
}
.annotation {
  position: absolute; border-radius: 8px; border: 2px solid rgba(239,68,68,.95); background: rgba(239,68,68,.18);
}
.annotation.blue { border-color: rgba(59,130,246,.95); background: rgba(59,130,246,.18); }
.annotation.preview { pointer-events: none; }
.annotation.interactive { cursor: pointer; }
.annotation-badge {
  position: absolute; right: -6px; bottom: -10px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(7,17,31,.88); color: white; border: 1px solid rgba(255,255,255,.18);
}
.review-grid { display: grid; gap: 10px; grid-template-columns: minmax(180px, 1fr) 110px; }
.key-box { display: grid; gap: 12px; }
.empty-state {
  padding: 18px;
  border-radius: 16px;
  border: 1px dashed var(--line);
  color: var(--muted);
  background: rgba(255,255,255,0.03);
}

.muted-banner {
  padding: 14px 16px;
  font-size: 14px;
}
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(120%);
  padding: 12px 16px; border-radius: 999px; background: rgba(7,17,31,.94); color: #fff; border: 1px solid rgba(255,255,255,.14); transition: .22s ease;
  z-index: 100;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  .mushaf-layout { grid-template-columns: 1fr; }
  .mushaf-side { position: static; }
  .ranking-grid { grid-template-columns: 40px minmax(100px, 1fr) repeat(5, minmax(56px, .7fr)); font-size: 13px; }
  .session-grid { grid-template-columns: 46px 1fr 1fr 1fr 90px 90px; font-size: 13px; }
}

@media (max-width: 720px) {
  .topbar { padding-inline: 14px; }
  .page-shell { padding-inline: 14px; }
  .bottom-tabs { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .hero-card { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .student-grid { grid-template-columns: 1fr; }
  .review-grid { grid-template-columns: 1fr; }
  .ranking-grid { grid-template-columns: 36px minmax(100px, 1fr) repeat(5, minmax(52px, .65fr)); overflow-x: auto; }
  .session-grid { grid-template-columns: 40px 1fr 1fr 1fr 72px 84px; overflow-x: auto; }
  .table-head, .table-row { min-width: 760px; }
  #rankingTable, #sessionsTable { overflow-x: auto; }
  .toolbar-inline, .row-wrap { width: 100%; }
  .toolbar-inline > * { flex: 1 1 auto; }
  .number-input { max-width: none; }
}
