:root {
  color-scheme: light;
  --navy: #173454;
  --navy-deep: #102a47;
  --ink: #172b46;
  --muted: #6d7f96;
  --line: #dbe3ec;
  --line-strong: #c8d4e2;
  --canvas: #e9eef4;
  --soft: #f6f8fb;
  --blue: #1769e0;
  --blue-dark: #0d55c5;
  --green: #12a150;
  --green-soft: #eaf8f0;
  --red: #ef4444;
  --red-soft: #fff0f0;
  --amber: #e99400;
  --amber-soft: #fff7e7;
  --radius: 9px;
  --shadow: 0 16px 36px rgba(25, 52, 84, 0.12);
}

* { box-sizing: border-box; }

html, body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.trace-topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--navy-deep);
  color: #fff;
}

.trace-brand {
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .03em;
  text-decoration: none;
}

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d9e5f2;
  font-size: 12px;
  font-weight: 650;
}

.connection-state span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25d978;
  box-shadow: 0 0 0 3px rgba(37, 217, 120, .12);
}

.trace-workspace {
  display: grid;
  grid-template-columns: 310px minmax(460px, 1fr) 350px;
  min-height: calc(100vh - 56px);
  border-bottom: 1px solid var(--line);
}

.input-panel,
.inspector-panel {
  min-width: 0;
  background: #fff;
}

.input-panel {
  padding: 20px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.input-section + .input-section { margin-top: 26px; }

.input-section h2,
.preview-toolbar h2,
.inspector-header h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: -.01em;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.text-button {
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.trace-drop-zone {
  position: relative;
  min-height: 126px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border: 1px dashed #97b1ce;
  border-radius: var(--radius);
  background: #fbfdff;
  text-align: center;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.trace-drop-zone:hover,
.trace-drop-zone.is-dragging { border-color: var(--blue); background: #f3f7ff; }

.trace-drop-zone input,
.compact-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.trace-drop-zone svg {
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  fill: none;
  stroke: var(--navy);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.trace-drop-zone strong { font-size: 13px; }
.trace-drop-zone small { margin-top: 4px; color: var(--muted); font-size: 11px; }

.trace-file-list {
  display: grid;
  gap: 7px;
  max-height: 252px;
  margin: 10px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.trace-file-row {
  display: grid;
  grid-template-columns: 25px 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.trace-file-row.is-current { border-color: #82aceb; background: #f5f9ff; }
.trace-file-row[draggable="true"] { cursor: grab; }
.trace-file-row[draggable="true"]:active { cursor: grabbing; }
.trace-file-row.is-dragging { opacity: .45; }
.trace-file-row.is-drag-over { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(23, 105, 224, .12); }
.trace-file-number { color: var(--muted); font-size: 11px; font-weight: 800; }
.trace-file-thumb { width: 38px; height: 38px; border-radius: 3px; object-fit: cover; background: var(--soft); }
.trace-file-meta { min-width: 0; }
.trace-file-name { overflow: hidden; color: #29435f; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.trace-file-size { margin-top: 2px; color: var(--muted); font-size: 10px; }
.trace-file-actions { display: flex; }

.mini-button {
  width: 22px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.mini-button:hover { background: #eaf0f7; color: var(--ink); }

.answer-section > h2 { margin-bottom: 10px; }

.answer-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 7px 7px 0 0;
  overflow: hidden;
}

.answer-tab {
  min-height: 34px;
  padding: 0 4px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.answer-tab:last-child { border-right: 0; }
.answer-tab.is-active { background: #fff; color: var(--blue); box-shadow: inset 0 -2px var(--blue); }

.answer-panel { position: relative; }
.answer-panel textarea {
  display: block;
  width: 100%;
  min-height: 148px;
  padding: 12px 12px 28px;
  resize: vertical;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 7px 7px;
  outline: none;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.65;
}

.answer-panel textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(23, 105, 224, .1); }
.character-count { position: absolute; right: 10px; bottom: 8px; color: #8b99ab; font-size: 10px; }
.character-count b { font-weight: 600; }

.compact-upload {
  position: relative;
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 7px 7px;
  cursor: pointer;
}

.compact-upload:hover { background: #f8fbff; }
.compact-upload svg { width: 30px; height: 30px; fill: none; stroke: var(--blue); stroke-width: 1.5; }
.compact-upload span { display: grid; gap: 4px; }
.compact-upload strong { font-size: 12px; }
.compact-upload small { color: var(--muted); font-size: 10px; }
.answer-image-list { max-height: 220px; margin-bottom: 0; }
.answer-image-list:empty { display: none; }
.answer-image-list .trace-file-row { grid-template-columns: 18px 25px 38px minmax(0, 1fr) auto; }
.drag-handle { color: #8fa0b4; font-size: 15px; letter-spacing: -4px; user-select: none; }

.answer-preview-dialog {
  width: min(1000px, calc(100vw - 48px));
  max-width: none;
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(14, 34, 58, .3);
}

.answer-preview-dialog::backdrop { background: rgba(13, 27, 45, .68); }
.answer-preview-dialog header,
.answer-preview-dialog footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.answer-preview-dialog header { border-bottom: 1px solid var(--line); }
.answer-preview-dialog header div { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.answer-preview-dialog header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answer-preview-dialog header small { flex: none; color: var(--muted); }
.answer-preview-dialog button { min-height: 32px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; cursor: pointer; }
.answer-preview-dialog button:disabled { opacity: .38; cursor: default; }
#answer-preview-close { width: 32px; padding: 0; border: 0; font-size: 22px; }
.answer-preview-canvas { height: min(72vh, 820px); padding: 16px; overflow: auto; background: var(--canvas); text-align: center; }
.answer-preview-canvas img { max-width: 100%; height: auto; box-shadow: var(--shadow); }
.answer-preview-dialog footer { justify-content: center; gap: 10px; border-top: 1px solid var(--line); }

.trace-error {
  margin-top: 14px;
  padding: 10px 11px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  color: #9f2630;
  font-size: 11px;
  line-height: 1.5;
}

.trace-submit {
  width: 100%;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.trace-submit:hover { background: var(--blue-dark); transform: translateY(-1px); }
.trace-submit:disabled { cursor: wait; opacity: .72; transform: none; }
.trace-submit svg { width: 18px; height: 18px; fill: currentColor; }

.preview-panel { min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }

.preview-toolbar {
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.page-controls,
.zoom-controls { display: flex; align-items: center; }
.page-controls { gap: 8px; }
.page-controls span { min-width: 52px; color: var(--muted); font-size: 11px; text-align: center; }
.page-controls b { color: var(--ink); font-variant-numeric: tabular-nums; }
.zoom-controls { justify-content: flex-end; gap: 5px; }

.tool-button,
.fit-button {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: #425a75;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.tool-button { padding: 0; }
.tool-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tool-button:hover, .fit-button:hover { border-color: #8faed1; background: #f7faff; }
.tool-button:disabled { cursor: default; opacity: .38; }
#zoom-value { min-width: 46px; color: #40546c; font-size: 11px; font-weight: 750; text-align: center; }

.mark-controls {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-left: 5px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.mark-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #40546c;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.mark-toggle input { width: 14px; height: 14px; accent-color: var(--blue); }
.mark-toggle:has(input:disabled) { opacity: .45; }

.paper-viewport {
  position: relative;
  flex: 1;
  min-height: 560px;
  padding: 22px;
  overflow: auto;
}

.empty-preview {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}

.empty-preview svg { width: 54px; height: 54px; fill: none; stroke: #91a5ba; stroke-width: 1.3; }
.empty-preview h3 { margin: 18px 0 6px; color: #3d5570; font-size: 17px; }
.empty-preview p { max-width: 340px; margin: 0; font-size: 12px; line-height: 1.7; }

.paper-sheet {
  position: relative;
  width: 680px;
  margin: 0 auto;
  background: #fff;
  box-shadow: var(--shadow);
  transform-origin: top center;
}

.paper-sheet img { display: block; width: 100%; height: auto; }
.bbox-layer { position: absolute; inset: 0; pointer-events: none; }
.bbox-layer.is-hidden { display: none; }

.bbox-box {
  position: absolute;
  border: 2px dashed currentColor;
  background: color-mix(in srgb, currentColor 4%, transparent);
  color: var(--blue);
  pointer-events: auto;
  cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
}

.bbox-box:hover,
.bbox-box.is-selected { background: color-mix(in srgb, currentColor 9%, transparent); box-shadow: 0 0 0 2px #fff, 0 0 0 4px currentColor; }
.bbox-box.status-correct { color: var(--green); }
.bbox-box.status-incorrect { color: var(--red); }
.bbox-box.status-partial { color: var(--amber); }
.bbox-box.status-neutral { color: var(--blue); }

.bbox-question {
  z-index: 1;
  border-style: solid;
  color: #7048c8;
  background: color-mix(in srgb, currentColor 3%, transparent);
  pointer-events: none;
}

.bbox-answer { z-index: 2; }

.bbox-question-label {
  position: absolute;
  top: -2px;
  left: -2px;
  padding: 3px 7px;
  background: #7048c8;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 19px;
  white-space: nowrap;
}

.bbox-mark {
  position: absolute;
  top: -2px;
  right: -2px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 25px;
  padding: 3px 7px;
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.bbox-mark span { color: #fff; }
.status-correct .bbox-mark { background: var(--green); }
.status-incorrect .bbox-mark { background: var(--red); }
.status-partial .bbox-mark { background: var(--amber); }

.processing-mask {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: rgba(233, 238, 244, .92);
  color: var(--ink);
  text-align: center;
  z-index: 10;
}

.processing-mask[hidden] { display: none; }
.processing-mask small { color: var(--muted); font-size: 11px; }

.trace-spinner {
  width: 34px;
  height: 34px;
  margin-bottom: 5px;
  border: 3px solid #c8d7e7;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: trace-spin 760ms linear infinite;
}

@keyframes trace-spin { to { transform: rotate(360deg); } }

.inspector-panel {
  padding: 19px 18px;
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.inspector-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.inspector-header span { color: var(--muted); font-size: 10px; }

.detail-list { margin: 0; }
.detail-list > div {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 10px;
  min-height: 39px;
  align-items: center;
  border-bottom: 1px solid #e7edf3;
}

.detail-list dt { color: var(--muted); font-size: 11px; }
.detail-list dd { min-width: 0; margin: 0; overflow-wrap: anywhere; color: #29425e; font-size: 11px; font-weight: 650; }
.detail-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; }
.detail-status.correct { color: var(--green); }
.detail-status.incorrect { color: var(--red); }
.detail-status.partial { color: var(--amber); }

.inspector-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-top: 13px; border-bottom: 1px solid var(--line); }
.inspector-tab { min-height: 38px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; }
.inspector-tab.is-active { color: var(--blue); box-shadow: inset 0 -2px var(--blue); }

.inspector-content { padding-top: 10px; }
.item-table-head,
.item-row { display: grid; grid-template-columns: 1fr 1.15fr .8fr; align-items: center; }
.item-table-head { min-height: 32px; padding: 0 9px; border: 1px solid var(--line); background: var(--soft); color: var(--muted); font-size: 10px; font-weight: 700; }
.item-list { border: 1px solid var(--line); border-top: 0; }

.item-row {
  width: 100%;
  min-height: 42px;
  padding: 0 9px;
  border: 0;
  border-bottom: 1px solid #e9eef4;
  background: #fff;
  color: #29425e;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
}

.item-row:last-child { border-bottom: 0; }
.item-row:hover { background: #f7faff; }
.item-row.is-selected { background: #edf5ff; box-shadow: inset 3px 0 var(--blue); }
.item-row .correct { color: var(--green); font-weight: 800; }
.item-row .incorrect { color: var(--red); font-weight: 800; }
.item-row .partial { color: var(--amber); font-weight: 800; }
.empty-list { margin: 0; padding: 30px 12px; color: var(--muted); font-size: 11px; text-align: center; }

.json-content textarea {
  width: 100%;
  min-height: 310px;
  padding: 12px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: none;
  color: #27405b;
  background: #f8fafc;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  line-height: 1.55;
}

.json-content textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(23, 105, 224, .1); }
.apply-json-button { width: 100%; min-height: 36px; margin-top: 8px; border: 1px solid var(--blue); border-radius: 6px; background: #fff; color: var(--blue); font-size: 11px; font-weight: 750; cursor: pointer; }
.apply-json-button:hover { background: #f2f7ff; }

[hidden] { display: none !important; }

@media (max-width: 1180px) {
  .trace-workspace { grid-template-columns: 285px minmax(430px, 1fr); }
  .inspector-panel { grid-column: 1 / -1; border-top: 1px solid var(--line); border-left: 0; }
  .detail-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .inspector-content { max-width: 720px; }
}

@media (max-width: 760px) {
  .trace-topbar { height: 52px; padding: 0 14px; }
  .trace-brand { font-size: 17px; }
  .trace-workspace { display: block; }
  .input-panel, .inspector-panel { padding: 16px; border: 0; }
  .preview-toolbar { grid-template-columns: 1fr auto; padding: 10px 12px; }
  .preview-toolbar h2 { grid-row: 1; }
  .page-controls { justify-self: end; }
  .zoom-controls { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .mark-controls { margin-left: 0; }
  .paper-viewport { min-height: 520px; padding: 14px; }
  .detail-list { display: block; }
  .connection-state { font-size: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; }
}
