:root {
  --bg: #070b14;
  --bg2: #0e1524;
  --bg3: #151f35;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.09);

  --blue: #4f8ef7;
  --purple: #a855f7;
  --cyan: #22d3ee;
  --green: #34d399;
  --yellow: #fcd34d;
  --red: #f87171;
  --pink: #f472b6;

  --txt: #e8edf5;
  --txt2: #8896b0;
  --txt3: #4a5568;

  --radius: 14px;
  --rad-sm: 8px;

  /* Dark / Light mode swap */
  --mode-bg: var(--bg);
  --mode-bg2: var(--bg2);
  --mode-bg3: var(--bg3);
  --mode-txt: var(--txt);
  --mode-txt2: var(--txt2);
  --mode-border: var(--border);
  --mode-surface: var(--surface);
}

/* Light mode overrides */
body.light {
  --mode-bg: #f0f4f8;
  --mode-bg2: #ffffff;
  --mode-bg3: #e2e8f0;
  --mode-txt: #1a202c;
  --mode-txt2: #4a5568;
  --mode-border: rgba(0, 0, 0, 0.1);
  --mode-surface: rgba(0, 0, 0, 0.03);
}

/* Light Mode Card Color Overrides for Accessibility/Readability */
body.light .student-card.drawn .student-name {
  color: #047857; /* Deep readable emerald green */
}

body.light .student-card.picker-winner .student-name {
  color: #b45309; /* Deep readable amber gold */
}

body.light .status-dot {
  color: #059669; /* Deep emerald dot status */
}

body.light .status-dot::before {
  background: #059669;
}

body.light .student-card.absent .status-dot {
  color: #dc2626; /* Deep red dot status */
}

body.light .student-card.absent .status-dot::before {
  background: #dc2626;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--mode-bg);
  color: var(--mode-txt);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s, color 0.4s;
  line-height: 1.5;
}

/* SCROLL BAR */
#scroll-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--purple), var(--pink));
  z-index: 9999;
  transition: width 0.08s linear;
  border-radius: 0 100px 100px 0;
}

/* NAVBAR */
#navbar {
  position: sticky;
  top: 0;
  z-index: 800;
  background: rgba(7, 11, 20, 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--mode-border);
  height: 62px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  justify-content: space-between;
}

body.light #navbar {
  background: rgba(240, 244, 248, 0.88);
}

.navbar-brand {
  font-weight: 900;
  font-size: 1rem;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
}

.navbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.nav-back-link {
  text-decoration: none;
  color: var(--mode-txt2);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--mode-border);
  border-radius: 8px;
  transition: all 0.2s;
  background: var(--mode-surface);
}

.nav-back-link:hover {
  color: var(--mode-txt);
  border-color: var(--blue);
  background: rgba(79, 142, 247, 0.08);
}

#mode-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--rad-sm);
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  color: var(--mode-txt);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#mode-toggle:hover {
  background: rgba(79, 142, 247, 0.15);
  border-color: var(--blue);
}

/* HERO SECTION */
.hero {
  text-align: center;
  padding: 3rem 1.5rem 2rem;
  background:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(168, 85, 247, 0.1) 0%, transparent 60%);
  position: relative;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 100px;
  padding: 0.35rem 1.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--purple);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  animation: fadeUp 0.6s ease both;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 0.5rem;
  animation: fadeUp 0.7s ease both 0.1s;
}

.hero h1 .grad {
  background: linear-gradient(120deg, var(--blue), var(--purple), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p {
  color: var(--mode-txt2);
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto 1.5rem;
  animation: fadeUp 0.7s ease both 0.2s;
}

/* STATS ROW */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 800px;
  margin: 0 auto;
  animation: fadeUp 0.7s ease both 0.3s;
}

.stat-card {
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  border-radius: var(--rad-sm);
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 130px;
  flex: 1;
}

.stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--mode-txt);
}

.stat-lbl {
  font-size: 0.7rem;
  color: var(--mode-txt2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* MAIN CONTENT SPLIT */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1.2fr 1.8fr;
  gap: 1.5rem;
}

@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
  }
}

/* LEFT SIDE: CONTROLS & PICKER */
.left-pane {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* SCREEN PANEL */
.picker-card {
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.picker-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--blue), var(--purple), var(--pink));
}

.picker-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mode-txt2);
  margin-bottom: 1.5rem;
}

/* SPIN DISPLAY SCREEN */
.display-screen {
  background: rgba(0, 0, 0, 0.3);
  border: 1.5px solid var(--mode-border);
  border-radius: var(--rad-sm);
  min-height: 160px;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  padding: 1.5rem 1rem 2.5rem;
  position: relative;
  overflow: hidden;
}

body.light .display-screen {
  background: #090d16;
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

body.light .display-name {
  color: #f1f5f9;
}

body.light .display-name.spinning {
  color: var(--cyan);
}

body.light .display-name.winner {
  color: var(--yellow);
  text-shadow: 0 0 15px rgba(252, 211, 77, 0.6);
}

.display-name {
  font-size: clamp(1.3rem, 4vw, 1.85rem);
  font-weight: 900;
  color: var(--mode-txt);
  text-align: center;
  word-break: break-word;
  max-width: 100%;
  transition: transform 0.1s ease;
  line-height: 1.2;
}

.display-name.spinning {
  animation: reelSpin 0.1s linear infinite;
  color: var(--purple);
}

.display-name.winner {
  color: var(--yellow);
  font-size: clamp(1.4rem, 4.5vw, 2.1rem);
  text-shadow: 0 0 15px rgba(252, 211, 77, 0.4);
  animation: popWinner 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.display-class {
  position: absolute;
  bottom: 0.75rem;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  background: var(--mode-txt3);
}

.display-class.t1 {
  background: var(--blue);
}

.display-class.t2 {
  background: var(--purple);
}

/* BUTTONS AND TOGGLES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--rad-sm);
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  color: var(--mode-txt2);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-outline {
  background: var(--mode-surface);
  color: var(--mode-txt);
  border: 1px solid var(--mode-border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--blue);
  background: rgba(79, 142, 247, 0.08);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* PANEL SETTINGS */
.panel-settings {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
  text-align: left;
  border-top: 1px solid var(--mode-border);
  padding-top: 1.25rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--mode-txt2);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  cursor: pointer;
  accent-color: var(--purple);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* HISTORY CARD */
.history-card {
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  max-height: 380px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.history-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--mode-txt);
}

.history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-right: 0.25rem;
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--mode-border);
  border-radius: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--mode-bg2);
  border: 1px solid var(--mode-border);
  border-radius: var(--rad-sm);
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  animation: slideIn 0.3s ease forwards;
}

.history-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-num {
  font-weight: 800;
  color: var(--mode-txt2);
  font-size: 0.75rem;
  background: var(--mode-surface);
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.history-name {
  font-weight: 600;
}

.history-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: #fff;
}

.history-badge.t1 {
  background: var(--blue);
}

.history-badge.t2 {
  background: var(--purple);
}

.history-delete {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
  padding: 0.2rem;
}

.history-delete:hover {
  opacity: 1;
}

.history-empty {
  color: var(--mode-txt2);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 0;
  font-style: italic;
}

/* RIGHT SIDE: STUDENTS CONTROL LIST */
.right-pane {
  background: var(--mode-surface);
  border: 1px solid var(--mode-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.list-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* CLASS TABS */
.tabs-wrap {
  display: flex;
  background: var(--mode-bg3);
  padding: 0.25rem;
  border-radius: var(--rad-sm);
  border: 1px solid var(--mode-border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--mode-txt2);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  outline: none;
}

.tab-btn:hover {
  color: var(--mode-txt);
}

.tab-btn.active {
  background: var(--mode-bg2);
  color: var(--mode-txt);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* SEARCH INPUT */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}

.search-input {
  width: 100%;
  background: var(--mode-bg2);
  border: 1px solid var(--mode-border);
  color: var(--mode-txt);
  padding: 0.45rem 0.75rem;
  border-radius: var(--rad-sm);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
}

.search-input:focus {
  border-color: var(--blue);
}

/* STUDENT GRID */
.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.85rem;
  max-height: 600px;
  overflow-y: auto;
  padding: 0.5rem;
  padding-right: 0.6rem;
}

.student-grid::-webkit-scrollbar {
  width: 6px;
}

.student-grid::-webkit-scrollbar-thumb {
  background: var(--mode-border);
  border-radius: 10px;
}

/* STUDENT CARD */
.student-card {
  background: var(--mode-bg2);
  border: 1px solid var(--mode-border);
  border-radius: var(--rad-sm);
  padding: 0.85rem 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  min-height: 125px;
  box-sizing: border-box;
}

.student-card:hover {
  transform: translateY(-2px);
  border-color: rgba(168, 85, 247, 0.3);
  box-shadow: 0 4px 12px rgba(168, 85, 247, 0.08);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.25rem;
}

.class-pill {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: #fff;
}

.class-pill.t1 {
  background: var(--blue);
}

.class-pill.t2 {
  background: var(--purple);
}

.student-initials {
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--mode-surface);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--mode-txt2);
  border: 1px solid var(--mode-border);
}

.student-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--mode-txt);
  line-height: 1.3;
  margin-top: 0.25rem;
  word-wrap: break-word;
}

.card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-top: 1px solid var(--mode-border);
  padding-top: 0.6rem;
  margin-top: auto;
}

/* Attendance toggle label */
.attendance-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--mode-txt2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.attendance-toggle input {
  margin: 0;
  accent-color: var(--red);
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Dotted Status indicator */
.status-dot {
  font-size: 0.65rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--green);
  white-space: nowrap;
}

.status-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

/* CARD STATES */
/* Drawn card */
.student-card.drawn {
  background: linear-gradient(135deg, var(--mode-bg2), rgba(52, 211, 153, 0.05));
  border-color: var(--green);
  box-shadow: 0 4px 15px rgba(52, 211, 153, 0.08);
}

.student-card.drawn .student-name {
  color: var(--green);
}

/* Absent Card */
.student-card.absent {
  opacity: 0.5;
  background: var(--mode-bg3);
  border-color: var(--mode-border);
}

.student-card.absent .student-name {
  text-decoration: line-through;
  color: var(--mode-txt2);
}

.student-card.absent .status-dot {
  color: var(--red);
}

.student-card.absent .status-dot::before {
  background: var(--red);
}

/* Flash picker highlighting */
.student-card.picker-highlight {
  border-color: var(--purple);
  background: rgba(168, 85, 247, 0.15);
  transform: scale(1.02);
  z-index: 10;
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.35);
}

/* Winner Card highlight */
.student-card.picker-winner {
  border-color: var(--yellow);
  background: rgba(252, 211, 77, 0.15);
  transform: scale(1.04);
  z-index: 15;
  box-shadow: 0 0 20px rgba(252, 211, 77, 0.45), inset 0 0 10px rgba(252, 211, 77, 0.25);
  animation: pulseWinnerCard 1.5s infinite alternate;
}

/* CONFETTI ANIMATIONS */
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--yellow);
  border-radius: 50%;
  z-index: 999;
  pointer-events: none;
}

/* ANIMATIONS KEYFRAMES */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes reelSpin {
  0% { transform: translateY(0); opacity: 1; }
  25% { transform: translateY(-10px); opacity: 0.3; }
  26% { transform: translateY(10px); opacity: 0; }
  50% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes popWinner {
  0% { transform: scale(0.6); opacity: 0; }
  80% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulseWinnerCard {
  0% { box-shadow: 0 0 15px rgba(252, 211, 77, 0.3); }
  100% { box-shadow: 0 0 30px rgba(252, 211, 77, 0.6); }
}
