@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --primary: #6C5CE7;
  --primary-dark: #A29BFE;
  --primary-medium: #DFE6E9;
  --primary-light: #FFEAA7;
  --primary-bg: #2D3436;
  --white: #FFFFFF;
  --off-white: #F5F6FC;
  --gray-100: #EEEEF5;
  --gray-200: #D1D5E8;
  --gray-300: #A0A4BE;
  --gray-500: #6B6F8D;
  --gray-700: #3A3D56;
  --gray-900: #1E1F33;
  --success: #43A047;
  --danger: #E53935;
  --warning: #FB8C00;
  --opt-a: #E53935;
  --opt-b: #1E88E5;
  --opt-c: #FDD835;
  --opt-d: #43A047;
  --shadow-sm: 0 1px 3px rgba(63, 81, 181, 0.08);
  --shadow-md: 0 4px 12px rgba(63, 81, 181, 0.12);
  --shadow-lg: 0 8px 32px rgba(63, 81, 181, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

::selection {
  background: var(--primary-light);
  color: var(--white);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--primary-bg);
  color: var(--gray-900);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
}

/* ===== ROLE SELECT ===== */
.role-select-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 50%, var(--primary-medium) 100%);
  padding: 1rem;
}

.role-select-container {
  text-align: center;
  animation: fadeInUp 0.6s ease both;
}

.logo-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.app-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -0.02em;
}

.app-subtitle {
  color: var(--primary-light);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
  font-weight: 500;
}

.role-cards {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  flex-wrap: wrap;
}

.role-card {
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(12px);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-xl);
  padding: 2rem 2.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.3s ease;
  min-width: 180px;
  color: var(--white);
  font-family: inherit;
}

.role-card:hover {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.4);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.role-emoji {
  font-size: 2.5rem;
}

.role-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
}

.role-desc {
  font-size: 0.85rem;
  color: var(--primary-light);
  font-weight: 500;
}

/* ===== APP SHELL ===== */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-logo {
  font-size: 1.5rem;
}

.header-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.switch-role-btn {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.switch-role-btn:hover {
  background: var(--primary);
  color: var(--white);
}

.app-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* ===== TABS ===== */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--primary);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(63, 81, 181, 0.3);
}

.tab-btn:not(.active):hover {
  background: var(--primary-bg);
  color: var(--primary);
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.5rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(63, 81, 181, 0.3);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.5rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.btn-accent {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-accent:hover {
  background: var(--primary);
  color: var(--white);
}

.btn-large {
  padding: 0.85rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

.btn-icon {
  background: var(--gray-100);
  border: none;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--primary-bg);
}

.btn-icon.btn-danger:hover {
  background: #FFEBEE;
}

.btn-tiny {
  background: var(--gray-100);
  border: none;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-tiny:hover:not(:disabled) {
  background: var(--primary-bg);
}

.btn-tiny:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-tiny.btn-danger {
  color: var(--danger);
}

/* ===== INPUTS ===== */
.field-group {
  margin-bottom: 1rem;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.field-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--gray-900);
  background: var(--white);
  transition: all 0.2s ease;
  outline: none;
}

.field-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(63, 81, 181, 0.12);
}

.field-input::placeholder {
  color: var(--gray-300);
}

.time-input {
  max-width: 120px;
}

/* ===== CREATE QUIZ BTN ===== */
.create-quiz-btn {
  width: 100%;
  padding: 1rem;
  background: var(--white);
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius-md);
  color: var(--primary);
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.create-quiz-btn:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
}

/* ===== QUIZ GRID ===== */
.quiz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.quiz-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  animation: fadeInUp 0.4s ease both;
  animation-delay: var(--anim-delay, 0s);
}

.quiz-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.quiz-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.quiz-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gray-900);
}

.question-count {
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  white-space: nowrap;
}

.quiz-card-actions {
  display: flex;
  gap: 0.5rem;
}

/* ===== QUIZ BUILDER ===== */
.quiz-builder {
  animation: fadeInUp 0.4s ease both;
}

.builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.builder-header h2 {
  color: var(--primary);
}

.builder-header-actions {
  display: flex;
  gap: 0.5rem;
}

.builder-body {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.questions-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--gray-100);
  padding-top: 1.5rem;
}

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

.questions-header h3 {
  color: var(--gray-700);
  font-size: 1rem;
}

.question-card {
  background: var(--off-white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
  animation: fadeInUp 0.3s ease both;
}

.question-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.question-number {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 0.15rem 0.6rem;
  border-radius: 6px;
}

.question-card-controls {
  display: flex;
  gap: 0.25rem;
}

.question-text-input {
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.options-grid {
  display: grid;
  gap: 0.5rem;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.option-row.correct .option-input {
  border-color: var(--success);
  background: #E8F5E9;
}

.correct-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--gray-200);
  background: var(--white);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  flex-shrink: 0;
}

.correct-toggle.active {
  background: var(--success);
  border-color: var(--success);
  color: var(--white);
}

.option-input {
  flex: 1;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state.small-empty {
  padding: 1.5rem;
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 0.75rem;
}

.empty-text {
  color: var(--gray-500);
  font-size: 1rem;
}

/* ===== LOADING SKELETON ===== */
.loading-skeleton {
  display: grid;
  gap: 1rem;
}

.skel-card {
  height: 100px;
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  animation: shimmer 1.5s infinite;
}

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

/* ===== HISTORY ===== */
.history-list {
  display: grid;
  gap: 0.75rem;
}

.history-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.4s ease both;
  animation-delay: var(--anim-delay, 0s);
}

.history-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-card-top h4 {
  font-size: 1rem;
  color: var(--gray-900);
}

.history-date {
  font-size: 0.8rem;
  color: var(--gray-300);
  font-weight: 500;
}

.history-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}

.history-top {
  font-size: 0.85rem;
  color: var(--gray-700);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.top-player {
  background: var(--primary-bg);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.8rem;
}

/* ===== LIVE QUIZ - LOBBY ===== */
.live-quiz {
  animation: fadeInUp 0.4s ease both;
}

.lobby-screen {
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
  padding: 2rem 0;
}

.lobby-title {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 2rem;
}

.room-code-display {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  display: inline-flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 0.75rem;
  border: 2px solid var(--primary-light);
}

.room-code-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.room-code-value {
  font-family: 'Space Grotesk', monospace;
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.15em;
}

.lobby-info {
  color: var(--gray-500);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.player-count-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.5rem;
}

.player-count-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.player-count-label {
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 500;
}

.joined-players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 2rem;
}

.player-chip {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  animation: popIn 0.3s ease both;
}

.lobby-screen .btn-primary {
  margin-bottom: 0.75rem;
  width: 100%;
}

.lobby-screen .btn-secondary {
  width: 100%;
}

/* ===== LIVE QUIZ - QUESTION ===== */
.live-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.live-progress {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
}

.live-timer {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 0.25rem 1rem;
  border-radius: var(--radius-sm);
  transition: all 0.3s ease;
}

.live-timer.urgent {
  color: var(--danger);
  background: #FFEBEE;
  animation: pulse 0.5s ease infinite alternate;
}

.live-responses {
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 600;
}

.live-question-area {
  text-align: center;
}

.live-question-text {
  font-size: 1.5rem;
  color: var(--gray-900);
  margin-bottom: 2rem;
  line-height: 1.4;
}

.live-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.live-option {
  padding: 1.25rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  color: var(--white);
  transition: all 0.3s ease;
  position: relative;
}

.live-option.opt-a { background: var(--opt-a); }
.live-option.opt-b { background: var(--opt-b); }
.live-option.opt-c { background: var(--opt-c); color: var(--gray-900); }
.live-option.opt-d { background: var(--opt-d); }

.live-option.correct-reveal {
  box-shadow: 0 0 0 4px var(--white), 0 0 0 6px var(--success);
  transform: scale(1.03);
}

.live-option.wrong-reveal {
  opacity: 0.5;
}

.opt-letter {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.opt-text {
  flex: 1;
  text-align: left;
}

.opt-count {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  background: rgba(255,255,255,0.3);
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
}

.live-actions {
  text-align: center;
  margin-top: 2rem;
  animation: fadeInUp 0.3s ease both;
}

.live-actions .btn-large {
  min-width: 250px;
}

/* ===== FINISHED SCREEN ===== */
.finished-screen {
  text-align: center;
  padding: 2rem 0;
  animation: fadeInUp 0.5s ease both;
}

.finished-screen h2 {
  font-size: 2rem;
  color: var(--primary);
  margin-bottom: 2rem;
}

.finished-screen .btn-large {
  margin-top: 2rem;
}

/* ===== STUDENT VIEW ===== */
.student-view {
  animation: fadeInUp 0.4s ease both;
}

.join-screen {
  text-align: center;
  max-width: 400px;
  margin: 2rem auto;
}

.join-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.join-screen h2 {
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-code-input {
  text-align: center;
  font-family: 'Space Grotesk', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 0.75rem;
}

/* ===== WAITING SCREEN ===== */
.waiting-screen {
  text-align: center;
  padding: 4rem 1rem;
}

.pulse-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-light);
  margin: 0 auto 1.5rem;
  animation: pulseGrow 1.5s ease infinite;
}

.waiting-screen h2 {
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.waiting-text {
  color: var(--gray-500);
}

/* ===== STUDENT QUESTION ===== */
.student-question-screen {
  max-width: 600px;
  margin: 0 auto;
}

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

.student-q-num {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
}

.student-timer {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 0.25rem 1rem;
  border-radius: var(--radius-sm);
  transition: all 0.3s ease;
}

.student-timer.urgent {
  color: var(--danger);
  background: #FFEBEE;
  animation: pulse 0.5s ease infinite alternate;
}

.student-question-text {
  font-size: 1.25rem;
  text-align: center;
  margin-bottom: 1.5rem;
  line-height: 1.4;
  color: var(--gray-900);
}

.student-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.student-option {
  padding: 1.25rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--white);
  transition: all 0.2s ease;
  text-align: left;
  min-height: 70px;
}

.student-option.opt-a { background: var(--opt-a); }
.student-option.opt-b { background: var(--opt-b); }
.student-option.opt-c { background: var(--opt-c); color: var(--gray-900); }
.student-option.opt-d { background: var(--opt-d); }

.student-option:hover:not(:disabled) {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}

.student-option:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.student-option.selected {
  box-shadow: 0 0 0 4px var(--white), 0 0 0 6px var(--primary);
  transform: scale(1.03);
}

.student-option.correct-reveal {
  box-shadow: 0 0 0 4px var(--white), 0 0 0 6px var(--success);
}

.student-option.wrong-answer {
  opacity: 0.5;
  box-shadow: 0 0 0 4px var(--white), 0 0 0 6px var(--danger);
}

.so-letter {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.so-text {
  flex: 1;
}

.answer-submitted {
  text-align: center;
  margin-top: 1.5rem;
  color: var(--success);
  font-weight: 600;
  font-size: 1.1rem;
  animation: popIn 0.3s ease both;
}

.reveal-message {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  animation: popIn 0.4s ease both;
}

.reveal-message.correct {
  color: var(--success);
}

.reveal-message.incorrect {
  color: var(--danger);
}

/* ===== STUDENT FINISHED ===== */
.finished-student-screen {
  text-align: center;
  padding: 2rem 0;
  animation: fadeInUp 0.5s ease both;
}

.finished-student-screen h2 {
  font-size: 2rem;
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.my-result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.my-rank {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
}

.my-score {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-700);
  background: var(--primary-bg);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
}

.final-leaderboard {
  max-width: 400px;
  margin: 0 auto 2rem;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--white);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  border: 1px solid var(--gray-200);
  animation: fadeInUp 0.3s ease both;
}

.leaderboard-row.is-me {
  background: var(--primary-bg);
  border-color: var(--primary-light);
}

.lb-rank {
  font-size: 1.1rem;
  width: 32px;
  text-align: center;
  font-weight: 700;
}

.lb-name {
  flex: 1;
  font-weight: 600;
  color: var(--gray-700);
  text-align: left;
}

.lb-score {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: var(--primary);
}

/* ===== SCOREBOARD ===== */
.scoreboard {
  max-width: 500px;
  margin: 0 auto;
}

.scoreboard-title {
  text-align: center;
  color: var(--primary);
  margin-bottom: 1.25rem;
  font-size: 1.25rem;
}

.scoreboard-list {
  display: grid;
  gap: 0.5rem;
}

.scoreboard-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--white);
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  animation: fadeInUp 0.4s ease both;
  animation-delay: var(--anim-delay, 0s);
}

.sb-rank {
  font-size: 1.25rem;
  width: 36px;
  text-align: center;
  font-weight: 700;
}

.sb-name {
  width: 100px;
  font-weight: 600;
  color: var(--gray-700);
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-score-bar {
  flex: 1;
  height: 8px;
  background: var(--gray-100);
  border-radius: 4px;
  overflow: hidden;
}

.sb-score-fill {
  height: 100%;
  width: var(--fill-width, 0%);
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  border-radius: 4px;
  transition: width 0.8s ease;
}

.sb-score {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
  min-width: 50px;
  text-align: right;
}

.scoreboard-empty {
  text-align: center;
  padding: 2rem;
  color: var(--gray-500);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  70% {
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

@keyframes pulseGrow {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0.6;
  }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 640px) {
  .app-main {
    padding: 1rem;
  }

  .role-cards {
    flex-direction: column;
    align-items: center;
  }

  .role-card {
    width: 100%;
    max-width: 280px;
  }

  .app-title {
    font-size: 2rem;
  }

  .live-options-grid,
  .student-options {
    grid-template-columns: 1fr;
  }

  .live-question-text {
    font-size: 1.2rem;
  }

  .room-code-value {
    font-size: 2.25rem;
  }

  .quiz-grid {
    grid-template-columns: 1fr;
  }

  .builder-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .builder-header-actions {
    width: 100%;
  }

  .builder-header-actions .btn-primary,
  .builder-header-actions .btn-secondary {
    flex: 1;
  }

  .sb-name {
    width: 70px;
  }
}

<!-- WALKTHROUGH_SCRIPT:
[
  {"step": 1, "narration": "Welcome to QuizPulse! Choose whether you're a Teacher or a Student.", "view": "visitor", "highlight_selector": ".role-cards", "wait_for": "user_interaction"},
  {"step": 2, "narration": "As a Teacher, tap 'Create New Quiz' to build your first quiz.", "view": "teacher", "highlight_selector": ".create-quiz-btn", "wait_for": "user_interaction"},
  {"step": 3, "narration": "Give your quiz a title, set the time per question, then add multiple choice questions.", "view": "teacher", "highlight_selector": ".builder-body", "wait_for": "user_interaction"},
  {"step": 4, "narration": "Mark the correct answer by clicking the letter circle next to each option. Green means correct!", "view": "teacher", "highlight_selector": ".correct-toggle", "wait_for": "tap_to_continue"},
  {"step": 5, "narration": "Save your quiz, then hit the play button to start a live session.", "view": "teacher", "highlight_selector": ".quiz-card-actions", "wait_for": "user_interaction"},
  {"step": 6, "narration": "Share the room code with your students. Wait for them to join, then start the quiz!", "view": "teacher", "highlight_selector": ".room-code-display", "wait_for": "user_interaction"},
  {"step": 7, "narration": "Students enter their name and the room code to join the quiz.", "view": "student", "highlight_selector": ".join-form", "wait_for": "user_interaction"},
  {"step": 8, "narration": "Answer each question by tapping one of the colored options. Faster answers earn bonus points!", "view": "student", "highlight_selector": ".student-options", "wait_for": "user_interaction"},
  {"step": 9, "narration": "After each question, see if you got it right and watch the live scoreboard update.", "view": "student", "highlight_selector": ".reveal-message", "wait_for": "tap_to_continue"},
  {"step": 10, "narration": "At the end, see the final leaderboard with rankings and scores. Check the History tab for past results!", "view": "teacher", "highlight_selector": ".scoreboard", "wait_for": "tap_to_continue"}
]
-->

.presence-tab {
  display: grid;
  gap: 1rem;
}

.presence-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.presence-header h2 {
  color: var(--primary);
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
}

.presence-subtitle {
  color: var(--gray-500);
  font-size: 0.9rem;
}

.presence-count-badge {
  background: var(--primary-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}

.presence-list {
  display: grid;
  gap: 0.75rem;
}

.presence-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.35s ease both;
  animation-delay: var(--anim-delay, 0s);
}

.presence-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(67, 160, 71, 0.12);
  flex-shrink: 0;
}

.presence-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.presence-info strong {
  color: var(--gray-900);
}

.presence-info span {
  color: var(--gray-500);
  font-size: 0.85rem;
}

.teacher-auth-gate {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.teacher-auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  text-align: center;
}

.teacher-auth-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.teacher-auth-card h2 {
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.teacher-auth-card p {
  color: var(--gray-500);
  margin-bottom: 1.5rem;
}

.teacher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
}

.teacher-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.teacher-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 800;
  flex-shrink: 0;
}

.teacher-identity h2 {
  font-size: 1.05rem;
  color: var(--gray-900);
}

.teacher-email {
  color: var(--gray-500);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.ai-builder-panel {
  background: var(--primary-bg);
  border: 1px solid var(--primary-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.ai-builder-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.ai-generate-btn {
  align-self: flex-start;
}

.ai-feedback {
  font-size: 0.9rem;
  font-weight: 500;
}

.ai-feedback.success {
  color: var(--success);
}

.ai-feedback.error {
  color: var(--danger);
}

.scoreboard-wrap {
  display: grid;
  gap: 1rem;
}

.scoreboard-controls {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.scoreboard-export-field {
  flex: 1;
  min-width: 220px;
  margin-bottom: 0;
}

.btn-export-pdf {
  white-space: nowrap;
}

.scoreboard-subtitle {
  text-align: center;
  color: var(--gray-500);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.scoreboard-report-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-200);
}

.scoreboard-report-title {
  color: var(--gray-700);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.scoreboard-report-list {
  display: grid;
  gap: 0.75rem;
}

.scoreboard-question-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.scoreboard-question-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.scoreboard-question-number {
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.scoreboard-question-points {
  font-weight: 700;
  color: var(--gray-500);
  font-size: 0.85rem;
}

.scoreboard-question-text {
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.65rem;
  line-height: 1.4;
}

.scoreboard-question-meta {
  display: grid;
  gap: 0.35rem;
  color: var(--gray-700);
  font-size: 0.9rem;
}

.scoreboard-report-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  color: var(--gray-500);
  font-size: 0.85rem;
  border-top: 1px dashed var(--gray-200);
  padding-top: 0.75rem;
}

@media (max-width: 640px) {
  .scoreboard-controls {
    align-items: stretch;
  }

  .btn-export-pdf {
    width: 100%;
  }
}

.export-responses-panel {
  margin: 1.5rem auto 1.5rem;
  max-width: 560px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.export-responses-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.export-responses-header h3 {
  color: var(--primary);
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.export-responses-header p {
  color: var(--gray-500);
  font-size: 0.9rem;
}

.export-format-toggle {
  display: flex;
  gap: 0.35rem;
  background: var(--gray-100);
  padding: 0.25rem;
  border-radius: 999px;
}

.export-format-toggle .btn-tiny {
  width: auto;
  min-width: 54px;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: transparent;
}

.export-format-toggle .btn-tiny.active {
  background: var(--primary);
  color: var(--white);
}

.export-responses-actions {
  display: flex;
  justify-content: flex-end;
}

.export-responses-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--gray-500);
}
