:root {
  color-scheme: light;
  --bg: #f0f4f5;
  --panel: #ffffff;
  --panel-soft: #eef3f4;
  --ink: #142023;
  --muted: #617478;
  --line: #d6e0e2;
  --accent: #0f9f8f;
  --accent-strong: #087d75;
  --accent-glow: rgba(15, 159, 143, .18);
  --danger: #b23b3b;
  --shadow: 0 1px 3px rgba(24, 43, 48, .08), 0 8px 32px rgba(24, 43, 48, .10);
  --shadow-sm: 0 1px 2px rgba(24, 43, 48, .06);
  --radius: 10px;
  --radius-sm: 7px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius-sm);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
  transition: all .15s ease;
  font-weight: 500;
  font-size: 13px;
}

button:hover:not(:disabled) {
  border-color: #91b5b2;
  background: #f9fcfc;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  color: #9aa5a8;
  cursor: not-allowed;
  background: #f3f6f7;
}

.app-shell {
  min-height: 100vh;
  padding: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: 345px minmax(0, 1fr);
  min-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fafcfc;
  padding: 22px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0f9f8f, #087d75);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  box-shadow: 0 4px 12px var(--accent-glow);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0 0 1px;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .01em;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 150px;
  padding: 22px;
  text-align: center;
  background:
    linear-gradient(45deg, #dfe7e9 25%, transparent 25%),
    linear-gradient(-45deg, #dfe7e9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe7e9 75%),
    linear-gradient(-45deg, transparent 75%, #dfe7e9 75%);
  background-color: #fff;
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  border: 2px dashed #a9bec2;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .2s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background-color: #f9fffe;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  outline: 3px solid var(--accent-glow);
  background-color: #effbf9;
  transform: scale(1.02);
}

.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform .2s ease;
}

.dropzone:hover .drop-icon {
  transform: scale(1.08);
}

.dropzone strong {
  font-size: 15px;
}

.dropzone small {
  color: var(--muted);
  line-height: 1.45;
  font-size: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented button {
  min-width: 0;
  padding: 0 6px;
  font-size: 13px;
}

.view-tabs button {
  min-width: 0;
}

.is-active {
  background: #def4f1;
  border-color: #7bc6bd;
  color: #075e58;
  font-weight: 600;
}

.control-grid {
  display: grid;
  gap: 16px;
}

.control-grid label {
  display: grid;
  gap: 7px;
}

.control-grid span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

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

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.switch input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  min-height: 46px;
  box-shadow: 0 4px 14px var(--accent-glow);
  letter-spacing: .01em;
}

.primary-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #12b5a4, var(--accent-strong));
  border-color: var(--accent-strong);
  box-shadow: 0 6px 20px rgba(15, 159, 143, .30);
  transform: translateY(-2px);
}

.primary-btn:disabled {
  background: #d4e0e3;
  border-color: #c5d3d6;
  color: #8ba0a5;
  box-shadow: none;
}

.primary-btn.loading {
  position: relative;
  color: transparent;
}

.primary-btn.loading::after {
  content: '';
  position: absolute;
  inset: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2.5px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

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

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

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

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

.stats dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stage-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: #ecf1f2;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.view-tabs,
.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

#zoomLabel {
  min-width: 54px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

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

.empty-state {
  display: grid;
  place-content: center;
  min-height: 100%;
  padding: 40px;
  text-align: center;
  gap: 12px;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-glow), transparent);
  display: grid;
  place-items: center;
  font-size: 36px;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(20px, 3.5vw, 36px);
  font-weight: 700;
  letter-spacing: -.02em;
}

.empty-state p {
  margin: 0 auto;
  max-width: 520px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 15px;
}

.loading-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #2ed0c0, var(--accent));
  background-size: 200% 100%;
  animation: loadingBar 1.5s ease-in-out infinite;
  transform-origin: 0 0;
  z-index: 10;
  display: none;
}

.loading-bar.is-active {
  display: block;
  animation: loadingBar 1.5s ease-in-out infinite, loadingFade .3s ease;
}

@keyframes loadingBar {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes loadingFade {
  from { opacity: 0; transform: scaleX(0); }
  to { opacity: 1; transform: scaleX(1); }
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  background:
    linear-gradient(45deg, #ccd5d8 25%, transparent 25%),
    linear-gradient(-45deg, #ccd5d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccd5d8 75%),
    linear-gradient(-45deg, transparent 75%, #ccd5d8 75%);
  background-color: #fff;
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.panzoom {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 0 0;
  transition: transform .08s ease-out;
}

.artboard {
  position: relative;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(20, 32, 35, .20);
}

.artboard img,
.svg-layer,
.line-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.artboard img {
  display: block;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.svg-layer svg,
.line-layer svg {
  display: block;
  width: 100%;
  height: 100%;
}

.line-layer {
  pointer-events: none;
  mix-blend-mode: multiply;
}

.line-layer path,
.line-layer polygon,
.line-layer rect,
.line-layer circle,
.line-layer ellipse {
  fill: none !important;
  stroke: #02d5d9 !important;
  stroke-width: 1.2 !important;
  vector-effect: non-scaling-stroke;
}

.view-output #originalImage,
.view-output .split-handle,
.view-output .split-range {
  display: none;
}

.view-original .svg-layer,
.view-original .line-layer,
.view-original .split-handle,
.view-original .split-range {
  display: none;
}

.view-overlay .split-handle,
.view-overlay .split-range {
  display: none;
}

.view-overlay .svg-layer {
  opacity: .72;
}

.view-split .svg-layer,
.view-split .line-layer {
  clip-path: inset(0 0 0 var(--split-left, 50%));
}

.view-split .split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split-left, 50%);
  width: 3px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(20, 32, 35, .30), 0 0 24px rgba(0, 0, 0, .18);
  pointer-events: none;
}

.split-range {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 20px;
  width: calc(100% - 48px);
  accent-color: var(--accent);
  z-index: 5;
}

.magnifier {
  position: absolute;
  width: 210px;
  height: 210px;
  border: 3px solid #fff;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .22), 0 0 0 1px rgba(0,0,0,.08);
  background:
    linear-gradient(45deg, #ccd5d8 25%, transparent 25%),
    linear-gradient(-45deg, #ccd5d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccd5d8 75%),
    linear-gradient(-45deg, transparent 75%, #ccd5d8 75%);
  background-color: #fff;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  z-index: 20;
  transition: opacity .15s ease;
}

.magnifier::after {
  content: "";
  position: absolute;
  inset: 50%;
  width: 14px;
  height: 14px;
  translate: -50% -50%;
  border-left: 1px solid rgba(255, 255, 255, .9);
  border-top: 1px solid rgba(255, 255, 255, .9);
  box-shadow: 7px 7px 0 -6px rgba(255, 255, 255, .9);
}

.magnifier-content {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.magnifier-content img,
.magnifier-content .svg-layer,
.magnifier-content .line-layer {
  position: absolute;
  inset: 0;
}

.magnifier-label {
  position: absolute;
  bottom: 16px;
  left: 50%;
  translate: -50% 0;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  translate: -50% 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.20);
  z-index: 100;
  animation: toastIn .3s ease, toastOut .3s ease 2.5s forwards;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -12px); }
}

.status {
  margin: 0;
  padding: 11px 16px;
  min-height: 40px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.is-hidden {
  display: none !important;
}

.magnifier-visible {
  opacity: 1;
  transition: opacity .12s ease;
}

.magnifier-hidden {
  opacity: 0;
  transition: opacity .12s ease;
}

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

  .workspace {
    grid-template-columns: 1fr;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 14px;
    padding: 16px;
  }

  .stage-panel {
    min-height: 60vh;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .magnifier {
    width: 160px;
    height: 160px;
  }
}
