:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --amber: #d97706;
  --blue: #2563eb;
  --green: #15803d;
  --red: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-badge {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
}

.brand h1 {
  font-size: 1.05rem;
  margin: 0;
}

.brand p {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 64px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.content-area {
  padding: 1.25rem;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

.filter-group {
  margin-bottom: 0.75rem;
}

.filter-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.filter-group input,
.filter-group select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  background: #fff;
}

.filter-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.filter-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}

.lock-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  margin-bottom: 0.75rem;
}

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

.practice-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.segmented-control {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.seg-btn {
  border: none;
  background: var(--surface);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Question Card & Per-User Faint Watermark */
.q-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem;
  margin-bottom: 1rem;
  overflow: hidden;
}

.q-card::after {
  content: attr(data-watermark);
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-18deg);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(15, 23, 42, 0.042);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  z-index: 1;
}

.q-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  position: relative;
  z-index: 2;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.badge {
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text);
}

.badge-type {
  background: #ccfbf1;
  color: #115e59;
}

.badge-stars {
  background: #fef3c7;
  color: #92400e;
}

.badge-rep {
  background: #dbeafe;
  color: #1e40af;
}

.badge-combined {
  background: #fae8ff;
  color: #86198f;
}

.q-stem {
  font-size: 0.98rem;
  margin-bottom: 0.85rem;
  position: relative;
  z-index: 2;
}

.q-figure {
  margin: 0.75rem 0;
  text-align: center;
}

.q-figure img {
  max-width: 100%;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.cq-parts {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
  border-top: 1px dashed var(--border);
}

.cq-parts li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed #f1f5f9;
}

.mcq-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.mcq-option {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  cursor: pointer;
  font-size: 0.92rem;
}

.mcq-option.correct {
  border-color: var(--green);
  background: #dcfce7;
}

.mcq-option.wrong {
  border-color: var(--red);
  background: #fee2e2;
}

/* Solution Box */
.solution-panel {
  margin-top: 0.85rem;
  padding: 0.9rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  position: relative;
  z-index: 2;
}

.solution-status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.status-unverified {
  background: #fef3c7;
  color: #92400e;
}

.status-verified {
  background: #dcfce7;
  color: #166534;
}

/* Underneath Scratch Pad */
.scratchpad-wrap {
  margin-top: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.5rem;
  position: relative;
  z-index: 2;
}

.scratch-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.scratch-canvas {
  width: 100%;
  height: 220px;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  touch-action: none;
  background: #fcfcfd;
  cursor: crosshair;
}

/* Teacher Controls Bar */
.teacher-bar {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
}

.btn {
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-google {
  background: #1d4ed8;
  color: #fff;
}

.full-width {
  width: 100%;
  margin-top: 0.35rem;
}

.pagination,
.focus-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.25rem 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-card {
  background: #fff;
  border-radius: 10px;
  max-width: 420px;
  width: 100%;
  padding: 1.25rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.divider {
  text-align: center;
  margin: 0.85rem 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.auth-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0;
    z-index: 40;
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateY(0);
  }
  .mobile-only {
    display: inline-flex;
  }
  .mcq-grid {
    grid-template-columns: 1fr;
  }
}