:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --panel-soft: #f8faf8;
  --ink: #171717;
  --muted: #6f6b63;
  --line: #d9d4ca;
  --line-strong: #b8b0a3;
  --accent: #147a75;
  --accent-strong: #0f5d59;
  --amber: #c27c12;
  --coral: #d95f45;
  --violet: #6d5bd0;
  --green: #2c7d49;
  --shadow: 0 20px 60px rgba(31, 28, 21, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(246, 244, 239, 0.72)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(20, 122, 117, 0.22);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav-item {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.side-nav-item.active,
.side-nav-item:hover {
  background: #efede7;
  color: var(--ink);
}

.usage-box,
.queue-box {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.usage-box {
  margin-top: auto;
}

.usage-box strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.usage-box p,
.queue-box p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.usage-meter {
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1ddd4;
}

.usage-meter span {
  display: block;
  width: 58%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--amber));
}

.workspace {
  min-width: 0;
  padding: 24px clamp(18px, 3vw, 40px) 38px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: clamp(24px, 3vw, 40px);
  line-height: 1.05;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-pill.good {
  border-color: rgba(44, 125, 73, 0.25);
  background: rgba(44, 125, 73, 0.1);
  color: var(--green);
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.primary-button:hover {
  background: #000;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.secondary-button:hover,
.ghost-button:hover {
  background: #efede7;
}

.ghost-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}

.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.step-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(76px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.step-tab {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-weight: 850;
}

.step-tab.active {
  background: var(--ink);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.two-column,
.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.78fr);
  gap: 14px;
  align-items: stretch;
}

.tool-panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.canvas-panel {
  padding: 16px;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.drop-zone {
  position: relative;
  display: grid;
  gap: 10px;
  place-items: center;
  min-height: 370px;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, #f2f1ee 25%, transparent 25%),
    linear-gradient(-45deg, #f2f1ee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f2f1ee 75%),
    linear-gradient(-45deg, transparent 75%, #f2f1ee 75%);
  background-color: #fbfaf8;
  background-position:
    0 0,
    0 12px,
    12px -12px,
    -12px 0;
  background-size: 24px 24px;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px rgba(20, 122, 117, 0.12);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

canvas {
  max-width: 100%;
  border-radius: 6px;
}

#sourceCanvas {
  width: min(360px, 100%);
  height: auto;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stat-tile {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  min-width: 0;
}

.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.stat-tile strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: clamp(15px, 1.4vw, 19px);
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
}

.field span,
.range-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.field input,
.field select {
  min-height: 46px;
  padding: 0 12px;
}

.field textarea {
  resize: vertical;
  min-height: 118px;
  padding: 12px;
  line-height: 1.5;
}

.toggle-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.toggle-field span {
  grid-column: 1 / -1;
}

.toggle-field input {
  width: 46px;
  min-height: 26px;
  accent-color: var(--accent);
}

.toggle-field em {
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.control-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-row {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}

.mask-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.role-button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.role-button.active[data-role="transform"] {
  border-color: rgba(20, 122, 117, 0.45);
  background: rgba(20, 122, 117, 0.12);
  color: var(--accent-strong);
}

.role-button.active[data-role="procedural"] {
  border-color: rgba(194, 124, 18, 0.45);
  background: rgba(194, 124, 18, 0.13);
  color: #8c5708;
}

.role-button.active[data-role="refine"] {
  border-color: rgba(109, 91, 208, 0.45);
  background: rgba(109, 91, 208, 0.13);
  color: #4f41a6;
}

.role-button.active[data-role="locked"] {
  border-color: rgba(217, 95, 69, 0.45);
  background: rgba(217, 95, 69, 0.13);
  color: #a6402d;
}

.range-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.range-field input {
  width: 110px;
  accent-color: var(--accent);
}

#maskCanvas,
#pathCanvas,
#previewCanvas {
  width: 100%;
  background: #fbfaf8;
  border: 1px solid var(--line);
}

#sheetCanvas {
  width: 100%;
  min-height: 210px;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, #ece9e2 25%, transparent 25%),
    linear-gradient(-45deg, #ece9e2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ece9e2 75%),
    linear-gradient(-45deg, transparent 75%, #ece9e2 75%);
  background-color: #fff;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.layer-list {
  display: grid;
  gap: 10px;
}

.layer-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.layer-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.layer-row strong,
.layer-row span {
  display: block;
}

.layer-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.role-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: #efede7;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.anchor-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.anchor-box strong {
  display: block;
  margin-top: 7px;
}

.anchor-box p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.code-panel {
  min-height: 272px;
  margin: 0;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #151515;
  color: #f1f0eb;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.frame-strip,
.timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.frame-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.frame-button.active {
  background: var(--ink);
  color: #fff;
}

.frame-button.key {
  border-color: rgba(20, 122, 117, 0.42);
  background: rgba(20, 122, 117, 0.08);
  color: var(--accent-strong);
}

.frame-button.active.key {
  background: var(--ink);
  color: #fff;
}

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

.action-grid button {
  min-height: 58px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-weight: 760;
}

.action-grid button:hover {
  border-color: var(--accent);
}

.version-list {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.version-list p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.qa-list,
.fix-list {
  display: grid;
  gap: 10px;
}

.qa-row,
.fix-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.fix-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.qa-row strong,
.qa-row span,
.fix-row strong,
.fix-row span {
  display: block;
}

.qa-row span,
.fix-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.qa-value {
  color: var(--ink);
  font-weight: 850;
}

.qa-status {
  min-width: 54px;
  padding: 6px 8px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 850;
}

.qa-status.ok {
  background: rgba(44, 125, 73, 0.12);
  color: var(--green);
}

.qa-status.warn {
  background: rgba(194, 124, 18, 0.14);
  color: #8c5708;
}

.qa-status.fix {
  background: rgba(217, 95, 69, 0.14);
  color: #a6402d;
}

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

.fix-cost {
  min-width: 70px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.package-line {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

#panel-export .control-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#panel-export .control-grid .field:first-child {
  grid-column: 1 / -1;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(14px);
  max-width: min(420px, calc(100vw - 44px));
  padding: 13px 15px;
  border: 1px solid rgba(20, 122, 117, 0.22);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition:
    transform 160ms ease,
    opacity 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.owner-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 23, 23, 0.42);
  backdrop-filter: blur(8px);
}

.owner-overlay.hidden {
  display: none;
}

.owner-card {
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.22);
}

.owner-card h2 {
  margin: 4px 0 8px;
  font-size: 26px;
}

.owner-card p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
}

.owner-error {
  min-height: 20px;
  margin-top: 12px;
  color: #a6402d;
  font-size: 13px;
  font-weight: 750;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(260px, 2fr);
    align-items: start;
  }

  .side-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-column: 1 / -1;
  }

  .usage-box,
  .queue-box {
    margin-top: 0;
  }

  .two-column,
  .editor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 18px 14px 30px;
  }

  .sidebar {
    padding: 16px;
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

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

  .control-grid,
  .control-grid.compact,
  .stat-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .qa-row {
    grid-template-columns: 1fr auto;
  }

  .qa-row .qa-status {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
