* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(340px, 0.9fr);
  align-items: start;
}

.workspace-pane {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2.2vw, 1.35rem);
}

.control-pane {
  display: grid;
  gap: 1rem;
}

.panel {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2vw, 1.2rem);
}

.engine-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.35rem 0.62rem;
  border: 1px solid rgba(15, 148, 140, 0.24);
  border-radius: 999px;
  color: var(--teal-dark);
  background: rgba(15, 148, 140, 0.08);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.promise-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(15, 148, 140, 0.22);
  border-radius: 8px;
  background: rgba(237, 246, 243, 0.72);
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.promise-strip strong {
  color: var(--ink);
  font-weight: 900;
}

.promise-strip a {
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-weight: 900;
  text-decoration: none;
}

.drop-zone {
  position: relative;
  display: grid;
  min-height: 170px;
  border: 2px dashed rgba(15, 148, 140, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 148, 140, 0.08), transparent),
    rgba(255, 253, 250, 0.68);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.drop-zone.dragging {
  border-color: var(--teal);
  background: rgba(237, 246, 243, 0.92);
  transform: translateY(-1px);
}

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

.drop-label {
  display: grid;
  place-items: center;
  gap: 0.45rem;
  min-height: 100%;
  padding: 1.4rem;
  text-align: center;
  cursor: pointer;
}

.drop-icon {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 8px;
  background:
    linear-gradient(180deg, transparent 0 30%, var(--teal) 30% 48%, transparent 48%),
    linear-gradient(90deg, transparent 0 30%, var(--teal) 30% 48%, transparent 48%),
    rgba(15, 148, 140, 0.12);
}

.drop-title {
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 950;
}

.drop-note {
  max-width: 52rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.workspace-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.workspace-stats div {
  min-width: 0;
  padding: 0.78rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.72);
}

.workspace-stats span,
.card-meta,
.helper-text {
  color: var(--muted);
  font-size: 0.82rem;
}

.workspace-stats strong {
  display: block;
  margin-top: 0.2rem;
  color: var(--ink);
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  line-height: 1;
}

.action-row,
.preset-row,
.batch-bar,
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  min-width: 0;
}

.button,
.preset,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.45rem;
  border: 1px solid rgba(23, 33, 31, 0.14);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.button {
  padding: 0.64rem 0.88rem;
}

.button.primary {
  border-color: rgba(10, 96, 92, 0.4);
  background: var(--teal);
  color: white;
}

.button.ghost {
  background: transparent;
}

.button:disabled,
.mini-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.button-icon {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
}

.convert-icon {
  background:
    linear-gradient(90deg, transparent 0 15%, currentColor 15% 85%, transparent 85%) 50% 24% / 100% 18% no-repeat,
    linear-gradient(90deg, transparent 0 15%, currentColor 15% 85%, transparent 85%) 50% 76% / 100% 18% no-repeat,
    linear-gradient(135deg, transparent 0 50%, currentColor 50% 70%, transparent 70%) 100% 24% / 50% 50% no-repeat,
    linear-gradient(315deg, transparent 0 50%, currentColor 50% 70%, transparent 70%) 0 76% / 50% 50% no-repeat;
}

.download-icon {
  background:
    linear-gradient(currentColor 0 0) 50% 10% / 18% 52% no-repeat,
    linear-gradient(135deg, transparent 0 42%, currentColor 42% 62%, transparent 62%) 50% 60% / 70% 46% no-repeat,
    linear-gradient(currentColor 0 0) 50% 90% / 82% 16% no-repeat;
}

.zip-icon {
  border: 2px solid currentColor;
  border-radius: 2px;
  background:
    linear-gradient(currentColor 0 0) 50% 0 / 20% 100% no-repeat,
    repeating-linear-gradient(180deg, transparent 0 13%, currentColor 13% 20%);
}

.reset-icon {
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}

.preset,
.mini-button {
  padding: 0.5rem 0.7rem;
  font-size: 0.86rem;
}

.preset {
  background: rgba(237, 246, 243, 0.78);
}

.empty-state {
  display: grid;
  gap: 0.4rem;
  padding: clamp(1rem, 2.4vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.62);
}

.empty-state h2,
.empty-state p {
  margin: 0;
}

.empty-state h2 {
  font-size: clamp(1.2rem, 2.5vw, 1.65rem);
}

.empty-state p {
  color: var(--muted);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}

.image-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.86);
}

.card-preview {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background:
    linear-gradient(45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    #eee9de;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.card-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-check {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(255, 253, 250, 0.9);
  box-shadow: 0 8px 22px rgba(23, 33, 31, 0.18);
}

.card-badge {
  position: absolute;
  right: 0.55rem;
  bottom: 0.55rem;
  max-width: calc(100% - 1.1rem);
  padding: 0.32rem 0.5rem;
  border-radius: 999px;
  background: rgba(23, 33, 31, 0.84);
  color: white;
  font-size: 0.75rem;
  font-weight: 900;
}

.card-body {
  display: grid;
  gap: 0.42rem;
  padding: 0.78rem;
  min-width: 0;
}

.card-name {
  overflow: hidden;
  color: var(--ink);
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  display: grid;
  gap: 0.18rem;
}

.card-error {
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 850;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  padding: 0 0.78rem 0.78rem;
}

.card-actions .mini-button {
  min-height: 2.2rem;
}

.card-actions .danger {
  color: var(--red);
}

.field-grid {
  display: grid;
  gap: 0.8rem;
}

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

.field,
.checkline {
  min-width: 0;
}

.field {
  display: grid;
  gap: 0.38rem;
}

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

.field span,
.checkline span {
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 900;
}

.field input,
.field select {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.field input:not([type="range"]):not([type="color"]),
.field select {
  padding: 0.54rem 0.66rem;
}

.field input[type="range"] {
  accent-color: var(--teal);
}

.field input[type="color"] {
  padding: 0.2rem;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.55rem;
  padding: 0.54rem 0.66rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.62);
}

.checkline input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--teal);
}

.helper-text {
  margin: 0;
}

.image-topbar-actions {
  flex: 1 1 auto;
  gap: 0.7rem;
}

.tool-switcher {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.78);
}

.tool-switcher-link {
  display: grid;
  gap: 0.12rem;
  min-width: 9.8rem;
  padding: 0.5rem 0.64rem;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink-soft);
  text-decoration: none;
}

.tool-switcher-link strong,
.tool-switcher-link span {
  display: block;
  line-height: 1.12;
}

.tool-switcher-link strong {
  color: inherit;
  font-size: 0.88rem;
  font-weight: 950;
}

.tool-switcher-link span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.tool-switcher-link:hover,
.tool-switcher-link:focus-visible {
  border-color: rgba(15, 148, 140, 0.24);
  color: var(--teal-dark);
  background: rgba(15, 148, 140, 0.08);
  outline: none;
}

.tool-switcher-link.active {
  border-color: rgba(15, 148, 140, 0.3);
  color: var(--teal-dark);
  background: rgba(15, 148, 140, 0.13);
}

.guarantee-pills {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.guarantee-pills .status-pill {
  min-height: 1.9rem;
  cursor: default;
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(520px, 1.15fr) minmax(340px, 0.85fr);
  align-items: start;
}

.editor-pane {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2.2vw, 1.35rem);
}

.editor-drop {
  position: relative;
  display: grid;
  min-height: 190px;
  border: 2px dashed rgba(15, 148, 140, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 148, 140, 0.08), transparent),
    rgba(255, 253, 250, 0.68);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.editor-drop.dragging {
  border-color: var(--teal);
  background: rgba(237, 246, 243, 0.92);
  transform: translateY(-1px);
}

.editor-workbench {
  display: grid;
  gap: 1rem;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.editor-stage {
  position: relative;
  height: clamp(360px, 58vw, 700px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    #eee9de;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.editor-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.crop-box {
  position: absolute;
  min-width: 20px;
  min-height: 20px;
  border: 2px solid #ffffff;
  box-shadow:
    0 0 0 1px rgba(10, 96, 92, 0.9),
    0 12px 34px rgba(23, 33, 31, 0.22);
  cursor: move;
  touch-action: none;
}

.crop-box::before,
.crop-box::after {
  content: "";
  position: absolute;
  inset: 33.333% 0 33.333% 0;
  border-top: 1px solid rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid rgba(255, 255, 255, 0.78);
  pointer-events: none;
}

.crop-box::after {
  inset: 0 33.333% 0 33.333%;
  border: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.78);
  border-right: 1px solid rgba(255, 255, 255, 0.78);
}

.crop-handle {
  position: absolute;
  z-index: 1;
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--teal-dark);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(23, 33, 31, 0.22);
}

.crop-handle.nw,
.crop-handle.n,
.crop-handle.ne {
  top: -0.48rem;
}

.crop-handle.sw,
.crop-handle.s,
.crop-handle.se {
  bottom: -0.48rem;
}

.crop-handle.nw,
.crop-handle.w,
.crop-handle.sw {
  left: -0.48rem;
}

.crop-handle.ne,
.crop-handle.e,
.crop-handle.se {
  right: -0.48rem;
}

.crop-handle.n,
.crop-handle.s {
  left: calc(50% - 0.425rem);
}

.crop-handle.w,
.crop-handle.e {
  top: calc(50% - 0.425rem);
}

.crop-handle.nw,
.crop-handle.se {
  cursor: nwse-resize;
}

.crop-handle.ne,
.crop-handle.sw {
  cursor: nesw-resize;
}

.crop-handle.n,
.crop-handle.s {
  cursor: ns-resize;
}

.crop-handle.e,
.crop-handle.w {
  cursor: ew-resize;
}

.editor-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.editor-meta div {
  min-width: 0;
  padding: 0.78rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.72);
}

.editor-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.editor-meta strong {
  display: block;
  margin-top: 0.18rem;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(0.9rem, 1.5vw, 1.05rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.output-preview {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2vw, 1.2rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.74);
}

.output-canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(23, 33, 31, 0.055) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(23, 33, 31, 0.055) 75%),
    #eee9de;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.output-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.editor-controls .button[href] {
  width: fit-content;
}

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

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions,
  .image-topbar-actions,
  .guarantee-pills {
    justify-content: flex-start;
  }

  .image-topbar-actions {
    align-items: stretch;
    width: 100%;
  }

  .tool-switcher {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .tool-switcher-link {
    min-width: 0;
  }

  .workspace-stats,
  .editor-meta,
  .field-grid.two {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .editor-stage {
    height: 430px;
  }
}

@media (max-width: 460px) {
  .workspace-stats,
  .editor-meta,
  .field-grid.two {
    grid-template-columns: 1fr;
  }

  .action-row .button,
  .preview-toolbar .mini-button,
  .preset,
  .mini-button {
    width: 100%;
  }

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

  .editor-stage {
    height: 360px;
  }
}
