:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f7f7f5;
  color: #1f2328;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

.app {
  min-height: 100vh;
}

.upload-screen {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 30px;
  place-items: center;
  padding: 20px;
}

.upload-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: #1f2328;
}

.brand-mark {
  width: 64px;
  height: 64px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(31, 35, 40, 0.08);
}

.brand-mark svg {
  width: 46px;
  height: 46px;
  overflow: visible;
}

.cap-top {
  fill: #1f2328;
}

.cap-band {
  fill: #0f766e;
}

.cap-tassel {
  fill: none;
  stroke: #b42318;
  stroke-linecap: round;
  stroke-width: 4;
}

.cap-tassel-dot {
  fill: #b42318;
}

.brand-name {
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
}

.upload-button {
  position: relative;
  width: min(220px, 72vw);
  aspect-ratio: 3 / 1;
  display: inline-grid;
  place-items: center;
  border: 1px solid #1f2328;
  border-radius: 8px;
  background: #ffffff;
  color: #1f2328;
  font-size: 18px;
  font-weight: 650;
  cursor: pointer;
}

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

.upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.preview-screen {
  position: fixed;
  inset: 0;
  background: #111111;
  overflow: hidden;
}

.viewer-toolbar {
  position: fixed;
  z-index: 2;
  top: auto;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-button {
  min-width: 56px;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: rgba(17, 17, 17, 0.68);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.toolbar-button:hover {
  background: rgba(17, 17, 17, 0.84);
}

.error-legend {
  position: fixed;
  z-index: 2;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: rgba(17, 17, 17, 0.62);
  color: #ffffff;
  font-size: 12px;
  font-weight: 650;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.legend-swatch.fresh {
  background: #d1242f;
}

.legend-swatch.consequence {
  background: #8250df;
}

.viewer {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  overscroll-behavior: contain;
  background: #111111;
  touch-action: none;
  --zoom: 1;
}

.document-content {
  position: relative;
  width: calc(var(--base-width, 100vw) * var(--zoom));
  margin: auto;
}

.image-document {
  height: calc(var(--base-height, 100vh) * var(--zoom));
}

.pdf-document {
  display: grid;
  gap: calc(18px * var(--zoom));
  align-content: start;
  padding: calc(18px * var(--zoom)) 0;
}

.document-page {
  position: relative;
  width: 100%;
  aspect-ratio: var(--page-ratio, 1 / 1.414);
  overflow: hidden;
  background: #ffffff;
}

.document-content img,
.pdf-page-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.document-content img {
  filter: none;
  opacity: 1;
  mix-blend-mode: normal;
  object-fit: contain;
  object-position: top center;
}

.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: transparent;
  filter: none;
  opacity: 1;
  mix-blend-mode: normal;
  pointer-events: none;
  --annotation-ink: #d1242f;
}

.annotation-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  filter: none;
  opacity: 1;
  mix-blend-mode: normal;
  overflow: visible;
}

.writing-zone-debug-layer {
  pointer-events: none;
  mix-blend-mode: multiply;
}

.writing-zone-debug {
  fill: rgba(0, 168, 204, 0.12);
  stroke: rgba(0, 123, 150, 0.82);
  stroke-dasharray: 7 5;
  stroke-linejoin: round;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.writing-zone-debug-label {
  fill: rgba(0, 88, 112, 0.9);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-linejoin: round;
  stroke-width: 2.5px;
  vector-effect: non-scaling-stroke;
}

.text-contour-debug-layer {
  pointer-events: none;
}

.no-no-zone-debug {
  fill: rgba(255, 64, 96, 0.055);
  stroke: rgba(255, 64, 96, 0.82);
  stroke-dasharray: 4 3;
  stroke-linejoin: round;
  stroke-width: 1.15;
  vector-effect: non-scaling-stroke;
}

.no-no-zone-debug-label {
  fill: rgba(190, 20, 54, 0.95);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 800;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-linejoin: round;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

.text-region-polygon-debug {
  fill: rgba(255, 214, 10, 0.05);
  stroke: rgba(255, 214, 10, 0.72);
  stroke-dasharray: 5 4;
  stroke-linejoin: round;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.text-contour-debug {
  fill: rgba(57, 255, 20, 0.035);
  stroke: rgba(57, 255, 20, 0.72);
  stroke-linejoin: round;
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.teacher-writing-footprint-debug {
  fill: transparent;
  opacity: 0.58;
  pointer-events: none;
  stroke: rgba(0, 132, 255, 0.62);
  stroke-dasharray: 2 4;
  stroke-linejoin: round;
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.text-contour-debug-label {
  fill: rgb(32, 180, 20);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 800;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-linejoin: round;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

.annotation-pen-mark,
.annotation-slash,
.annotation-connector,
.annotation-association-line {
  fill: none;
  stroke: var(--annotation-ink, #d1242f);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.annotation-pen-mark {
  stroke-width: 2.7;
}

.annotation-slash {
  stroke-width: 3.2;
}

.annotation-arrow {
  fill: none;
  stroke: var(--annotation-ink, #d1242f);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.annotation-ink-echo {
  opacity: 0.62;
}

.annotation-connector {
  opacity: 0.88;
  stroke-width: 2.4;
}

.annotation-association-line {
  opacity: 0.7;
  stroke-dasharray: 8 7;
  stroke-width: 1.8;
}

.annotation-handwriting {
  position: absolute;
  padding: 2px 5px;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: var(--annotation-ink, #d1242f);
  font-family: "Bradley Hand", "Comic Sans MS", "Segoe Print", "Marker Felt", cursive;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: 0;
  line-height: 1.12;
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.8),
    0 0 0.25px currentColor;
  transform: rotate(var(--rotation, -1deg));
  transform-origin: left center;
  white-space: normal;
  overflow-wrap: anywhere;
}

.annotation-inline-correction {
  display: flex;
  align-items: end;
  overflow: visible;
  padding: 0 3px;
  line-height: 1;
  white-space: nowrap;
  overflow-wrap: normal;
}

.annotation-stacked-correction {
  display: block;
  padding: 4px 6px;
  line-height: 1.16;
  white-space: normal;
}

.annotation-stacked-correction span:not(.annotation-note-index) {
  white-space: nowrap;
}

.handwritten-exponent {
  position: relative;
  top: -0.42em;
  font-size: 0.62em;
  line-height: 0;
}

.annotation-handwriting mjx-container {
  color: inherit;
}

.annotation-handwriting .error-line {
  margin: 0;
  padding: 0;
  border: 0;
}

.annotation-note-index {
  font-size: 0.88em;
  font-weight: 800;
}

.annotation-target,
.annotation-callout {
  position: absolute;
}

.annotation-target {
  min-width: 28px;
  min-height: 22px;
}

.annotation-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--annotation-ink, #d1242f);
}

.annotation-corner.top-left {
  top: 0;
  left: 0;
  border-top: 3px solid;
  border-left: 3px solid;
}

.annotation-corner.top-right {
  top: 0;
  right: 0;
  border-top: 3px solid;
  border-right: 3px solid;
}

.annotation-corner.bottom-left {
  bottom: 0;
  left: 0;
  border-bottom: 3px solid;
  border-left: 3px solid;
}

.annotation-corner.bottom-right {
  right: 0;
  bottom: 0;
  border-right: 3px solid;
  border-bottom: 3px solid;
}

.annotation-callout {
  display: grid;
  align-content: start;
  padding: 10px 12px;
  overflow: auto;
  border: 2px solid var(--annotation-ink, #d1242f);
  border-radius: 6px;
  background: #ffffff;
  color: #1f2328;
  font-size: clamp(12px, 1.05vw, 15px);
  line-height: 1.38;
}

.annotation-callout-message {
  overflow-wrap: anywhere;
}

.mark-panel {
  position: fixed;
  z-index: 3;
  right: 16px;
  bottom: 16px;
  width: min(520px, calc(100vw - 32px));
  max-height: min(42vh, 360px);
  padding: 42px 16px 16px;
  overflow: auto;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: none;
  color: #1f2328;
}

.close-mark-panel {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #ffffff;
  color: #1f2328;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.mark-status {
  margin-bottom: 12px;
  color: #57606a;
  font-size: 13px;
  font-weight: 700;
}

.mark-response {
  max-width: 980px;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.55;
}

.error-line {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eaeef2;
}

.unsupported-file {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  width: min(320px, calc(100vw - 40px));
  min-height: 150px;
  padding: 20px;
  border-radius: 8px;
  background: #ffffff;
  color: #1f2328;
  text-align: center;
}

.unsupported-file span {
  color: #57606a;
  font-size: 14px;
}

.drag-over .upload-screen {
  background: #eceff3;
}

@media (max-width: 760px) {
  .upload-screen {
    gap: 24px;
  }

  .upload-brand {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
  }

  .brand-mark svg {
    width: 42px;
    height: 42px;
  }

  .upload-button {
    width: min(190px, 74vw);
  }

  .viewer-toolbar {
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
  }

  .error-legend {
    max-width: calc(100vw - 96px);
    gap: 5px;
    padding: 0 8px;
    font-size: 11px;
  }
}
