:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #202522;
  background: #f7f8f6;
  font-synthesis: none;
  --border: #d9ded9;
  --muted: #68716c;
  --surface: #ffffff;
  --surface-subtle: #f0f3f0;
  --accent: #147d64;
  --accent-hover: #0f6954;
  --blue: #2474c6;
  --yellow: #e2a50c;
  --shadow: 0 10px 30px rgb(30 45 37 / 8%);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #f7f8f6;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
}

.brand-mark svg {
  width: 21px;
}

.brand h1,
.brand p,
.section-header h2,
.section-header p,
.control-section h2 {
  margin: 0;
}

.brand h1 {
  font-size: 16px;
  line-height: 20px;
}

.brand p {
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa39e;
}

.header-status.ready .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgb(20 125 100 / 12%);
}

.workspace {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

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

.control-section,
.advanced-settings {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.control-section h2 {
  margin-bottom: 14px;
  color: #404843;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.drop-zone {
  display: grid;
  min-height: 132px;
  place-items: center;
  align-content: center;
  gap: 7px;
  border: 1px dashed #aeb8b2;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-subtle);
  transition: border-color 160ms, background 160ms;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--accent);
  background: #eaf4f0;
}

.drop-zone svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.drop-zone strong {
  color: #28302b;
  font-size: 14px;
}

.drop-zone span {
  font-size: 11px;
}

.file-info {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  min-height: 54px;
}

.file-info > svg {
  color: var(--accent);
}

.file-info div {
  min-width: 0;
}

.file-info strong,
.file-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info strong {
  font-size: 13px;
}

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

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.icon-button:hover {
  border-color: var(--border);
  color: #232a26;
  background: var(--surface-subtle);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

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

.field {
  display: grid;
  gap: 7px;
  color: #4b544f;
  font-size: 12px;
}

.field input[type="number"] {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #202522;
  background: #fff;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(20 125 100 / 10%);
}

.range-field {
  margin-top: 16px;
}

.range-field > span {
  display: flex;
  justify-content: space-between;
}

.range-field output {
  color: var(--accent);
  font-weight: 700;
}

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

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  cursor: pointer;
}

.toggle-row + .toggle-row {
  margin-top: 10px;
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row strong {
  font-size: 13px;
}

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

.toggle-row input {
  position: absolute;
  opacity: 0;
}

.toggle {
  position: relative;
  flex: 0 0 38px;
  width: 38px;
  height: 22px;
  border-radius: 11px;
  background: #b8bfbb;
  transition: background 160ms;
}

.toggle::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 20%);
  transition: transform 160ms;
  content: "";
}

.toggle-row input:checked + .toggle {
  background: var(--accent);
}

.toggle-row input:checked + .toggle::after {
  transform: translateX(16px);
}

.toggle-row input:focus-visible + .toggle {
  outline: 3px solid rgb(20 125 100 / 20%);
}

.advanced-settings {
  padding-top: 0;
  padding-bottom: 0;
}

.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  color: #414a45;
  font-size: 12px;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary svg {
  width: 16px;
  transition: transform 160ms;
}

.advanced-settings[open] summary svg {
  transform: rotate(180deg);
}

.advanced-content {
  display: grid;
  gap: 12px;
  padding-bottom: 18px;
}

.primary-actions {
  position: sticky;
  bottom: 0;
  padding: 18px 20px;
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(10px);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 15px;
  border-radius: 6px;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

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

.secondary-button {
  border: 1px solid var(--border);
  color: #27302b;
  background: #fff;
}

.secondary-button:hover:not(:disabled) {
  border-color: #a9b2ad;
  background: var(--surface-subtle);
}

.primary-button svg,
.secondary-button svg {
  width: 17px;
  height: 17px;
}

.content-area {
  min-width: 0;
  padding: 24px;
}

.preview-section,
.results-section {
  width: min(100%, 1440px);
  margin: 0 auto;
}

.results-section {
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.section-header h2 {
  font-size: 16px;
}

.section-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 11px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  display: inline-block;
  width: 16px;
  height: 3px;
}

.legend-line.theoretical {
  background: var(--blue);
}

.legend-line.detected {
  background: var(--accent);
}

.preview-stage {
  position: relative;
  display: grid;
  min-height: 440px;
  max-height: 68vh;
  padding: 20px;
  overflow: auto;
  place-items: center;
  border: 1px solid var(--border);
  background-color: #e8ece9;
  background-image:
    linear-gradient(45deg, #dfe4e0 25%, transparent 25%),
    linear-gradient(-45deg, #dfe4e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe4e0 75%),
    linear-gradient(-45deg, transparent 75%, #dfe4e0 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.preview-stage canvas {
  display: block;
  max-width: 100%;
  max-height: calc(68vh - 40px);
  background: #fff;
  box-shadow: var(--shadow);
}

.empty-preview {
  display: grid;
  place-items: center;
  gap: 10px;
  color: #748078;
  font-size: 13px;
}

.empty-preview svg {
  width: 34px;
  height: 34px;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #27302b;
  background: rgb(247 248 246 / 86%);
  backdrop-filter: blur(4px);
}

.processing-overlay strong {
  font-size: 13px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #b8c4bd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}

.result-item {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

.result-image {
  display: grid;
  min-height: 140px;
  padding: 10px;
  place-items: center;
  background-color: #eff2ef;
  background-image:
    linear-gradient(45deg, #e2e6e3 25%, transparent 25%),
    linear-gradient(-45deg, #e2e6e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e6e3 75%),
    linear-gradient(-45deg, transparent 75%, #e2e6e3 75%);
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
}

.result-image canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 180px;
  background: #fff;
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 5px 7px 5px 10px;
  border-top: 1px solid var(--border);
}

.result-meta strong,
.result-meta span {
  display: block;
}

.result-meta strong {
  font-size: 11px;
}

.result-meta span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid #cbd2ce;
  border-radius: 7px;
  color: #fff;
  background: #29312d;
  box-shadow: var(--shadow);
  font-size: 13px;
}

@media (max-width: 820px) {
  .app-header {
    height: 58px;
    padding: 0 14px;
  }

  .workspace {
    display: block;
  }

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

  .primary-actions {
    position: static;
  }

  .content-area {
    padding: 18px 14px 30px;
  }

  .preview-stage {
    min-height: 300px;
    max-height: 60vh;
    padding: 12px;
  }

  .preview-stage canvas {
    max-height: calc(60vh - 24px);
  }
}

@media (max-width: 520px) {
  .header-status span:last-child,
  .legend {
    display: none;
  }

  .section-header {
    align-items: flex-end;
  }

  .results-header {
    align-items: center;
  }

  .secondary-button span {
    display: none;
  }

  .secondary-button {
    width: 40px;
    padding: 0;
  }

  .results-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .result-image {
    min-height: 120px;
  }
}

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