:root {
  --bg: #fff9ee;
  --ink: #16213a;
  --accent: #1f6f78;
  --accent-2: #f08a24;
  --card: #ffffffcc;
  --dot: #101010;
  --ok: #147a32;
  --bad: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #ff7777 0%, #fff9ee 36%, #e9f7f6 100%);
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  filter: blur(30px);
  opacity: 0.6;
}

.bg-shape-1 {
  width: 320px;
  height: 320px;
  border-radius: 40% 60% 65% 35%;
  background: #ffc36b;
  top: -80px;
  left: -90px;
}

.bg-shape-2 {
  width: 280px;
  height: 280px;
  border-radius: 68% 32% 27% 73%;
  background: #80cbc4;
  right: -90px;
  bottom: 30px;
}

.topbar {
  padding: 22px 22px 10px;
}

.topbar-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.topbar h1 {
  margin: 0;
  letter-spacing: 0.4px;
  font-size: clamp(1.4rem, 2.8vw, 2.3rem);
}

.topbar p {
  margin: 6px 0 0;
  max-width: 760px;
  font-size: 0.98rem;
  opacity: 0.9;
}

.nav-link {
  display: inline-block;
  color: #1f6f78;
  text-decoration: none;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #1f6f78;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-link:hover {
  background: #1f6f78;
  color: white;
}

.layout {
  padding: 14px 22px 26px;
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 18px;
}

.panel {
  border: 1px solid #ffffff;
  border-radius: 18px;
  background: var(--card);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 35px #9f8f7633;
}

.controls {
  padding: 14px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.controls section + section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed #d7d7d7;
}

h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.hint {
  margin: 7px 0 0;
  font-size: 0.86rem;
  line-height: 1.4;
  opacity: 0.84;
}

.file-btn,
.primary-btn,
.ghost-btn {
  display: inline-block;
  margin-top: 4px;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.primary-btn {
  width: 100%;
  margin-top: 12px;
  background: var(--accent-2);
  color: #1d1408;
}

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

.ghost-btn {
  background: #ecf5f4;
  color: #0c4950;
}

.ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

input[type="file"] {
  display: none;
}

.question-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid #d8dee9;
  border-radius: 11px;
  background: #fff;
}

.question-row label {
  font-size: 0.9rem;
  font-weight: 500;
}

.question-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.answer-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-input {
  width: 100%;
  border: 1px solid #bfd0e6;
  border-radius: 8px;
  padding: 6px 8px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.choice-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.choice-item label {
  width: 18px;
  font-size: 0.8rem;
}

.answer-select {
  width: 100%;
  font-family: "IBM Plex Mono", monospace;
  border: 1px solid #bfd0e6;
  border-radius: 8px;
  padding: 5px;
}

.grade-result {
  margin-top: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.viewer-panel {
  padding: 12px;
}

.pdf-container {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  max-width: 100%;
  overflow: auto;
  border-radius: 14px;
  box-shadow: 0 10px 24px #00000020;
  background: #fff;
}

#pdfCanvas {
  display: block;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.corner-dot {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 3px #ffffffcc, 0 0 12px #00000044;
}

.mcq-anchor {
  position: absolute;
  min-width: 240px;
  max-width: 320px;
  pointer-events: auto;
  transform: translate(-8px, -8px);
}

.mcq-tag {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  color: #fff;
  background: #13203d;
  border-radius: 8px;
  padding: 2px 6px;
}

.option-row {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-direction: column;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.option-bubble {
  width: 24px;
  height: 24px;
  border: 2px solid #183164;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  color: #12233f;
}

.mcq-prompt {
  margin-top: 5px;
  font-size: 0.77rem;
  line-height: 1.2;
  max-width: 310px;
  color: #0f1d35;
  background: #ffffffd9;
  border-radius: 6px;
  padding: 2px 5px;
}

.option-text {
  font-size: 0.7rem;
  line-height: 1.1;
  max-width: 210px;
  color: #101f3a;
  background: #ffffffe8;
  border-radius: 5px;
  padding: 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend {
  margin: 10px 5px 0;
  font-size: 0.85rem;
  opacity: 0.82;
}

.hidden-canvas {
  display: none;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    max-height: unset;
  }
}

  .topbar-content {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── Profile Switcher ────────────────────────────────────────────── */

.ps-wrap {
  position: relative;
}

.ps-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #bdc5d1;
  border-radius: 6px;
  padding: 6px 10px 6px 12px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.ps-toggle:hover  { border-color: var(--accent); }
.ps-toggle:focus  { outline: 2px solid var(--accent); outline-offset: 1px; }

.ps-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 220px;
  background: #fff;
  border: 1px solid #bdc5d1;
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,.1);
  padding: 4px 0;
  z-index: 500;
}

.ps-menu.ps-open {
  display: block;
}

.ps-item {
  display: block;
  padding: 8px 14px;
  border-radius: 0;
  font-size: 0.87rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}

.ps-item:hover  { background: #f0faf9; }
.ps-active      { background: #e6f6f5; font-weight: 600; }
.ps-add         { color: var(--accent); font-weight: 600; background: none; border: none; cursor: pointer; width: 100%; text-align: left; font-family: inherit; }
.ps-out         { color: #888; font-size: 0.82rem; background: none; border: none; cursor: pointer; width: 100%; text-align: left; font-family: inherit; }
.ps-hr          { border: none; border-top: 1px solid #eee; margin: 4px 0; }

.ps-new-form {
  padding: 6px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px dashed #e2e8f0;
  border-bottom: 1px dashed #e2e8f0;
  margin: 2px 0;
}

/* ── Auth page ───────────────────────────────────────────────────── */

.auth-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--card);
  backdrop-filter: blur(10px);
  border: 1px solid #ffffff;
  border-radius: 20px;
  box-shadow: 0 10px 40px #9f8f7633;
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #888;
  transition: all 0.15s;
}

.auth-tab-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px #0001;
}

.auth-form { display: flex; flex-direction: column; gap: 6px; }

.auth-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 6px;
}

.auth-error {
  font-size: 0.83rem;
  color: var(--bad);
  min-height: 18px;
  margin-top: 2px;
}

/* ── Dashboard (student + teacher) ──────────────────────────────── */

.dash-main {
  padding: 0 22px 40px;
  max-width: 960px;
}

.dash-section {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid #ffffff;
  border-radius: 16px;
  box-shadow: 0 6px 24px #9f8f7622;
  padding: 18px 20px;
  margin-top: 18px;
}

.dash-heading {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: 0.2px;
}

.quiz-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.quiz-card {
  background: #fff;
  border: 1px solid #e8edf4;
  border-radius: 12px;
  padding: 14px 16px;
}

.quiz-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow 0.15s, transform 0.15s;
}

.quiz-card-link:hover {
  box-shadow: 0 4px 16px #1f6f7830;
  transform: translateY(-2px);
}

.qc-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
  letter-spacing: 0.2px;
}

.qc-pending   { background: #fef3c7; color: #92400e; }
.qc-submitted { background: #dbeafe; color: #1e40af; }
.qc-graded    { background: #dcfce7; color: #166534; }
.qc-class     { background: #ede9fe; color: #5b21b6; }

.qc-title { font-weight: 700; font-size: 0.92rem; margin-bottom: 4px; }
.qc-sub   { font-size: 0.8rem; color: #888; }

/* ── Tab navigation ──────────────────────────────────────────────── */

.tab-nav {
  display: flex;
  gap: 4px;
  padding: 0 22px 0;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px 10px 0 0;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: #e8edf4;
  color: #555;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover      { background: #d1dce8; color: var(--ink); }
.tab-btn-active     { background: var(--card); color: var(--ink); box-shadow: 0 -2px 0 var(--accent) inset; }

/* ── More dropdown ──────────────────────────────────────────────── */
.more-dropdown { position: relative; }
.more-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  background: var(--card);
  border-radius: 0 8px 8px 8px;
  box-shadow: 0 4px 18px #0002;
  min-width: 195px;
  z-index: 200;
  display: none;
  flex-direction: column;
  padding: 4px;
  border: 1px solid #e0e6f0;
}
.more-menu.open { display: flex; }
.more-menu-item {
  padding: 9px 14px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #555;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.more-menu-item:hover { background: #e8edf4; color: var(--ink); }
.more-menu-item.tab-btn-active { background: #e0f2f2; color: var(--ink); }

/* ── Gradebook table ─────────────────────────────────────────── */
.gradebook-table {
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 100%;
}
.gradebook-table th,
.gradebook-table td {
  border: 1px solid #e8edf4;
  padding: 4px 8px;
  white-space: nowrap;
}
.gb-name-header,
.gb-total-header {
  background: var(--card);
  font-weight: 700;
  font-size: 0.82rem;
  z-index: 1;
}
.gb-name-header {
  position: sticky;
  left: 0;
}
.gb-col-header {
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  text-align: left;
  vertical-align: bottom;
  height: 130px;
  min-width: 36px;
  font-weight: 600;
  background: #f9fafb;
  font-size: 0.75rem;
  padding: 8px 4px;
}
.gb-cat-group {
  text-align: center;
  font-weight: 700;
  background: #e0f2f2;
  color: #0c4950;
  font-size: 0.8rem;
  border-bottom: none;
}
.gb-cat-group.gb-uncategorized {
  background: #f3f4f6;
  color: #666;
}
.gb-cat-pct-col {
  background: #e0f2f2 !important;
  color: #0c4950;
  font-weight: 700;
}
.gb-student-name {
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--card);
  position: sticky;
  left: 0;
}
.gb-score        { text-align: center; }
.gb-score-missing { text-align: center; color: #ccc; }
.gb-cat-pct      { text-align: center; font-weight: 700; color: #1f6f78; background: #f0fafa; }
.gb-total        { text-align: center; font-weight: 700; background: #e0f2f2; color: #0c4950; }

/* ── Standards tree ─────────────────────────────────────────── */
.std-tree { margin-bottom: 8px; }
.std-node { margin-bottom: 2px; }
.std-node-header { border-radius: 5px; transition: background 0.12s; }
.std-node-header:hover { background: #f5f8fb; }
.std-node-children { border-left: 2px solid #e8edf4; margin-left: 20px; padding-left: 8px; }
.std-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e0f2f2; color: #0c4950; border-radius: 20px;
  font-size: 0.74rem; font-weight: 600; padding: 2px 8px;
  margin: 2px 3px 2px 0;
}
.std-chip button { background: none; border: none; cursor: pointer; color: #1f6f78; padding: 0 0 0 2px; font-size: 0.8rem; line-height: 1; }
