:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dfe2ec;
  --text: #171a26;
  --muted: #5f6578;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #e8e7fd;
  --on-accent: #ffffff;
  --danger: #c0262d;
  --danger-soft: #fdecec;
  --notice-soft: #fff6e0;
  --notice-text: #7a5300;
  --checker-a: #e9ebf1;
  --checker-b: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 4px 16px rgba(20, 24, 40, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #222632;
    --border: #2e3340;
    --text: #eceef4;
    --muted: #9aa0b2;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #272a4a;
    --on-accent: #0f1117;
    --danger: #f87171;
    --danger-soft: #3a1d20;
    --notice-soft: #33290f;
    --notice-text: #f5d58a;
    --checker-a: #20232d;
    --checker-b: #2a2e3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: calc(100dvh + env(safe-area-inset-top, 0px));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.topbar,
.layout {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.topbar {
  padding-top: 28px;
  padding-bottom: 8px;
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  font-size: 15px;
}

.brand-name {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.layout {
  display: grid;
  gap: 16px;
  padding-top: 16px;
  padding-bottom: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 190px;
  padding: 24px 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone.is-disabled {
  pointer-events: none;
  opacity: 0.55;
}

.dropzone-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  mask: url("../favicon.svg") center / contain no-repeat;
  -webkit-mask: url("../favicon.svg") center / contain no-repeat;
}

.dropzone-title {
  font-size: 17px;
  font-weight: 650;
}

.dropzone-hint {
  color: var(--muted);
  font-size: 13px;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.file-thumb {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: cover;
  border-radius: 8px;
  background: var(--checker-a);
}

.file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.file-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-details {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.notice,
.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.notice {
  background: var(--notice-soft);
  color: var(--notice-text);
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 14px;
}

.option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font-weight: 600;
  cursor: pointer;
}

.option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: inherit;
}

.option:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.actions .btn-primary {
  flex: 1 1 220px;
}

.progress {
  margin-top: 14px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}

.progress-track {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  --value: 0%;
  height: 100%;
  width: var(--value);
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s;
}

.progress-bar.progress-indeterminate {
  width: 35%;
  animation: progress-slide 1.2s ease-in-out infinite;
}

@keyframes progress-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(300%); }
}

.live {
  --ar: 1;
  position: relative;
  width: min(100%, 50vh * var(--ar));
  aspect-ratio: var(--ar);
  margin: 14px auto 0;
  border-radius: 12px;
  overflow: hidden;
  outline: 1px solid var(--border);
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 20px 20px;
}

.live-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.live-tile {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: left 0.15s, top 0.15s;
  animation: live-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes live-pulse {
  from { opacity: 1; }
  to { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .live-tile {
    transition: none;
    animation: none;
  }
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 16px 0 0;
  font-size: 13px;
}

.stats div {
  display: flex;
  gap: 6px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-weight: 600;
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.viewer {
  max-height: 70vh;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 20px 20px;
  overscroll-behavior: contain;
}

.stage {
  --zoom: 1;
  --pos: 50%;
  --ar: 1;
  position: relative;
  width: calc(min(100%, 70vh * var(--ar)) * var(--zoom));
  aspect-ratio: var(--ar);
  margin: 0 auto;
}

.stage-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.stage-after {
  clip-path: inset(0 0 0 var(--pos));
}

.stage-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.stage-tag {
  position: absolute;
  top: 10px;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

.stage.is-zoomed .stage-tag {
  display: none;
}

.stage-tag-left {
  left: 10px;
}

.stage-tag-right {
  right: 10px;
}

.compare {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.compare input {
  flex: 1;
  accent-color: var(--accent);
  min-width: 0;
}

@media (max-width: 560px) {
  .topbar {
    padding-top: 18px;
  }

  .brand-name {
    font-size: 19px;
  }

  .panel {
    padding: 14px;
  }

  .result-head .btn {
    flex: 1 1 100%;
  }
}
