:root {
  /* Gradebook-inspired palette (fallback; overridden by Telegram theme where sensible) */
  --cover-green: #2f4538;
  --cover-green-dark: #223529;
  --paper: #faf7ef;
  --paper-line: #dde3d6;
  --ink: #232420;
  --ink-soft: #5b5d55;
  --red-pen: #a8402f;
  --red-pen-soft: #c96b5b;
  --gold: #b08d3f;

  --bg: var(--paper);
  --surface: #ffffff;
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --accent: var(--red-pen);
  --line: var(--paper-line);

  --radius: 10px;
  --tab-bar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }

.ledger {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.ledger-head {
  background: var(--cover-green);
  color: #f2efe4;
  padding: 18px 20px 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  border-bottom: 3px double #9fae95;
}

.ledger-head-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stamp-mark {
  width: 38px;
  height: 38px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  color: var(--gold);
  flex-shrink: 0;
}

.ledger-head-title h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  letter-spacing: 0.03em;
}

.ledger-head-title p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #cdd6c4;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.ledger-head-date {
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: #cdd6c4;
  text-align: right;
  white-space: nowrap;
}

/* ---------- Body / Pages ---------- */
.ledger-body {
  flex: 1;
  padding: 20px 16px calc(var(--tab-bar-h) + 28px);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.page.hidden { display: none; }

.section-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  padding-bottom: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.section-note {
  font-size: 13px;
  color: var(--text-soft);
  margin: -8px 0 14px;
}

/* ---------- Stat grid (dashboard) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.stat-card.skeleton {
  height: 76px;
  background: linear-gradient(90deg, var(--surface) 25%, #f0ede2 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.stat-card .stat-num {
  font-family: "Courier New", monospace;
  font-size: 30px;
  color: var(--accent);
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Ruled list (users / teachers / tests) ---------- */
.ruled-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.ruled-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.ruled-row:last-child { border-bottom: none; }

.row-main { min-width: 0; flex: 1; }

.row-name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta {
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 2px;
}

.role-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 6px;
  border: 1px solid currentColor;
}

.role-badge.teacher { color: var(--cover-green); }
.role-badge.student { color: var(--gold); }

.empty-note {
  padding: 20px 14px;
  color: var(--text-soft);
  font-size: 14px;
  text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-approve {
  background: var(--cover-green);
  color: #f2efe4;
}

.btn-revoke {
  background: transparent;
  color: var(--red-pen);
  border: 1px solid var(--red-pen-soft);
}

.btn-delete {
  background: transparent;
  color: var(--red-pen);
  border: 1px solid var(--red-pen-soft);
}

.stamp-approved {
  font-family: Georgia, serif;
  font-size: 11px;
  color: var(--cover-green);
  border: 1.5px solid var(--cover-green);
  border-radius: 5px;
  padding: 3px 8px;
  transform: rotate(-4deg);
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Tab bar ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-soft);
  cursor: pointer;
}

.tab-btn .tab-icon { font-size: 18px; }

.tab-btn.active {
  color: var(--accent);
}

/* ---------- Test detail overlay ---------- */
.test-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  overflow-y: auto;
}

.test-detail.hidden { display: none; }

.test-detail-panel {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 14px;
  border: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-soft);
}

#test-detail-title {
  font-family: Georgia, serif;
  font-size: 20px;
  padding-right: 40px;
  margin-bottom: 18px;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.question-card .q-num {
  font-family: "Courier New", monospace;
  color: var(--accent);
  font-size: 12px;
  margin-bottom: 4px;
}

.question-card .q-text { font-size: 14px; margin-bottom: 6px; }

.question-card .q-opt {
  font-size: 13px;
  color: var(--text-soft);
  padding: 2px 0;
}

.question-card .q-opt.correct {
  color: var(--cover-green);
  font-weight: 600;
}

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.leaderboard-row:last-child { border-bottom: none; }

.leaderboard-row .lb-rank {
  font-family: "Courier New", monospace;
  color: var(--text-soft);
  width: 24px;
}

.leaderboard-row .lb-score {
  font-family: "Courier New", monospace;
  color: var(--accent);
  font-weight: 700;
}

/* ---------- Dark theme (Telegram dark mode) ---------- */
body.tg-dark {
  --bg: #171a15;
  --surface: #20241d;
  --text: #ece9df;
  --text-soft: #9aa093;
  --line: #333829;
  --paper: #171a15;
}

body.tg-dark .ledger-head {
  border-bottom-color: #3d4a37;
}
