:root {
  color-scheme: light;
  --paper: #fff3f6;
  --card: #fffafb;
  --ink: #2e2529;
  --muted: #8d737b;
  --line: #ead5dc;
  --green: #a75a75;
  --green-soft: #f8e3ea;
  --orange: #ca7890;
  --red: #b94862;
  --rose-deep: #91415d;
  --rose-soft: #f7e1e9;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, #f4cbd7 0, transparent 34rem),
    radial-gradient(circle at 8% 12%, #fff8e9 0, transparent 24rem),
    var(--paper);
}

body::before,
body::after {
  display: none;
  position: fixed;
  z-index: -1;
  width: 360px;
  height: 360px;
  background: url("/hello-kitty.webp") center / contain no-repeat;
  content: "";
  opacity: 0.08;
  pointer-events: none;
}

body.has-kitty-watermark::before,
body.has-kitty-watermark::after {
  display: block;
}

body::before {
  top: 26px;
  right: max(24px, calc((100vw - 980px) / 2));
  transform: rotate(-8deg);
}

body::after {
  bottom: 36px;
  left: max(14px, calc((100vw - 1020px) / 2));
  width: 260px;
  height: 260px;
  opacity: 0.055;
  transform: rotate(12deg);
}

button,
input,
textarea {
  font: inherit;
}

.page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 64px 0 80px;
}

.hero {
  margin-bottom: 48px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(42px, 9vw, 72px);
  font-weight: 500;
  line-height: 1.04;
  letter-spacing: -0.04em;
}

.intro {
  max-width: 580px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.workspace-tabs {
  position: sticky;
  z-index: 10;
  top: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: -18px 0 18px;
  padding: 10px 0;
  backdrop-filter: blur(14px);
}

.tab-button {
  display: grid;
  gap: 4px;
  min-height: 74px;
  align-content: center;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: rgb(255 250 251 / 84%);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 8px 24px rgb(120 54 78 / 5%);
}

.tab-button strong,
.tab-button span {
  display: block;
}

.tab-button strong {
  font-size: 14px;
}

.tab-button span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.tab-button.active {
  color: white;
  border-color: var(--green);
  background: linear-gradient(135deg, var(--green), #d88da0);
}

.tab-button.active span {
  color: rgb(255 255 255 / 76%);
}

.workspace-panel {
  display: none;
}

.workspace-panel.active {
  display: block;
}

.card {
  margin-top: 20px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  box-shadow: 0 12px 40px rgb(120 54 78 / 7%);
}

.section-heading {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.section-heading.compact {
  align-items: center;
  margin-bottom: 16px;
}

.step {
  display: grid;
  flex: 0 0 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h2 {
  margin: 1px 0 5px;
  font-size: 20px;
}

.section-heading p,
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

label {
  color: #525850;
  font-size: 13px;
  font-weight: 650;
}

.full {
  grid-column: 1 / -1;
}

input,
textarea {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  color: var(--ink);
  background: white;
}

input {
  height: 46px;
  padding: 0 14px;
}

textarea {
  padding: 14px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(23 79 59 / 10%);
}

.hint {
  margin-top: 10px;
}

.ai-note {
  margin: 18px 0 0;
  padding: 13px 15px;
  border-radius: 10px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 13px;
  line-height: 1.6;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.upload-button {
  display: flex;
  min-height: 86px;
  gap: 14px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: white;
  text-align: left;
  cursor: pointer;
}

.upload-button.primary {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

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

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

.button-icon {
  font-size: 28px;
  font-weight: 300;
}

.upload-button strong,
.upload-button small {
  display: block;
}

.upload-button small {
  margin-top: 4px;
  color: inherit;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.7;
}

.empty-state {
  margin-top: 18px;
  padding: 28px;
  border: 1px dashed #c9cbc3;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.history-card {
  margin-bottom: 20px;
}

.result-empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 42px 28px;
  border-style: dashed;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0, #f9e1e8 0, transparent 18rem),
    color-mix(in srgb, var(--card) 94%, transparent);
}

.empty-illustration {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 18px;
  color: var(--rose-deep);
  background: var(--rose-soft);
  font-size: 26px;
  font-weight: 800;
}

.result-empty h2,
.result-empty p {
  margin: 0;
}

.result-empty p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.empty-actions button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--rose-deep);
  background: white;
  cursor: pointer;
}

.empty-actions button:first-child {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.ghost-button {
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--green);
  background: white;
  cursor: pointer;
}

.history-list,
.ai-log-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border: 1px solid #e7e6df;
  border-radius: 13px;
  background: white;
}

.history-item strong,
.history-item span,
.history-item small {
  display: block;
}

.history-item strong {
  font-size: 14px;
}

.history-item span {
  margin-top: 5px;
  color: #555c55;
  font-size: 12px;
  line-height: 1.5;
}

.history-item small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.history-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
}

.history-actions button {
  padding: 8px 11px;
  border: 0;
  border-radius: 9px;
  color: white;
  background: var(--green);
  cursor: pointer;
}

.preview-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.preview-item {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  background: #e8e8e2;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}

.preview-item img:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: -3px;
}

.page-number {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  color: white;
  background: rgb(20 26 22 / 75%);
  font-size: 11px;
}

.remove-image {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: white;
  background: rgb(20 26 22 / 75%);
  cursor: pointer;
}

.submit-button {
  width: 100%;
  height: 58px;
  margin-top: 20px;
  border: 0;
  border-radius: 15px;
  color: white;
  background: var(--orange);
  font-size: 17px;
  font-weight: 750;
  cursor: pointer;
}

.submit-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.message {
  min-height: 22px;
  margin: 10px 4px 0;
  color: var(--red);
  font-size: 13px;
}

.hidden {
  display: none;
}

.progress-track {
  overflow: hidden;
  height: 10px;
  border-radius: 10px;
  background: #e2e3dc;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 300ms ease;
}

.progress-bar.failed {
  background: var(--red);
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.summary-item {
  padding: 13px 14px;
  border-radius: 12px;
  background: #f0f1ec;
}

.summary-item strong,
.summary-item span {
  display: block;
}

.summary-item strong {
  font-size: 20px;
}

.summary-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.summary-item.warning {
  color: #88520d;
  background: #fff0d6;
}

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

.result-item {
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--line);
  border-left: 5px solid #9ba19a;
  border-radius: 15px;
  background: white;
}

.result-item.correct {
  border-left-color: var(--green);
}

.result-item.incorrect {
  border-left-color: var(--red);
}

.result-item.partial,
.result-item.review {
  border-left-color: #d3902f;
}

.result-item-header,
.question-meta,
.status-group {
  display: flex;
  align-items: center;
}

.result-item-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.question-meta,
.status-group {
  gap: 9px;
}

.question-meta {
  min-width: 0;
  flex-wrap: wrap;
}

.question-meta > span:last-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.question-number {
  overflow: hidden;
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 9px;
  color: white;
  background: var(--green);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-section-title {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 11px;
  color: #3f463f;
  background: #f4f5f0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.question-score {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.question-content h3 {
  margin: 0;
  white-space: pre-line;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.75;
}

.question-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 13px;
}

.question-option {
  padding: 10px 12px;
  border: 1px solid #e5e5de;
  border-radius: 9px;
  color: #4d534d;
  background: #fafaf7;
  font-size: 13px;
  line-height: 1.5;
}

.question-source {
  display: flex;
  width: 100%;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  padding: 9px;
  border: 1px solid #e0e1da;
  border-radius: 11px;
  color: var(--ink);
  background: #f7f7f3;
  text-align: left;
  cursor: zoom-in;
}

.question-source img {
  width: 72px;
  height: 54px;
  border-radius: 7px;
  object-fit: cover;
  background: #e5e5df;
}

.question-source strong,
.question-source small {
  display: block;
}

.question-source strong {
  font-size: 13px;
}

.question-source small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.answer-box {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f7f7f3;
}

.answer-box span,
.answer-box strong {
  display: block;
}

.answer-box span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.answer-box strong {
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.5;
}

.answer-box.correct {
  border-color: #bfd5c5;
  color: var(--green);
  background: #eff7f1;
}

.answer-box.incorrect {
  border-color: #ebc3bd;
  color: var(--red);
  background: #fff2f0;
}

.answer-box.review {
  border-color: #ead09d;
  color: #805416;
  background: #fff8e9;
}

.result-explanation {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #ecece6;
  border-radius: 12px;
  background: #fffdfb;
}

.result-explanation strong {
  color: var(--green);
  font-size: 12px;
}

.result-explanation p {
  margin: 6px 0 0;
  color: #596059;
  font-size: 13px;
  line-height: 1.65;
}

.result-explanation.incorrect,
.result-explanation.partial,
.result-explanation.review,
.result-explanation.ungraded {
  border-color: #f1cad5;
  background: #fff5f8;
}

.review-notice {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding: 11px 13px;
  border-radius: 10px;
  color: #754a0d;
  background: #fff0d6;
  font-size: 12px;
  line-height: 1.55;
}

.review-notice strong {
  flex: 0 0 auto;
}

.status {
  padding: 5px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 750;
}

.status.correct {
  color: var(--green);
  background: var(--green-soft);
}

.status.incorrect {
  color: var(--red);
  background: #f6dfdb;
}

.status.partial,
.status.review {
  color: #805416;
  background: #fff0d6;
}

.status.ungraded {
  color: #616761;
  background: #e8e9e5;
}

.ai-log-item {
  border: 1px solid #e1e1da;
  border-radius: 12px;
  background: white;
}

.ai-log-item summary {
  cursor: pointer;
  padding: 13px 14px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.ai-log-item pre {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  padding: 14px;
  border-top: 1px solid #ecece6;
  color: #353a35;
  background: #fafaf7;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.viewer-open {
  overflow: hidden;
}

.image-viewer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 16px;
  background: rgb(15 18 16 / 92%);
}

.image-viewer.hidden {
  display: none;
}

.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 0 0 12px;
  color: white;
}

.viewer-toolbar > span {
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-actions {
  display: flex;
  gap: 7px;
}

.viewer-actions button {
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 9px;
  color: white;
  background: rgb(255 255 255 / 10%);
  cursor: pointer;
}

.viewer-canvas {
  overflow: auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #202421;
}

.viewer-canvas img {
  max-width: 92%;
  max-height: 92%;
  transform-origin: center;
  transition: transform 150ms ease;
  user-select: none;
  -webkit-user-drag: none;
}

.camera-modal {
  position: fixed;
  z-index: 110;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(49 28 36 / 82%);
}

.camera-modal.hidden {
  display: none;
}

.camera-panel {
  width: min(720px, 100%);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 22px;
  background: #1f171b;
  box-shadow: 0 24px 80px rgb(40 14 24 / 35%);
}

.camera-toolbar,
.camera-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
}

.camera-toolbar {
  justify-content: space-between;
  color: white;
}

.camera-toolbar strong,
.camera-toolbar span {
  display: block;
}

.camera-toolbar strong {
  font-size: 15px;
}

.camera-toolbar span {
  margin-top: 4px;
  color: rgb(255 255 255 / 72%);
  font-size: 12px;
}

.camera-toolbar button {
  width: 36px;
  height: 36px;
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 50%;
  color: white;
  background: rgb(255 255 255 / 10%);
  cursor: pointer;
}

.camera-stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  background: #0f0d0e;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 8%;
  border: 2px solid rgb(244 199 212 / 78%);
  border-radius: 18px;
  box-shadow:
    0 0 0 999px rgb(20 12 16 / 26%),
    inset 0 0 24px rgb(206 122 145 / 18%);
}

.scan-frame::before,
.scan-frame::after {
  position: absolute;
  left: 50%;
  width: 1px;
  height: 100%;
  background: linear-gradient(transparent, rgb(255 255 255 / 26%), transparent);
  content: "";
}

.scan-frame::after {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
}

.scan-frame span {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: #f4c7d4;
}

.scan-frame span:nth-child(1) {
  top: -2px;
  left: -2px;
  border-top: 5px solid;
  border-left: 5px solid;
  border-top-left-radius: 16px;
}

.scan-frame span:nth-child(2) {
  top: -2px;
  right: -2px;
  border-top: 5px solid;
  border-right: 5px solid;
  border-top-right-radius: 16px;
}

.scan-frame span:nth-child(3) {
  right: -2px;
  bottom: -2px;
  border-right: 5px solid;
  border-bottom: 5px solid;
  border-bottom-right-radius: 16px;
}

.scan-frame span:nth-child(4) {
  bottom: -2px;
  left: -2px;
  border-bottom: 5px solid;
  border-left: 5px solid;
  border-bottom-left-radius: 16px;
}

.camera-actions {
  justify-content: flex-end;
  background: #fff7fd;
}

.ghost-camera-button,
.capture-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  cursor: pointer;
}

.ghost-camera-button {
  border: 1px solid var(--line);
  color: var(--rose-deep);
  background: white;
}

.capture-button {
  border: 0;
  color: white;
  background: var(--green);
  font-weight: 750;
}

@media (max-width: 600px) {
  body::before {
    top: 14px;
    right: 10px;
    width: 190px;
    height: 190px;
    opacity: 0.075;
    transform: rotate(-8deg);
  }

  body::after {
    display: none !important;
  }

  .page {
    width: min(100% - 24px, 760px);
    padding-top: 32px;
  }

  .hero {
    margin-bottom: 26px;
    padding-right: 76px;
  }

  .intro {
    margin-top: 18px;
  }

  .card {
    padding: 20px;
  }

  .workspace-tabs {
    position: sticky;
    top: 0;
    display: flex;
    gap: 8px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .workspace-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-button {
    flex: 0 0 146px;
    min-height: auto;
    padding: 11px 12px;
  }

  #newPanel.active {
    display: flex;
    flex-direction: column;
  }

  .upload-card {
    order: 1;
  }

  .exam-info-card {
    order: 2;
  }

  #submitButton {
    order: 3;
  }

  #progressCard {
    order: 4;
  }

  .form-grid,
  .upload-actions {
    grid-template-columns: 1fr;
  }

  .preview-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .history-item,
  .history-actions {
    align-items: flex-start;
  }

  .history-item {
    flex-direction: column;
  }

  .question-options,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .result-item-header {
    align-items: flex-start;
  }

  .status-group {
    flex-direction: column-reverse;
    align-items: flex-end;
  }

  .image-viewer {
    padding: 10px;
  }

  .viewer-toolbar {
    align-items: flex-start;
  }

  .viewer-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .camera-modal {
    padding: 0;
  }

  .camera-panel {
    width: 100%;
    min-height: 100%;
    border-radius: 0;
  }

  .camera-stage {
    aspect-ratio: 3 / 4.5;
  }

  .camera-actions {
    justify-content: stretch;
  }

  .ghost-camera-button,
  .capture-button {
    flex: 1;
  }
}
