:root {
  --bg: #f4f7fb;
  --ink: #1b2430;
  --muted: #4d5c70;
  --accent: #ff6f3c;
  --accent-2: #18b0b8;
  --card: #ffffff;
  --ok: #0f8f4f;
  --warn: #b54708;
  --border: #d8e1ec;
  --font-scale: 1;
  --base-font: 'Space Grotesk', sans-serif;
  --heading-font: 'Manrope', sans-serif;
  --access-gap: max(8px, env(safe-area-inset-right));
  --access-top: max(8px, env(safe-area-inset-top));
  --access-fab-size: 45px;
}

html {
  font-size: calc(16px * var(--font-scale));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--base-font);
  font-size: 1rem;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #dcf8ff 0%, transparent 30%),
    radial-gradient(circle at 80% 15%, #ffe7db 0%, transparent 35%),
    var(--bg);
  min-height: 100vh;
}

body.dyslexia-font {
  --base-font: 'Lexend', sans-serif;
  --heading-font: 'Lexend', sans-serif;
}

body.high-contrast {
  --bg: #000000;
  --ink: #fff35c;
  --muted: #8fff63;
  --accent: #8fff63;
  --accent-2: #fff35c;
  --card: #000000;
  --ok: #8fff63;
  --warn: #fff35c;
  --border: #8fff63;
  background: var(--bg);
}

body.high-contrast .bg-shape {
  display: none;
}

body.high-contrast .panel,
body.high-contrast .quiz,
body.high-contrast .results,
body.high-contrast .question-card,
body.high-contrast .result-card,
body.high-contrast .diagram-wrap,
body.high-contrast .accessibility-panel,
body.high-contrast .access-toggle,
body.high-contrast .diagram-font-control,
body.high-contrast .dashboard-card,
body.high-contrast .mini-card,
body.high-contrast .stat-card,
body.high-contrast .meta span,
body.high-contrast .account-menu-bar {
  background: #000 !important;
  border-color: #8fff63 !important;
  color: #fff35c !important;
}

body.high-contrast select,
body.high-contrast input,
body.high-contrast textarea {
  background: #000;
  color: #fff35c;
  border-color: #8fff63;
}

body.high-contrast button {
  background: #8fff63;
  color: #000;
}

body.high-contrast .secondary,
body.high-contrast .purple-print,
body.high-contrast .access-fab {
  background: #fff35c;
  color: #000;
}

body.high-contrast .diagram-canvas {
  background: #000;
  border-color: #8fff63;
}

body.high-contrast .question-figure {
  background: #000;
  border-color: #8fff63;
}

body.high-contrast .video-modal-dialog,
body.high-contrast .video-modal-frame-wrap {
  background: #000;
  border-color: #8fff63;
  color: #fff35c;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(20px);
  opacity: 0.4;
}

.shape-a {
  width: 280px;
  height: 280px;
  background: #9df0f7;
  top: -80px;
  right: 5%;
}

.shape-b {
  width: 220px;
  height: 220px;
  background: #ffd2c0;
  bottom: 40px;
  left: -50px;
}

.container {
  width: min(980px, 92vw);
  margin: 2rem auto 3rem;
}

.hero {
  margin-bottom: 1.2rem;
}

.eyebrow {
  margin: 0;
  text-transform: none;
  font-size: clamp(1.7rem, 3.5vw, 2.8rem);
  letter-spacing: 0;
  color: var(--accent-2);
  font-weight: 800;
  font-family: var(--heading-font);
}

h1 {
  margin: 0.2rem 0;
  font-family: var(--heading-font);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.panel,
.quiz,
.results {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(26, 36, 48, 0.08);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.accessibility-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 10px;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--access-bar-height, 50px);
  min-height: 50px;
  overflow: hidden;
  white-space: normal;
}

.floating-access {
  position: fixed;
  top: var(--access-top);
  right: var(--access-gap);
  z-index: 36;
}

.floating-account-menu {
  position: fixed;
  top: var(--access-top);
  left: max(8px, env(safe-area-inset-left));
  z-index: 39;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: flex-start;
}

.account-menu-fab {
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.account-menu-panel {
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
  background: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  display: grid;
  gap: 0.42rem;
}

.account-menu-panel button {
  width: 100%;
  text-align: left;
}

.access-fab {
  position: fixed;
  top: var(--access-top);
  right: var(--access-gap);
  width: var(--access-fab-size);
  height: var(--access-fab-size);
  display: grid;
  place-items: center;
  border-radius: 999px;
  padding: 0;
  background: linear-gradient(135deg, #202837, #3d4f68);
  z-index: 38;
}

.access-fab-icon {
  width: 45px;
  height: 45px;
  object-fit: contain;
  display: block;
}

.floating-access .accessibility-panel.access-collapsed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-12px);
}

.floating-access .accessibility-panel {
  position: fixed;
  top: max(0px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: calc(var(--access-gap) + var(--access-fab-size) + 10px);
  min-width: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease, height 0.18s ease;
  z-index: 37;
}

.access-title {
  margin: 0;
  font-weight: 800;
  font-size: 14px;
  flex: 0 0 auto;
}

.access-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px 8px;
  align-items: center;
  align-content: flex-start;
  flex: 1;
  min-width: 0;
}

.access-btn {
  padding: 6px 10px;
  border-radius: 10px;
  flex: 0 0 auto;
}

.access-readout {
  font-weight: 700;
  min-width: 3.2rem;
  text-align: center;
  flex: 0 0 auto;
}

.access-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 9px;
  background: #fff;
  font-weight: 600;
  flex: 0 0 auto;
}

.access-toggle input[type='checkbox'] {
  width: auto;
}

.access-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 8px;
  background: #fff;
  font-weight: 600;
  flex: 0 0 auto;
}

.access-select select {
  width: auto;
  min-width: 108px;
  padding: 5px 7px;
  border-radius: 8px;
}

.access-select input[type='range'] {
  width: 120px;
}

.floating-access button,
.floating-access select,
.floating-access input,
.floating-access label,
.floating-access .access-readout,
.floating-access .access-title {
  font-size: 14px !important;
  line-height: 1.2;
}

.reading-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}

.marking-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.marking-overlay-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  box-shadow: 0 10px 24px rgba(26, 36, 48, 0.18);
  max-width: min(560px, 92vw);
  text-align: center;
}

.marking-overlay-card p {
  margin: 0;
  font-weight: 700;
  color: var(--ink);
}

body.high-contrast .marking-overlay {
  background: rgba(0, 0, 0, 0.78);
}

body.high-contrast .marking-overlay-card {
  background: #000;
  border-color: #8fff63;
}

body.high-contrast .marking-overlay-card p {
  color: #fff35c;
}

label {
  font-weight: 700;
  font-size: 0.95rem;
}

select,
textarea,
button {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 12px;
}

select,
input,
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
}

button {
  border: 0;
  background: linear-gradient(135deg, var(--accent), #ff965f);
  color: #fff;
  font-weight: 700;
  padding: 0.72rem 1rem;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary {
  background: linear-gradient(135deg, #2d6cdf, #5e8fea);
}

.purple-print {
  background: linear-gradient(135deg, #6d28d9, #9333ea);
}

.button-icon {
  margin-right: 0.35rem;
}

.status {
  margin: 0.7rem 0 0;
  min-height: 1.2rem;
  color: var(--muted);
}

.student-banner {
  margin: 0;
  font-weight: 700;
}

#streakLine {
  margin: 0.3rem 0 0;
  font-weight: 700;
  color: var(--ok);
}

.auth-toggle {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.auth-toggle button.active {
  outline: 2px solid rgba(24, 176, 184, 0.45);
}

.auth-form {
  margin-top: 0.35rem;
}

.account-menu-title {
  margin: 0 0 0.55rem;
}

.account-menu-bar {
  margin-top: 0.3rem;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, #eef4ff, #f8fbff);
}

.account-menu-bar button {
  flex: 1 1 180px;
}

#accountJoinClassWrap {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

#accountJoinClassWrap h3 {
  margin: 0 0 0.45rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.dashboard-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem;
  background: #fff;
}

.dashboard-card h3 {
  margin: 0 0 0.55rem;
}

.mini-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem;
  margin-top: 0.55rem;
  background: #fff;
}

.mini-card p {
  margin: 0.2rem 0;
  color: var(--muted);
}

.mini-card .actions {
  margin-top: 0.5rem;
}

.teacher-class-card {
  cursor: pointer;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem;
  background: #fff;
}

.stat-card .label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-card .value {
  margin: 0.2rem 0 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
}

.hidden {
  display: none;
}

.question-card,
.result-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem;
  margin-top: 0.9rem;
  background: #fff;
}

.meta {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.meta span {
  background: #f5f8fc;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

h3 {
  margin: 0.2rem 0 0.6rem;
  font-size: 1.05rem;
}

.question-text {
  margin: 0.2rem 0 0.6rem;
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.45;
}

.question-figure-wrap {
  margin: 0.35rem 0 0.7rem;
}

.question-figure-wrap p {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 700;
}

.question-figure {
  width: 100%;
  max-width: 620px;
  max-height: 440px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.diagram-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  margin-top: 0.8rem;
  background: #f9fcff;
}

.diagram-title {
  margin: 0 0 0.55rem;
  font-weight: 700;
  color: var(--ink);
}

.diagram-type-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.diagram-type-row label {
  font-size: 0.9rem;
}

.diagram-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.palette-item {
  border: 1px dashed #6a7f97;
  border-radius: 10px;
  background: #fff;
  color: #27425f;
  font-weight: 700;
  padding: 0.4rem 0.55rem;
  cursor: grab;
  user-select: none;
}

.diagram-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.diagram-font-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 0.9rem;
}

.diagram-font-control input[type='range'] {
  width: 130px;
}

.diagram-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  min-height: 420px;
  max-height: 84vh;
  border: 2px dashed #9fb4cb;
  border-radius: 10px;
  background: #fff;
  touch-action: none;
}

.diagram-item-body {
  cursor: move;
}

.diagram-handle {
  cursor: grab;
}

.diagram-move-indicator {
  cursor: move;
}

.diagram-resize-handle {
  cursor: nwse-resize;
}

.diagram-note {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.diagram-preview-wrap {
  margin: 0.55rem 0 0.3rem;
}

.diagram-preview {
  width: 100%;
  max-width: 540px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.actions {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.video-modal-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(940px, 94vw);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.video-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.video-modal-header h3 {
  margin: 0;
}

.video-modal-frame-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.video-modal-frame-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.class-report-dialog {
  width: min(1160px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.class-report-actions {
  margin: 0;
}

.users-dialog {
  width: min(860px, 94vw);
  max-height: 86vh;
  overflow: auto;
}

.class-report-table-wrap {
  margin-top: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 64vh;
  background: #fff;
}

.score-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.score-table th,
.score-table td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  font-size: 0.92rem;
  text-align: center;
  vertical-align: top;
  white-space: nowrap;
}

.score-table thead th {
  position: sticky;
  top: 0;
  background: #f4f8ff;
  z-index: 1;
}

.score-table th:first-child,
.score-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  background: #fff;
  min-width: 200px;
}

.score-table thead th:first-child {
  z-index: 3;
  background: #eef4ff;
}

.score-table th:last-child,
.score-table td:last-child {
  font-weight: 700;
}

.score-table small {
  display: block;
  margin-top: 0.15rem;
  font-weight: 600;
  color: var(--muted);
}

body.high-contrast .score-table thead th,
body.high-contrast .score-table th:first-child,
body.high-contrast .score-table td:first-child {
  background: #000 !important;
}

body.high-contrast .account-menu-panel {
  background: #000;
  border-color: #8fff63;
}

.result-top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.result-top h2 {
  margin: 0;
}

#scoreLine {
  margin: 0;
  font-weight: 800;
}

.feedback {
  margin: 0.55rem 0 0;
  color: var(--ink);
}

.mark-chip {
  display: inline-block;
  margin-top: 0.4rem;
  font-weight: 800;
  color: var(--ok);
}

.pdf-export-host {
  position: fixed;
  left: -20000px;
  top: 0;
  width: 1120px;
  padding: 0;
  pointer-events: none;
  z-index: -1;
  background: #ffffff;
}

.pdf-export-sheet {
  width: 1080px;
  background: #ffffff;
  color: #1b2430;
  font-family: 'Space Grotesk', sans-serif;
  padding: 24px;
}

.pdf-export-summary,
.pdf-export-card {
  border: 1px solid #d8e1ec;
  border-radius: 12px;
  background: #ffffff;
  padding: 14px 16px;
}

.pdf-export-summary {
  margin-bottom: 12px;
}

.pdf-export-summary h2 {
  margin: 0 0 0.6rem;
  font-size: 1.35rem;
}

.pdf-export-summary p {
  margin: 0.2rem 0;
  line-height: 1.35;
  font-size: 0.96rem;
}

.pdf-export-card {
  margin-bottom: 12px;
}

.pdf-export-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.pdf-export-meta span {
  background: #f5f8fc;
  border: 1px solid #d8e1ec;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.82rem;
  color: #4d5c70;
}

.pdf-export-question {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  line-height: 1.45;
  font-weight: 400;
}

.pdf-export-label {
  margin: 0.45rem 0 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.pdf-export-image-wrap {
  margin: 0.45rem 0 0.2rem;
}

.pdf-export-image {
  display: block;
  width: 100%;
  max-width: 880px;
  border: 1px solid #d8e1ec;
  border-radius: 10px;
  background: #ffffff;
}

.pdf-export-awarded {
  margin: 0.5rem 0 0;
  font-weight: 800;
  color: #0f8f4f;
}

@media (pointer: coarse) {
  .palette-item {
    padding: 0.55rem 0.8rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    touch-action: manipulation;
  }

  .diagram-tools button,
  .diagram-font-control {
    min-height: 44px;
  }

  .diagram-note {
    font-size: 0.95rem;
  }
}

@media (max-width: 767px) and (pointer: coarse) {
  .floating-access {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .container {
    width: 94vw;
    margin-top: 1rem;
  }

  .diagram-canvas {
    min-height: 320px;
  }

  .floating-access .accessibility-panel {
    left: 6px;
    right: calc(var(--access-gap) + var(--access-fab-size) + 6px);
    border-radius: 10px;
  }

  .floating-account-menu {
    left: 6px;
  }

  .account-menu-panel {
    min-width: 176px;
  }

  .accessibility-panel {
    padding: 0 6px;
    gap: 6px;
  }

  .access-title {
    display: none;
  }

  .dashboard-grid,
  .profile-stats {
    grid-template-columns: 1fr;
  }

  .class-report-dialog {
    width: 98vw;
    max-height: 92vh;
    padding: 0.6rem;
  }

  .users-dialog {
    width: 96vw;
  }

  .class-report-table-wrap {
    max-height: 68vh;
  }

  .score-table th,
  .score-table td {
    padding: 0.35rem 0.42rem;
    font-size: 0.84rem;
  }

  .score-table th:first-child,
  .score-table td:first-child {
    min-width: 155px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .no-print,
  .bg-shape {
    display: none !important;
  }

  .container {
    width: 100%;
    margin: 0;
  }

  .results,
  .result-card {
    box-shadow: none;
    border-color: #bbb;
  }
}
