:root {
  color-scheme: light;
  --bg: #eef1f3;
  --surface: #fbfcfd;
  --surface-2: #f4f6f7;
  --ink: #162025;
  --muted: #68757b;
  --line: #d9e0e4;
  --line-strong: #b8c5ca;
  --green: #1f8f62;
  --green-2: #e6f5ee;
  --blue: #285fbd;
  --blue-2: #e8effb;
  --amber: #9b6b15;
  --amber-2: #fff4db;
  --red: #b43b3b;
  --shadow: 0 16px 46px rgba(31, 43, 49, 0.12);
  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: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

canvas {
  display: block;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 253, 0.94);
  box-shadow: var(--shadow);
}

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

.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 34%, var(--blue-2) 34% 66%, transparent 66%),
    linear-gradient(0deg, transparent 0 34%, var(--green-2) 34% 66%, transparent 66%),
    #fff;
}

.brand-mark::after {
  position: absolute;
  inset: 8px;
  border: 2px solid var(--blue);
  border-radius: 4px;
  content: "";
}

.brand h1,
.output-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.output-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.button,
.ghost-button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
  line-height: 1;
}

.button {
  padding: 0 14px;
}

.button.mini {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.button:hover,
.ghost-button:hover {
  border-color: #8ba6b2;
}

.button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button.primary {
  border-color: #9ab4e4;
  background: var(--blue-2);
  color: #17427f;
}

.button.strong {
  border-color: #9ac8b3;
  background: var(--green-2);
  color: #126143;
}

.button.image {
  border-color: #d5ba76;
  background: var(--amber-2);
  color: var(--amber);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 94px);
}

.input-panel,
.output-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: #314047;
  cursor: pointer;
  font-weight: 700;
}

.drop-zone.dragging {
  border-color: var(--blue);
  background: var(--blue-2);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.preview-wrap {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #e1e6e9 25%, transparent 25%),
    linear-gradient(-45deg, #e1e6e9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e1e6e9 75%),
    linear-gradient(-45deg, transparent 75%, #e1e6e9 75%),
    #f8fafb;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #87939a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.field {
  display: grid;
  grid-template-columns: 72px 1fr 48px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.field span,
.field output {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.field output {
  text-align: right;
}

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

.select-field {
  grid-template-columns: 72px 1fr;
}

.select-field select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #344149;
  font-size: 13px;
  font-weight: 700;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.switch span {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #c9d2d7;
  transition: background 0.16s ease;
}

.switch span::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  content: "";
  transition: transform 0.16s ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.ghost-button {
  padding: 0 12px;
  background: transparent;
}

.status-line {
  min-height: 36px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #edf2f4;
  color: #546169;
  font-size: 12px;
}

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

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

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #435159;
  font-size: 12px;
}

.progress-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-meta strong {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 12px;
}

.progress-track {
  position: relative;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9ec;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 0.22s ease;
}

.progress-fill.indeterminate {
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent),
    linear-gradient(90deg, var(--blue), var(--green));
  background-size:
    68px 100%,
    100% 100%;
  animation: progress-sheen 1.1s linear infinite;
}

@keyframes progress-sheen {
  from {
    background-position:
      -68px 0,
      0 0;
  }
  to {
    background-position:
      68px 0,
      0 0;
  }
}

.output-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.output-head h2 {
  font-size: 17px;
}

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

.meter {
  display: grid;
  place-items: center;
  min-width: 64px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.meter span {
  color: var(--green);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.meter small {
  color: var(--muted);
  font-size: 11px;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.asset-card {
  display: grid;
  grid-template-rows: 180px 152px;
  min-width: 0;
  height: 334px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.asset-thumb {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  height: 180px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f3 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f3 75%),
    #fff;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
  cursor: zoom-in;
}

.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.asset-thumb:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.asset-thumb-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 7px;
  border: 1px solid rgba(184, 197, 202, 0.8);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #23404d;
  font-size: 11px;
  font-weight: 800;
  opacity: 0;
  transform: translateY(3px);
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}

.asset-thumb:hover .asset-thumb-badge,
.asset-thumb:focus-visible .asset-thumb-badge {
  opacity: 1;
  transform: translateY(0);
}

.asset-meta {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: 20px 18px 1fr;
  gap: 8px;
  padding: 10px;
  min-width: 0;
  background: #fff;
}

.asset-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.asset-title strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--green-2);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.chip.enhanced {
  background: var(--amber-2);
  color: var(--amber);
}

.asset-detail {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 7px;
  min-width: 0;
}

.download-row button {
  min-width: 0;
  min-height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: #23404d;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.1;
  white-space: nowrap;
}

.download-row button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.download-row button.turnaround {
  border-color: #d5ba76;
  color: var(--amber);
}

.asset-empty {
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.asset-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 26, 32, 0.58);
}

.asset-preview-modal[hidden] {
  display: none;
}

.asset-preview-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.22);
}

.asset-preview-head,
.asset-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.asset-preview-head {
  border-bottom: 1px solid var(--line);
}

.asset-preview-head h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.asset-preview-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.asset-preview-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: #fff;
  color: #314047;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.asset-preview-stage {
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f3 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f3 75%),
    #fff;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.asset-preview-stage img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 220px);
  object-fit: contain;
}

.asset-preview-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.asset-preview-actions button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: #23404d;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.asset-preview-actions button:last-child {
  border-color: #d5ba76;
  color: var(--amber);
}

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

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

  .actions {
    justify-content: stretch;
  }

  .actions .button {
    flex: 1;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

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

  .asset-preview-modal {
    padding: 12px;
  }

  .asset-preview-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
