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

:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --gold: #fbbf24;
  --silver: #9ca3af;
  --bronze: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout helpers ── */
.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; }
.topbar .back-btn {
  background: none; border: none; cursor: pointer;
  font-size: 22px; padding: 4px 8px; border-radius: 8px;
  min-width: 44px; min-height: 44px; display: flex; align-items: center;
}
.topbar .back-btn:hover { background: var(--bg); }

/* ── Buttons ── */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  border-radius: 10px;
  border: none;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 18px;
  transition: background .15s, transform .1s;
}
button:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }

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

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fecaca; }

.btn-icon {
  background: none;
  padding: 8px;
  font-size: 20px;
  border-radius: 10px;
}
.btn-icon:hover { background: var(--bg); }

/* ── Login screen ── */
#screen-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  gap: 16px;
}
#screen-login h1 { font-size: 28px; font-weight: 800; }
#screen-login p.subtitle { color: var(--muted); font-size: 16px; }
#screen-login input[type="email"] {
  width: 100%;
  max-width: 360px;
  padding: 14px 16px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
#screen-login input[type="email"]:focus { border-color: var(--accent); }
#screen-login .btn-primary { width: 100%; max-width: 360px; font-size: 16px; }
#login-confirm { color: var(--accent); font-weight: 600; text-align: center; }
#login-error { color: var(--danger); text-align: center; font-size: 14px; }

/* ── Classes screen ── */
#screen-classes { padding: 20px; }
.classes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.class-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  box-shadow: var(--shadow);
}
.class-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.class-tile:active { transform: scale(.98); }
.class-tile h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.class-tile .meta { color: var(--muted); font-size: 14px; }
.class-tile .co-tag {
  display: inline-block;
  background: #eff6ff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
}

/* ── Class view ── */
#screen-class {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.class-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.pupil-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.leaderboard-strip {
  width: 200px;
  border-left: 1px solid var(--border);
  background: var(--card);
  padding: 16px 12px;
  overflow-y: auto;
  flex-shrink: 0;
}
.leaderboard-strip h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 10px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { font-size: 18px; width: 24px; text-align: center; }
.lb-name { flex: 1; font-weight: 500; }
.lb-pts { font-weight: 700; color: var(--accent); }

@media (max-width: 600px) {
  .leaderboard-strip { display: none; }
}

/* ── Pupil grid ── */
.pupil-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (min-width: 900px) {
  .pupil-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 500px) {
  .pupil-grid { grid-template-columns: repeat(2, 1fr); }
}

.pupil-tile {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  user-select: none;
}
.pupil-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 3px #dbeafe; }
.pupil-tile:active { transform: scale(.95); }
.pupil-tile.selected {
  border-color: var(--accent);
  background: #eff6ff;
}
.pupil-tile .pupil-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.pupil-tile .pupil-pts { font-size: 20px; font-weight: 800; color: var(--accent); }
.pupil-tile .check { font-size: 22px; }

/* ── Nav bar actions ── */
.nav-actions { display: flex; gap: 8px; }
.btn-group {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
  font-weight: 700;
  padding: 8px 14px;
}
.btn-group.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Award sheet ── */
#award-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.15);
  z-index: 100;
  transform: translateY(100%);
  transition: transform .2s ease;
  max-height: 70vh;
  overflow-y: auto;
}
#award-sheet.open { transform: translateY(0); }
#award-sheet h3 { font-size: 17px; font-weight: 700; margin-bottom: 16px; color: var(--muted); }
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.cat-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.cat-chip:hover { background: #eff6ff; border-color: var(--accent); }
.cat-chip:active { transform: scale(.95); }
.cat-chip .cat-icon { font-size: 28px; display: block; margin-bottom: 4px; }
.cat-chip .cat-label { font-size: 13px; font-weight: 600; }
.cat-chip .cat-pts { font-size: 12px; color: var(--muted); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  white-space: nowrap;
  max-width: 90vw;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#toast button {
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: 4px 10px;
  min-height: unset;
  font-size: 13px;
  border-radius: 6px;
}

/* ── Settings panel ── */
#settings-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .2s ease;
}
#settings-panel.open { transform: translateX(0); }
.settings-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.settings-section h3 {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 14px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item-name { flex: 1; font-weight: 500; }
.list-item-actions { display: flex; gap: 6px; }
.list-item-actions button {
  font-size: 13px;
  padding: 6px 12px;
  min-height: unset;
}
.invite-url-box {
  background: var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
  margin-bottom: 10px;
}
.danger-zone {
  border-top: 2px dashed #fecaca;
  background: #fff5f5;
}
.danger-zone h3 { color: var(--danger); }
.danger-zone .danger-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal input[type="text"], .modal input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  font-family: inherit;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.modal label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════
   BOARD VIEW  (board.html)
═══════════════════════════════════ */
body.board-view {
  background: #0f172a;
  color: #f1f5f9;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.board-header {
  text-align: center;
  padding: 24px 20px 12px;
}
.board-header h1 {
  font-size: clamp(22px, 4vw, 40px);
  font-weight: 800;
  letter-spacing: -.02em;
  text-transform: uppercase;
}
.board-header .sub {
  font-size: 14px;
  color: #94a3b8;
  margin-top: 4px;
}
.board-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.board-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-radius: 14px;
  background: #1e293b;
  transition: background .3s;
}
.board-row.rank-1 { background: #422006; border: 1px solid #92400e; }
.board-row.rank-2 { background: #1c1917; border: 1px solid #57534e; }
.board-row.rank-3 { background: #1c1917; border: 1px solid #78350f; }
.board-row.pulse {
  animation: pulse-row .5s ease;
}
@keyframes pulse-row {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.02); background: #1d4ed8; }
  100% { transform: scale(1); }
}
.board-medal { font-size: clamp(24px, 3vw, 36px); width: 48px; text-align: center; }
.board-rank-num { font-size: clamp(18px, 2.5vw, 28px); font-weight: 700; color: #64748b; width: 40px; text-align: center; }
.board-name { flex: 1; font-size: clamp(18px, 2.8vw, 32px); font-weight: 700; }
.board-pts { font-size: clamp(22px, 3.5vw, 44px); font-weight: 900; color: #60a5fa; min-width: 80px; text-align: right; }
.board-pts-unit { font-size: .5em; font-weight: 500; color: #94a3b8; }
