:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9e0e7;
  --text: #1d2733;
  --muted: #607080;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --danger: #c2410c;
  --good: #15803d;
  --bad: #b91c1c;
  --shadow: 0 10px 30px rgba(23, 36, 48, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  padding: 10px 14px;
}

button:hover {
  background: var(--brand-dark);
}

button:disabled {
  background: #e8eef2;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.58;
}

button:disabled:hover {
  background: #e8eef2;
}

button.secondary {
  background: #e8eef2;
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

button.ghost {
  background: transparent;
  color: var(--brand);
  padding: 6px 8px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px 12px;
  color: var(--text);
}

textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 20px;
}

.login-brand img,
.brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.muted {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  margin: 16px 0;
}

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  padding: 12px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tab {
  background: #e6ecef;
  color: var(--text);
}

.tab.active {
  background: var(--brand);
  color: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.replay-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.replay-group {
  margin-bottom: 14px;
}

.replay-list {
  display: grid;
  gap: 10px;
}

.replay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.slide-viewer {
  display: grid;
  gap: 14px;
  touch-action: pan-y pinch-zoom;
}

.slide-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pdf-viewer {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: 100%;
  min-height: 70vh;
  overflow: visible;
  touch-action: pan-y pinch-zoom;
}

.pdf-page-wrap {
  position: relative;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(23, 36, 48, 0.08);
  touch-action: pan-y pinch-zoom;
  pointer-events: none;
}

.pdf-page {
  display: block;
  max-width: 100%;
  height: auto;
  pointer-events: none;
}

.pdf-watermark {
  position: absolute;
  inset: -12%;
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  align-content: space-around;
  gap: 42px 24px;
  pointer-events: none;
  transform: rotate(-45deg);
  transform-origin: center;
  color: rgba(29, 39, 51, 0.15);
  font-weight: 700;
  font-size: clamp(18px, 3.4vw, 34px);
  line-height: 1.5;
  text-align: center;
  white-space: pre-line;
  z-index: 1;
  user-select: none;
}

.pdf-frame {
  width: 100%;
  height: min(78vh, 900px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h3,
.panel h2,
.panel h3 {
  margin: 0 0 8px;
}

.meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #ecfdf5;
  color: #166534;
  padding: 3px 9px;
  font-size: 13px;
}

.pill.closed {
  background: #fef2f2;
  color: #991b1b;
}

.exam-layout {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
}

.question-nav {
  position: sticky;
  top: 82px;
  align-self: start;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: calc(100vh - 98px);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(8px);
  z-index: 4;
}

.question-nav button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  text-align: center;
  min-width: 40px;
  height: 38px;
  padding: 0;
  font-weight: 700;
}

.question-nav button.done {
  border-color: var(--brand);
  color: var(--brand);
}

.question-nav .nav-submit {
  height: auto;
  min-height: 38px;
  padding: 6px 4px;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
}

.question {
  scroll-margin-top: 96px;
  margin-bottom: 16px;
}

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.option {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
}

.option input {
  width: auto;
  margin-top: 5px;
}

.option.correct {
  border-color: var(--good);
  background: #f0fdf4;
}

.option.wrong {
  border-color: var(--bad);
  background: #fef2f2;
}

.formula {
  margin: 10px 0;
  color: #243447;
}

.question img,
.explain img {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.rich-image {
  margin: 12px 0;
}

.rich-image figcaption {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.option .rich-image {
  margin: 6px 0 0;
}

.option .rich-image img {
  max-height: 180px;
  object-fit: contain;
}

.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 360px;
  touch-action: none;
}

.canvas-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding: 10px;
}

.upload-tools {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  background: #e8eef2;
  color: var(--text);
  cursor: pointer;
  padding: 10px 14px;
}

.upload-button:hover {
  background: #dbe5eb;
}

.upload-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.upload-preview.empty {
  background: #f8fafc;
}

.upload-preview p {
  margin: 0 0 8px;
}

.upload-preview.empty p {
  margin-bottom: 0;
}

.upload-preview img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #fff;
}

.hidden {
  display: none !important;
}

.result-good {
  color: var(--good);
  font-weight: 700;
}

.result-bad {
  color: var(--bad);
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #eef3f5;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.error {
  color: var(--bad);
  margin-top: 10px;
}

.success {
  color: var(--good);
  margin-top: 10px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions button {
  padding: 7px 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.segmented button {
  padding: 7px 10px;
}

.segmented button.active {
  background: var(--brand);
  color: #fff;
}

.admin-list {
  display: grid;
  gap: 16px;
}

.admin-exam {
  display: grid;
  gap: 14px;
}

.admin-exam-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  list-style: none;
}

.admin-exam-summary::-webkit-details-marker {
  display: none;
}

.admin-exam-summary h3 {
  margin: 0 0 8px;
}

.admin-exam-body {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.admin-exam-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-exam-head .card-actions {
  margin-top: 0;
}

.admin-stats {
  font-size: 15px;
}

.admin-table {
  margin-top: 2px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .main {
    padding: 14px;
  }

  .exam-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

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

  .question-nav {
    position: sticky;
    top: 126px;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 38px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px;
    margin: -4px 0 4px;
  }

  .question-nav button {
    min-width: 38px;
    height: 34px;
  }

  .question-nav .nav-submit {
    min-width: 54px;
    padding: 0 8px;
  }

  .question {
    scroll-margin-top: 178px;
  }

  .admin-exam-head {
    flex-direction: column;
  }

  .replay-row {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
