:root {
  color-scheme: light;
  --ink: #15171a;
  --muted: #64717f;
  --line: #d9e0e6;
  --surface: #ffffff;
  --field: #f4f7f9;
  --accent: #0f8b8d;
  --accent-dark: #0a6567;
  --warn: #b35300;
  --danger: #b3261e;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #edf2f4;
  color: var(--ink);
}

body.is-busy {
  cursor: progress;
}

button,
input {
  font: inherit;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  min-height: 100vh;
}

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

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  overflow-y: auto;
}

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

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 10px;
  box-shadow: 0 6px 14px rgba(21, 23, 26, 0.12);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.brand p,
.drop-copy,
.status span,
small,
output,
header span {
  color: var(--muted);
  font-size: 12px;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 18px;
  min-height: 126px;
  justify-content: center;
  border: 1px dashed #9fb1bd;
  border-radius: 8px;
  background: var(--field);
  cursor: pointer;
}

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

.drop-zone input {
  display: none;
}

.drop-title {
  font-weight: 700;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-grid label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 8px;
  align-items: center;
}

.control-grid label > span {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 650;
}

.field-help > span {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.control-grid input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  padding: 9px 10px;
}

.control-grid input[type="range"] {
  grid-column: 1 / -1;
  accent-color: var(--accent);
}

.toggles {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.toggles label {
  display: flex;
  gap: 9px;
  align-items: center;
  font-size: 13px;
}

.toggles input {
  accent-color: var(--accent);
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: var(--ink);
  color: white;
  font-weight: 750;
  cursor: pointer;
}

.actions button:nth-child(2) {
  background: #243746;
}

.actions button:nth-child(3) {
  background: var(--accent);
}

button:hover:not(:disabled) {
  filter: brightness(0.94);
}

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

.status {
  display: grid;
  gap: 6px;
  padding: 13px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #f7fafb;
}

.status.warn {
  border-left-color: var(--warn);
}

.status.error {
  border-left-color: var(--danger);
}

.preview-area {
  min-width: 0;
  padding: 20px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.preview-strip {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(420px, 1fr);
  gap: 18px;
  height: calc(100vh - 96px);
}

.preview-column {
  display: grid;
  grid-template-rows: auto;
  min-height: 0;
}

.preview-column > .preview-card:first-child {
  align-self: start;
  max-height: min(58vh, 620px);
}

.actions-floating {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.preview-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.preview-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

#maskCanvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: 0;
  background:
    linear-gradient(45deg, #f2f5f7 25%, transparent 25%),
    linear-gradient(-45deg, #f2f5f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f5f7 75%),
    linear-gradient(-45deg, transparent 75%, #f2f5f7 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

#viewer {
  min-height: 420px;
}


.loading-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: start center;
  padding-top: 24px;
  background: rgba(237, 242, 244, 0.28);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 30;
}

.loading-shell.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-card {
  width: min(460px, calc(100vw - 28px));
  padding: 14px 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 14px 34px rgba(21, 23, 26, 0.12);
}

.loading-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
}

.loading-head strong {
  font-size: 14px;
}

.loading-head span,
.loading-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.loading-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #dce7eb;
}

.loading-bar {
  width: 42%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0f8b8d 0%, #58c1c3 100%);
  animation: loading-slide 1.1s ease-in-out infinite;
}

.loading-card p {
  margin-top: 10px;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-110%);
  }
  55% {
    transform: translateX(125%);
  }
  100% {
    transform: translateX(125%);
  }
}

@media (max-width: 980px) {
  .workspace,
  .preview-strip {
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: auto;
  }

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

  .preview-strip {
    height: auto;
  }

  #viewer {
    height: 520px;
  }
}

@media (max-width: 520px) {
  .controls-panel,
  .preview-area {
    padding: 14px;
  }

  .control-grid,
  .actions {
    grid-template-columns: 1fr;
  }

  .preview-strip {
    height: auto;
  }
}
