:root {
  color-scheme: dark;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #edf2f7;
  background: #0b0f14;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #0b0f14;
  --panel: #121820;
  --panel-strong: #171f29;
  --panel-soft: #0f151c;
  --line: #27313d;
  --line-strong: #394656;
  --text: #edf2f7;
  --muted: #93a1b2;
  --subtle: #647284;
  --accent: #79e5bf;
  --accent-strong: #26b889;
  --blue: #73a9ff;
  --warning: #ffd166;
  --danger: #ff696d;
  --ignore: #a98bff;
  --shadow: 0 22px 65px rgba(0, 0, 0, 0.32);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% -10%, rgba(51, 126, 112, 0.18), transparent 34rem),
    radial-gradient(circle at 96% 10%, rgba(56, 82, 130, 0.16), transparent 32rem),
    var(--page);
}

button,
input,
select {
  font: inherit;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
[role="button"]:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app-shell {
  width: min(1880px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.product-kicker {
  margin-bottom: 7px;
  color: var(--accent);
  font: 700 11px/1.2 ui-monospace, "SFMono-Regular", monospace;
  letter-spacing: 0.14em;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  letter-spacing: -0.035em;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions,
.region-actions,
.export-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.privacy-badge {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border: 1px solid rgba(121, 229, 191, 0.25);
  border-radius: 999px;
  color: #aaf0d6;
  background: rgba(33, 101, 82, 0.18);
  font-size: 12px;
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.button:disabled {
  color: #596575;
  cursor: not-allowed;
  background: #171d25;
  border-color: #252d38;
}

.button-primary {
  color: #08271e;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 750;
}

.button-primary:hover:not(:disabled) {
  background: #9af0d2;
}

.button-secondary {
  background: #1a232e;
  border-color: #334050;
}

.button-secondary:hover:not(:disabled) {
  border-color: #63758a;
  background: #222e3a;
}

.button-ghost {
  color: var(--muted);
  background: transparent;
  border-color: #2b3541;
}

.button-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #4a596c;
}

.text-button {
  min-height: 44px;
  border: 0;
  padding: 4px;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.upload-card {
  min-height: 105px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 15px;
  border: 1px dashed #415064;
  border-radius: var(--radius);
  padding: 15px;
  background: linear-gradient(135deg, rgba(25, 34, 45, 0.96), rgba(15, 21, 28, 0.96));
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-card:hover,
.upload-card.is-dragging {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(27, 51, 50, 0.95), rgba(15, 25, 29, 0.96));
}

.upload-card.has-image {
  border-style: solid;
  border-color: #3e5f59;
}

.upload-icon {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #071e18;
  background: var(--accent);
  font: 800 20px/1 ui-monospace, monospace;
}

.upload-icon-actual {
  color: #0b1c35;
  background: var(--blue);
}

.upload-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.upload-label {
  color: var(--subtle);
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.upload-copy strong,
.upload-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-copy strong {
  font-size: 15px;
}

.upload-copy small {
  color: var(--muted);
  font-size: 12px;
}

.review-layout {
  min-height: calc(100vh - 260px);
  display: grid;
  grid-template-columns: minmax(260px, 305px) minmax(540px, 1fr) minmax(290px, 335px);
  gap: 14px;
  align-items: stretch;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(20, 27, 36, 0.98), rgba(14, 20, 27, 0.98));
  box-shadow: var(--shadow);
}

.control-panel,
.result-panel {
  align-self: start;
  padding: 16px;
}

.panel-heading,
.region-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-heading h2,
.region-heading h2,
.reason-section h2 {
  margin: 0;
  font-size: 14px;
}

.panel-heading.compact {
  margin-bottom: 9px;
}

.section-index {
  color: var(--accent);
  font: 700 10px/1 ui-monospace, monospace;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin: 13px 0 15px;
  padding: 4px;
  border-radius: 11px;
  background: #0a0f15;
}

.segmented-control button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segmented-control button:hover {
  color: var(--text);
}

.segmented-control button.is-active {
  color: #0b211b;
  background: var(--accent);
  font-weight: 750;
}

.alignment-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 12px;
  padding: 4px;
  border-radius: 11px;
  background: #0a0f15;
}

.alignment-modes button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.alignment-modes button.is-active {
  color: #0b1c35;
  background: var(--blue);
  font-weight: 750;
}

.alignment-actions {
  display: flex;
  gap: 8px;
}

.alignment-actions .button {
  flex: 1;
}

.alignment-status {
  margin-top: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  color: var(--muted);
  background: #0d1319;
  font: 11px/1.5 ui-monospace, monospace;
}

.alignment-status.is-running {
  color: var(--blue);
  border-color: rgba(115, 169, 255, 0.4);
}

.alignment-status.is-accepted {
  color: var(--accent);
  border-color: rgba(121, 229, 191, 0.4);
}

.alignment-status.is-rejected {
  color: var(--danger);
  border-color: rgba(255, 105, 109, 0.45);
}

.alignment-fields {
  margin-top: 10px;
  border-left: 2px solid rgba(115, 169, 255, 0.45);
  padding-left: 10px;
}

.range-field {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.range-field > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.range-field b {
  color: #c9d2dc;
  font-weight: 600;
}

.range-field output {
  color: var(--accent);
  font-family: ui-monospace, monospace;
}

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

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.helper-text {
  margin: 9px 0 13px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.viewer-panel {
  min-height: 680px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.viewer-toolbar,
.viewer-footer {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 13px;
  color: var(--muted);
  background: #10161d;
}

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

.viewer-footer {
  min-height: 38px;
  border-top: 1px solid var(--line);
  font: 11px/1.2 ui-monospace, monospace;
}

.viewer-status {
  color: #dbe4ec;
  font-size: 13px;
}

.dimension-status {
  margin-left: 8px;
  color: var(--subtle);
  font: 11px/1 ui-monospace, monospace;
}

.dimension-status.is-error {
  color: var(--danger);
}

.legend {
  display: flex;
  gap: 12px;
  font-size: 11px;
}

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

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-critical {
  border: 1px solid var(--warning);
  background: rgba(255, 209, 102, 0.24);
}

.legend-ignore {
  border: 1px solid var(--ignore);
  background: rgba(169, 139, 255, 0.24);
}

.canvas-viewport {
  position: relative;
  min-height: 580px;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 20px;
  background:
    linear-gradient(45deg, #121920 25%, transparent 25%) 0 0 / 20px 20px,
    linear-gradient(-45deg, #121920 25%, transparent 25%) 0 10px / 20px 20px,
    linear-gradient(45deg, transparent 75%, #121920 75%) 10px -10px / 20px 20px,
    linear-gradient(-45deg, transparent 75%, #121920 75%) -10px 0 / 20px 20px,
    #0d1319;
}

.canvas-viewport.is-drawing {
  cursor: crosshair;
}

#review-canvas {
  display: block;
  max-width: none;
  border: 1px solid #3b4654;
  background: #0a0d11;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.42);
  touch-action: none;
}

#review-canvas.is-overlay-draggable {
  cursor: ew-resize;
}

.empty-state {
  width: min(440px, 100%);
  align-self: center;
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 9px;
  padding: 44px 24px;
  text-align: center;
}

.empty-mark {
  width: 72px;
  height: 54px;
  border: 2px solid #435162;
  border-radius: 12px;
  background:
    linear-gradient(90deg, transparent 48%, #435162 48% 52%, transparent 52%),
    linear-gradient(#1c2631, #121820);
}

.empty-state h2 {
  margin: 8px 0 0;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.verdict-card {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 15px;
  background: var(--panel-strong);
}

.verdict-label {
  color: var(--muted);
  font-size: 11px;
}

.verdict-card strong {
  font: 850 26px/1 ui-monospace, monospace;
}

.verdict-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.verdict-pass {
  border-color: rgba(121, 229, 191, 0.5);
  background: rgba(38, 122, 94, 0.17);
}

.verdict-pass strong { color: var(--accent); }
.verdict-review { border-color: rgba(255, 209, 102, 0.55); background: rgba(137, 102, 34, 0.18); }
.verdict-review strong { color: var(--warning); }
.verdict-fail { border-color: rgba(255, 105, 109, 0.58); background: rgba(136, 38, 47, 0.18); }
.verdict-fail strong { color: var(--danger); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 18px;
}

.metric-card {
  min-height: 83px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px;
  background: var(--panel-soft);
}

.metric-card span,
.metric-card small {
  color: var(--subtle);
  font-size: 10px;
}

.metric-card strong {
  font: 750 18px/1.15 ui-monospace, monospace;
}

.region-section,
.reason-section {
  border-top: 1px solid var(--line);
  padding-top: 15px;
  margin-top: 14px;
}

.region-heading span {
  color: var(--subtle);
  font-size: 11px;
}

.region-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
  max-height: 220px;
  overflow: auto;
}

.region-empty {
  padding: 15px 8px;
  color: var(--subtle);
  font-size: 12px;
  text-align: center;
}

.region-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  background: #10161d;
}

.region-swatch {
  width: 10px;
  height: 30px;
  border-radius: 4px;
  background: var(--warning);
}

.region-item.is-ignore .region-swatch {
  background: var(--ignore);
}

.region-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.region-name {
  width: 100%;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 5px;
  color: var(--text);
  background: transparent;
}

.region-name:hover,
.region-name:focus {
  border-color: var(--line-strong);
  background: #0b1016;
}

.region-copy small {
  color: var(--subtle);
  font: 10px/1.2 ui-monospace, monospace;
}

.region-verdict {
  font: 750 10px/1 ui-monospace, monospace;
}

.region-delete {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.region-delete:hover {
  color: white;
  border-color: var(--danger);
}

.reason-section ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.export-actions {
  margin-top: 17px;
}

.export-actions .button {
  flex: 1;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 24px;
  max-width: min(460px, calc(100% - 32px));
  border: 1px solid #425266;
  border-radius: 10px;
  padding: 11px 14px;
  color: white;
  background: #1a232e;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1320px) {
  .review-layout {
    grid-template-columns: 285px minmax(520px, 1fr);
  }

  .result-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.3fr) minmax(280px, 1fr);
    gap: 14px;
    align-items: start;
  }

  .metric-grid {
    margin: 0;
  }

  .region-section,
  .reason-section {
    margin-top: 0;
    border-top: 0;
    padding-top: 0;
  }

  .export-actions {
    grid-column: 1 / -1;
  }
}

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

  .app-header,
  .header-actions {
    align-items: flex-start;
  }

  .app-header {
    flex-direction: column;
  }

  .upload-grid,
  .review-layout,
  .result-panel {
    grid-template-columns: 1fr;
  }

  .result-panel,
  .export-actions {
    grid-column: auto;
  }

  .control-panel,
  .result-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .upload-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .choose-file {
    grid-column: 1 / -1;
    width: 100%;
  }

  .viewer-toolbar,
  .viewer-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .canvas-viewport {
    min-height: 480px;
    padding: 10px;
  }

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

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