:root {
  color-scheme: light;
  --page: #eef0eb;
  --surface: #f8f9f5;
  --surface-raised: #fbfcf8;
  --surface-muted: #e5e8e1;
  --text: #20231f;
  --text-muted: #626860;
  --line: #cdd2c9;
  --line-strong: #aab1a6;
  --accent: #c8a91f;
  --accent-strong: #a88c0e;
  --accent-readable: #6d5a00;
  --accent-text: #1c190a;
  --danger: #a33a32;
  --danger-surface: #f5dfdc;
  --success: #397052;
  --canvas: #272a26;
  --radius: 10px;
  --header-height: 70px;
  --font-ui: "Microsoft YaHei UI", "Segoe UI", "PingFang SC", sans-serif;
  --font-number: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #171916;
    --surface: #1d201c;
    --surface-raised: #242722;
    --surface-muted: #2a2e28;
    --text: #eceee8;
    --text-muted: #a6ada2;
    --line: #383d35;
    --line-strong: #555d50;
    --accent: #d8bc42;
    --accent-strong: #e4ca57;
    --accent-readable: #e4ca57;
    --accent-text: #17160c;
    --danger: #e08078;
    --danger-surface: #402825;
    --success: #6eba8c;
    --canvas: #111310;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: var(--font-ui);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}

.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 20px;
}

.brand-block h1,
.brand-block p,
.panel-section h2,
.count-section h2,
.metric-section p,
.empty-state h2,
.empty-state p,
.loading-state h2,
.loading-state p {
  margin: 0;
}

.brand-block h1 {
  font-size: 18px;
  line-height: 1.25;
}

.brand-block p {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.local-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-light {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.workbench {
  height: calc(100dvh - var(--header-height));
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 260px;
  min-width: 0;
}

.control-panel,
.result-panel {
  min-width: 0;
  overflow-y: auto;
  background: var(--surface);
}

.control-panel {
  border-right: 1px solid var(--line);
}

.result-panel {
  border-left: 1px solid var(--line);
}

.panel-section,
.count-section,
.metric-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2,
.count-section h2 {
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 700;
}

.drop-zone {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 120ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--accent-strong);
  background: color-mix(in srgb, var(--surface-muted) 80%, var(--accent) 20%);
}

.drop-zone:active {
  transform: translateY(1px);
}

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

.drop-zone strong {
  font-size: 15px;
}

.drop-zone span,
.helper-text,
.correction-section p,
.metric-note {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
}

.file-summary {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.file-summary:not([hidden]) {
  display: flex;
}

.file-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-button {
  padding: 4px 0;
  background: transparent;
  color: var(--accent-readable);
  cursor: pointer;
  white-space: nowrap;
}

.section-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-heading-row output,
.zoom-control output,
.count-value,
.metric-row strong {
  font-family: var(--font-number);
}

.section-heading-row output {
  color: var(--accent-readable);
  font-weight: 700;
}

.settings-section label {
  display: block;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-strong);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 11px;
}

.helper-text {
  margin: 14px 0 16px;
}

.primary-button,
.secondary-button,
.mode-button,
.error-banner button {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, transform 100ms ease;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary-button,
.mode-button {
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
}

.secondary-button:hover:not(:disabled),
.mode-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.mode-button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.compact-section {
  border-bottom: 0;
}

.guidance-grid {
  display: grid;
  gap: 10px;
}

.guidance-grid p {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
}

.guidance-grid span {
  color: var(--text-muted);
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr) 42px;
  background: var(--canvas);
}

.viewer-toolbar,
.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px;
  background: var(--surface-raised);
  color: var(--text);
}

.viewer-toolbar {
  border-bottom: 1px solid var(--line);
}

.viewer-footer {
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.viewer-footer > span {
  margin-left: auto;
  color: var(--text-muted);
  text-align: right;
}

.mode-group,
.viewer-actions,
.zoom-control,
.check-control {
  display: flex;
  align-items: center;
}

.mode-group,
.viewer-actions {
  gap: 8px;
}

.mode-button,
.secondary-button {
  min-height: 34px;
  padding-inline: 12px;
  font-size: 12px;
}

.mode-button.is-active {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: var(--accent-text);
}

.zoom-control {
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.zoom-control input {
  width: 100px;
}

.zoom-control output {
  width: 44px;
  color: var(--text);
}

.check-control {
  gap: 6px;
  white-space: nowrap;
}

.check-control input {
  accent-color: var(--accent-strong);
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.canvas-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 18px;
}

.canvas-wrap canvas {
  display: block;
  margin: auto;
  background: #20231f;
  box-shadow: 0 8px 28px rgb(7 9 7 / 0.35);
  touch-action: manipulation;
}

.canvas-wrap.is-editing canvas {
  cursor: crosshair;
}

.empty-state,
.loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  color: #e5e8e1;
}

.empty-state h2,
.loading-state h2 {
  margin-top: 18px;
  font-size: 18px;
}

.empty-state p,
.loading-state p {
  max-width: 440px;
  margin-top: 9px;
  color: #aeb5aa;
  font-size: 13px;
  line-height: 1.7;
}

.empty-visual {
  width: 116px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.empty-visual span {
  aspect-ratio: 1;
  border: 2px solid #737b70;
  border-radius: 50%;
}

.loading-lines {
  width: 190px;
  display: grid;
  gap: 8px;
}

.loading-lines span {
  height: 7px;
  border-radius: var(--radius);
  background: #4e554c;
  overflow: hidden;
}

.loading-lines span::after {
  content: "";
  display: block;
  width: 45%;
  height: 100%;
  background: var(--accent);
  animation: loading-scan 1.25s ease-in-out infinite alternate;
}

.loading-lines span:nth-child(2)::after {
  animation-delay: 140ms;
}

.loading-lines span:nth-child(3)::after {
  animation-delay: 280ms;
}

@keyframes loading-scan {
  from { transform: translateX(-15%); }
  to { transform: translateX(140%); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.count-section {
  padding-block: 22px;
}

.count-value {
  color: var(--accent-readable);
  font-size: clamp(44px, 5vw, 68px);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  overflow-wrap: anywhere;
}

.count-section > p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.metric-section {
  display: grid;
  gap: 12px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 12px;
}

.metric-row span {
  color: var(--text-muted);
}

.metric-note {
  margin-top: 2px;
}

.correction-section p {
  margin: 0 0 14px;
}

.wide-button {
  width: 100%;
}

.export-section {
  display: grid;
  gap: 10px;
  border-bottom: 0;
}

.export-section h2 {
  margin-bottom: 4px;
}

.error-banner {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(520px, calc(100vw - 36px));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-surface);
  color: var(--text);
  box-shadow: 0 12px 36px rgb(30 20 18 / 0.2);
  font-size: 13px;
}

.error-banner strong {
  color: var(--danger);
}

.error-banner button {
  min-height: 30px;
  border: 1px solid color-mix(in srgb, var(--danger) 60%, var(--line));
  background: transparent;
  color: var(--text);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1050px) {
  body {
    overflow: auto;
  }

  .workbench {
    height: auto;
    min-height: calc(100dvh - var(--header-height));
    grid-template-columns: 250px minmax(0, 1fr);
    grid-template-areas:
      "controls viewer"
      "results viewer";
  }

  .control-panel {
    grid-area: controls;
  }

  .viewer-panel {
    grid-area: viewer;
    min-height: calc(100dvh - var(--header-height));
  }

  .result-panel {
    grid-area: results;
    border-left: 0;
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  :root {
    --header-height: 64px;
  }

  .app-header {
    padding-inline: 14px;
  }

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

  .local-status {
    display: none;
  }

  .workbench {
    display: flex;
    flex-direction: column;
  }

  .control-panel,
  .result-panel {
    overflow: visible;
    border: 0;
  }

  .viewer-panel {
    order: 2;
    min-height: 74dvh;
    grid-template-rows: auto minmax(500px, 1fr) auto;
  }

  .result-panel {
    order: 3;
  }

  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
    padding-block: 10px;
  }

  .viewer-actions {
    flex-wrap: wrap;
  }

  .zoom-control {
    flex: 1;
  }

  .zoom-control input {
    min-width: 100px;
    flex: 1;
  }

  .viewer-footer {
    min-height: 48px;
    flex-wrap: wrap;
    padding-block: 8px;
  }

  .viewer-footer > span {
    width: 100%;
    text-align: left;
  }

  .error-banner {
    grid-template-columns: 1fr auto;
  }

  .error-banner strong {
    grid-column: 1;
  }

  .error-banner span {
    grid-column: 1;
  }

  .error-banner button {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}




.upload-privacy,
.public-note {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.65;
}

.legal-link,
.legal-back {
  color: var(--accent-readable);
  font-size: 12px;
  font-weight: 700;
  text-underline-offset: 3px;
}

.legal-page {
  min-height: 100dvh;
  overflow: auto;
  background: var(--page);
}

.legal-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.legal-header a {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.legal-header span {
  color: var(--text-muted);
  font-size: 13px;
}

.legal-shell {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 52px 0 max(64px, env(safe-area-inset-bottom));
}

.legal-shell h1 {
  max-width: 12ch;
  margin: 0;
  font-size: clamp(32px, 8vw, 54px);
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.legal-intro {
  max-width: 58ch;
  margin: 20px 0 38px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.8;
}

.legal-shell section {
  padding: 22px 0;
  border-top: 1px solid var(--line);
}

.legal-shell section h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.legal-shell section p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.8;
}

.legal-back {
  display: inline-block;
  margin-top: 28px;
}