:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #171a1f;
  --muted: #68707d;
  --line: #dfe3e8;
  --brand: #1877f2;
  --brand-strong: #166fe5;
  --brand-soft: #eef5ff;
  --brand-soft-border: #cfe1ff;
  --warn: #c96b00;
  --danger: #c93636;
  --shadow: 0 18px 48px rgba(30, 38, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #aab2bd;
}

.primary-button {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  border-color: var(--brand-strong);
  background: var(--brand-strong);
}

button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-spinner {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: spin 760ms linear infinite;
}

.button-spinner-dark {
  border-color: rgba(24, 119, 242, 0.22);
  border-top-color: var(--brand);
}

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

.ghost-button {
  background: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.workspace,
.report-panel,
.upload-panel,
.settings-panel,
.phone-frame {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.topbar,
.report-heading,
.canvas-title,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 0;
}

.brand-logo {
  display: block;
  width: 200px;
  height: auto;
  transform: translateY(-6px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p,
.panel-heading span,
.canvas-title span,
.principles p,
.issue-meta,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.actions {
  display: flex;
  gap: 10px;
  transform: translateY(-6px);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.upload-panel,
.settings-panel {
  padding: 14px;
}

.dropzone {
  display: grid;
  place-items: center;
  height: 112px;
  margin: 12px 0;
  border: 1px dashed #aeb7c2;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-active {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.dropzone input {
  display: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detect-card {
  min-height: 74px;
  border: 1px solid var(--brand-soft-border);
  border-radius: 8px;
  padding: 10px;
  white-space: pre-line;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 13px;
  line-height: 1.45;
}

.detect-card.is-low-confidence {
  border-color: #f1d1a8;
  background: #fff7eb;
  color: #7c4300;
}

.advanced-settings {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.advanced-settings summary {
  color: #4d5662;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.advanced-settings[open] {
  gap: 12px;
}

.advanced-settings[open] summary {
  margin-bottom: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #4d5662;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 76px;
  padding: 9px 10px;
  resize: vertical;
  line-height: 1.45;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--brand);
}

.settings-panel {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 12px;
}

.settings-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.compare-stage {
  display: grid;
  gap: 12px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 6px;
}

.compare-stage.is-empty {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  overflow-x: auto;
}

.compare-stage.has-images {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compare-stage.is-large-preview {
  grid-template-columns: minmax(720px, 1fr);
}

.compare-stage.is-large-preview .phone-frame {
  min-width: 720px;
}

.phone-frame {
  width: 100%;
  max-width: none;
  padding: 12px;
  overflow: visible;
}

.canvas-title {
  height: 28px;
  margin-bottom: 10px;
  overflow: hidden;
}

.canvas-title > span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.title-with-help {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.title-with-help strong {
  flex: 0 0 auto;
}

.canvas-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  min-width: 0;
  white-space: nowrap;
}

.annotation-switch {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.annotation-switch input {
  width: 34px;
  height: 18px;
  margin: 0;
  appearance: none;
  border: 1px solid #aab2bd;
  border-radius: 999px;
  background: #eef1f5;
  cursor: pointer;
  position: relative;
}

.annotation-switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transition: transform 160ms ease;
}

.annotation-switch input:checked {
  border-color: var(--brand);
  background: var(--brand);
}

.annotation-switch input:checked::after {
  transform: translateX(16px);
}

canvas {
  display: block;
  margin-inline: auto;
  max-width: none;
  border: 1px solid #e6e9ee;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f4f6f8 25%, transparent 25%),
    linear-gradient(-45deg, #f4f6f8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f4f6f8 75%),
    linear-gradient(-45deg, transparent 75%, #f4f6f8 75%);
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

#buildCanvas.has-annotations {
  cursor: grab;
}

#buildCanvas.is-dragging {
  cursor: grabbing;
}

.report-panel {
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  padding: 16px;
  overflow: auto;
  box-shadow: var(--shadow);
}

.report-heading {
  margin-bottom: 14px;
}

.report-heading button {
  min-height: 34px;
  padding: 0 10px;
}

.score-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.score-card span {
  font-size: 13px;
}

.score-card strong {
  font-size: 32px;
  line-height: 1;
}

.principles {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.principles strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.ai-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.ai-config {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.ai-config summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #303842;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.ai-config summary::-webkit-details-marker {
  display: none;
}

.ai-config summary::after {
  content: "展开";
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
}

.ai-config[open] summary {
  margin-bottom: 10px;
}

.ai-config[open] summary::after {
  content: "收起";
}

.ai-config small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-actions button {
  width: 100%;
}

.ai-hint,
.ai-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.ai-status {
  min-height: 18px;
}

.ai-result {
  display: none;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
  color: #303842;
  font-size: 13px;
  line-height: 1.55;
}

.ai-result.has-content {
  display: block;
}

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

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

.issue-card {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease,
    transform 120ms ease;
}

.issue-card.is-focused {
  border-color: #8fa3b8;
  box-shadow: 0 10px 24px rgba(30, 38, 50, 0.12);
  transform: translateY(-1px);
}

.issue-card.is-selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(15, 123, 108, 0.22), 0 12px 28px rgba(30, 38, 50, 0.14);
}

.issue-card.is-dimmed {
  opacity: 0.48;
}

.issue-card.high {
  border-left-color: var(--danger);
}

.issue-card.medium {
  border-left-color: var(--warn);
}

.issue-card.low {
  border-left-color: var(--brand);
}

.issue-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
}

.severity {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.high .severity {
  background: var(--danger);
}

.medium .severity {
  background: var(--warn);
}

.low .severity {
  background: var(--brand);
}

.issue-card p {
  color: #3a424d;
  font-size: 13px;
  line-height: 1.55;
}

.issue-meta {
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .report-panel {
    position: static;
    height: auto;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px;
  }

  .workspace {
    padding: 12px;
  }

  .topbar,
  .report-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions,
  .report-heading button {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }

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

  .compare-stage {
    overflow-x: auto;
  }

  .compare-stage.is-empty {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    overflow-x: auto;
  }

  .compare-stage.has-images {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }

  .compare-stage.is-large-preview {
    grid-template-columns: minmax(620px, 1fr);
  }

  .compare-stage.is-large-preview .phone-frame {
    min-width: 620px;
  }

  canvas {
    max-width: none;
  }
}
