:root {
  color-scheme: light;
  --bg: #f6fbff;
  --panel: #ffffff;
  --panel-soft: #eef6ff;
  --line: #d8e7fb;
  --ink: #081b39;
  --muted: #64748b;
  --accent: #2678ff;
  --accent-strong: #1558d6;
  --accent-soft: #e9f3ff;
  --accent-sky: #26b8ff;
  --warm: #f5b31d;
  --danger: #9b2f2f;
  --shadow: 0 18px 46px rgba(30, 96, 190, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 10%, rgba(38, 184, 255, 0.18), transparent 30%),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 46%, #eef7ff 100%);
  color: var(--ink);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: 64px 42px minmax(0, 1fr) 24px;
  width: 100vw;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 178px;
  max-width: 248px;
}

.brand-logo {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand span:last-child {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-promo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #315176;
  text-decoration: none;
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.top-promo-mark {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #0f172a;
  color: #fff;
  font-size: 11px;
  font-weight: 780;
}

.top-promo:hover {
  border-color: #b6d3ff;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 800;
}

.icon-button:hover {
  border-color: #8dbdff;
  background: var(--accent-soft);
}

#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.file-protocol-warning {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid #d7a64f;
  background: #fff8e7;
  color: #2d271b;
  box-shadow: var(--shadow);
  padding: 16px;
}

.file-protocol-warning strong {
  font-size: 15px;
}

.file-protocol-warning span {
  color: #675f50;
  font-size: 13px;
  line-height: 1.55;
}

.file-protocol-warning a {
  justify-self: start;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 9px 12px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.tool-button,
.wide-button,
.button-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 11px;
  flex: 0 0 auto;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.tool-button span:first-child,
.wide-button span:first-child {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--accent);
  font-weight: 700;
}

.tool-button.icon-only {
  width: 46px;
  min-width: 46px;
  padding: 0;
}

.tool-button.icon-only span:first-child {
  width: 20px;
  height: 20px;
  font-size: 16px;
}

.tool-button:hover,
.tool-button.active,
.wide-button:hover:not(:disabled),
.button-row button:hover:not(:disabled) {
  border-color: #8dbdff;
  background: var(--accent-soft);
}

.tool-button:disabled,
.wide-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tool-button.primary {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent), #0fa4ff);
  color: #fff;
  box-shadow: 0 10px 24px rgba(38, 120, 255, 0.24);
}

.tool-button.primary span:first-child {
  color: #fff;
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  overflow: hidden;
}

.segmented-control label {
  display: grid;
  min-width: 0;
  cursor: pointer;
}

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

.segmented-control span {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
}

.segmented-control input:checked + span {
  background: linear-gradient(135deg, var(--accent), #0fa4ff);
  color: #fff;
}

.segmented-control input:focus-visible + span {
  outline: 2px solid rgba(38, 120, 255, 0.3);
  outline-offset: -2px;
}

.segmented-control input:disabled + span {
  cursor: not-allowed;
  opacity: 0.48;
}

.segmented-control.compact span {
  min-height: 38px;
  padding: 0 10px;
}

.shape-control {
  width: 100%;
}

.workflow-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--line);
  background: #dbeafe;
}

.workflow-strip li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 8px;
}

.workflow-strip li > span:first-child {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.workflow-strip li > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workflow-strip li.done {
  color: var(--accent-strong);
}

.workflow-strip li.done > span:first-child {
  border-color: #8dbdff;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.workflow-strip li.current {
  background: #edf6ff;
  color: var(--accent-strong);
}

.workflow-strip li.current > span:first-child {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 292px;
  min-height: 0;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
}

.help-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(30, 37, 36, 0.28);
}

.help-dialog form {
  margin: 0;
  padding: 18px;
}

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

.help-header h2 {
  margin: 0;
  font-size: 17px;
}

.help-dialog ol {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.inspector-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
  padding: 0 16px 18px;
  overflow: auto;
}

.layer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 760;
  letter-spacing: 0;
}

#layerCount {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 24px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.layer-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.layer-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f7fbff;
  color: var(--muted);
  padding: 16px;
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.layer-item {
  display: grid;
  grid-template-columns: 22px 28px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.layer-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.lock-toggle {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
}

.lock-toggle:hover:not(:disabled),
.lock-toggle.active {
  border-color: #8dbdff;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.lock-toggle svg {
  width: 16px;
  height: 16px;
}

.lock-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.layer-select {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  padding: 6px;
  text-align: left;
  cursor: pointer;
}

.layer-select:disabled {
  cursor: default;
  opacity: 0.62;
}

.layer-select canvas {
  width: 44px;
  height: 32px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 6px;
}

.layer-select span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}

.layer-select small {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.layer-item.selected .layer-select {
  border-color: #8dbdff;
  border-radius: 8px;
  background: var(--accent-soft);
}

.layer-item.locked .layer-select {
  color: var(--muted);
}

.layer-item.locked .layer-select canvas {
  opacity: 0.62;
}

.stage-shell {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.stage-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
}

#modeLabel {
  color: var(--accent-strong);
  font-weight: 720;
}

#statusText {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stage-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.scan-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.scan-progress[hidden] {
  display: none;
}

.scan-progress::before {
  content: "";
  grid-column: 1;
  grid-row: 1;
  height: 8px;
  border-radius: 999px;
  background: #dcecff;
  box-shadow: inset 0 1px 2px rgba(8, 27, 57, 0.08);
}

.scan-progress-bar {
  grid-column: 1;
  grid-row: 1;
  width: 0%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-sky));
  box-shadow: 0 4px 12px rgba(38, 120, 255, 0.28);
  transition: width 0.24s ease;
}

#scanProgressLabel {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 760;
  text-align: right;
}

.canvas-scroller {
  position: relative;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  background-color: #f7fbff;
  background-image:
    linear-gradient(45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.035) 75%);
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.canvas-scroller.drag-over {
  outline: 2px solid rgba(38, 120, 255, 0.42);
  outline-offset: -8px;
}

#stageCanvas {
  display: block;
  width: min(100%, 1536px);
  min-width: 240px;
  height: auto;
  margin: 0 auto;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.upload-empty {
  position: absolute;
  inset: 24px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.upload-empty[hidden] {
  display: none;
}

.upload-empty label {
  display: grid;
  gap: 9px;
  place-items: center;
  max-width: min(480px, 90%);
  border: 1px dashed #8dbdff;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 30px 34px;
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: auto;
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.upload-empty.drag-over label {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 18px 46px rgba(38, 120, 255, 0.22);
  transform: translateY(-1px);
}

.upload-empty strong {
  color: var(--ink);
  font-size: 18px;
}

.upload-empty span {
  font-size: 13px;
  line-height: 1.55;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.field input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(38, 120, 255, 0.16);
}

.field input:disabled,
.button-row button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

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

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  margin-top: 14px;
  color: var(--ink);
  font-size: 13px;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.wide-button {
  width: 100%;
  margin-top: 16px;
}

.wide-button.active {
  border-color: #8dbdff;
  background: var(--accent-soft);
}

.icon-wide-button {
  min-height: 42px;
}

.lock-icon {
  position: relative;
  width: 18px;
  height: 16px;
  color: var(--accent-strong);
}

.lock-icon::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0;
  width: 10px;
  height: 9px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.lock-icon::after {
  content: "";
  position: absolute;
  left: 2px;
  bottom: 0;
  width: 14px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 8px;
  margin-top: 20px;
}

.button-row button:last-child {
  border-color: #d9b9b9;
  color: var(--danger);
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-width: 760px;
    min-height: 760px;
    grid-template-rows: auto auto minmax(0, 1fr) 24px;
  }

  .workspace {
    grid-template-columns: 236px minmax(420px, 1fr) 252px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    height: auto;
    min-height: 86px;
    padding-block: 10px;
  }

  .top-promo {
    margin-left: auto;
  }

  .toolbar {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .workflow-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
