:root {
  color-scheme: dark;
  --bg: #050505;
  --bg-grid: rgba(255, 255, 255, 0.055);
  --ink: #f5f5f5;
  --muted: #a8a8a8;
  --line: #3b3b3b;
  --line-strong: #f2f2f2;
  --surface: #0b0b0b;
  --surface-raised: #141414;
  --accent: #ffffff;
  --accent-strong: #ffffff;
  --info: #e8e8e8;
  --warning: #cfcfcf;
  --danger: #ffffff;
  --shadow: rgba(255, 255, 255, 0.1);
  --font-terminal: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-terminal);
  font-size: 1rem;
  font-weight: 400;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  content: "";
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.035) 0,
    rgba(255, 255, 255, 0.035) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: screen;
}

.photopea-host {
  position: fixed;
  top: 0;
  left: -1200px;
  width: 1000px;
  height: 900px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.photopea-instance {
  position: absolute;
  inset: 0;
  width: 1000px;
  height: 900px;
}

.photopea-frame {
  width: 100%;
  height: 100%;
  border: 0;
}

button,
input,
fieldset {
  font: inherit;
}

button,
input {
  color: inherit;
}

.shell {
  min-height: 100svh;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 24px;
  min-height: calc(100svh - 48px);
}

.controls,
.stage {
  min-width: 0;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 34px var(--shadow);
}

.title-block {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  color: var(--info);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow::before {
  color: var(--accent);
  content: "$ ";
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--accent);
  font-size: clamp(34px, 4.5vw, 46px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.18);
}

h1::before {
  color: var(--muted);
  content: "./";
}

h2 {
  color: var(--ink);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0;
}

.output-title-gif {
  display: block;
  width: min(180px, 50vw);
  max-width: 50%;
  height: auto;
}

.subtitle {
  max-width: 34ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.subtitle::before {
  color: var(--warning);
  content: "# ";
}

.file-picker {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.file-picker span,
.layer-picker legend {
  color: var(--info);
}

.file-picker span::before,
.layer-picker legend::before {
  color: var(--accent);
  content: "> ";
}

.file-picker input {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-raised);
  color: var(--ink);
}

.file-picker input::file-selector-button {
  margin-right: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  text-transform: uppercase;
  cursor: pointer;
}

.file-picker input:focus,
.smart-object-select:focus,
.layers-list:focus-within,
.primary-button:focus-visible,
.download:focus-visible,
.output-preview-button:focus-visible,
.preview-modal-close:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.layer-picker {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.layer-picker legend {
  padding: 0;
  font-size: 13px;
  font-weight: 400;
}

.layers-list {
  display: grid;
  gap: 12px;
  max-height: 178px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 13px;
  scrollbar-color: var(--line-strong) var(--surface);
}

.layer-group {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.layer-group:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.layer-group-title {
  overflow-wrap: anywhere;
  color: var(--warning);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.layer-group-title::before {
  color: var(--accent);
  content: "template ";
}

.layer-empty {
  color: var(--danger);
  font-size: 12px;
  line-height: 1.35;
}

.smart-object-picker {
  display: grid;
  color: var(--ink);
  line-height: 1.35;
}

.smart-object-select {
  width: 100%;
  min-height: 40px;
  padding: 8px 34px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%) calc(100% - 17px) 17px / 6px 6px no-repeat,
    linear-gradient(135deg, var(--accent) 50%, transparent 50%) calc(100% - 11px) 17px / 6px 6px no-repeat,
    var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  appearance: none;
  cursor: pointer;
}

.smart-object-select:hover {
  border-color: var(--line-strong);
}

.primary-button,
.download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--surface-raised);
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.06);
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.primary-button::before,
.download:not(.icon-download)::before {
  content: "[ ";
}

.primary-button::after,
.download:not(.icon-download)::after {
  content: " ]";
}

.primary-button:hover,
.download:hover {
  border-color: var(--accent-strong);
  background: #1d1d1d;
  color: var(--accent-strong);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.08), 0 0 18px rgba(255, 255, 255, 0.08);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.status {
  min-height: 44px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status::before {
  color: var(--accent);
  content: "status: ";
}

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

.log {
  display: grid;
  gap: 7px;
  max-height: 180px;
  margin: 0;
  padding: 10px 10px 10px 32px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #050505;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  scrollbar-color: var(--line-strong) var(--surface);
}

.log li::marker {
  color: var(--accent);
}

.stage {
  display: flex;
  align-items: flex-start;
  min-height: 0;
}

.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  align-content: start;
  width: 100%;
  min-height: calc(100svh - 48px);
  padding: 22px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 0 34px var(--shadow);
}

.outputs {
  grid-column: 1 / -1;
  display: grid;
  gap: 22px;
  width: 100%;
  padding-bottom: 6px;
}

.output-section {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.output-section-title {
  overflow: hidden;
  color: var(--warning);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: clip;
  white-space: nowrap;
}

.output-section-title::before {
  color: var(--accent);
  content: "psd ";
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(var(--output-columns, 1), minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.output-item {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.output-preview {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
}

img.output-preview {
  background: #000000;
  object-fit: contain;
}

.output-preview-button {
  padding: 0;
  text-align: inherit;
  cursor: zoom-in;
}

.output-preview-button:hover {
  border-color: var(--line-strong);
}

.output-preview-image {
  display: block;
  width: 100%;
  height: 100%;
  background: #000000;
  object-fit: contain;
}

.output-item.is-running .output-preview {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.08);
}

.output-item.is-error .output-preview,
.output-item.is-error .output-size {
  border-color: var(--danger);
  color: var(--danger);
}

.output-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: center;
}

.output-name,
.output-size {
  font-size: 12px;
  line-height: 1.35;
}

.output-name {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--ink);
  font-weight: 400;
  text-overflow: clip;
  white-space: nowrap;
}

.output-name::before {
  color: var(--info);
  content: "file ";
}

.output-size {
  grid-column: 1;
  color: var(--muted);
  white-space: nowrap;
}

.output-size::before {
  color: var(--warning);
  content: "size ";
}

.output-detail .download {
  grid-row: 2;
  grid-column: 2;
  min-height: 24px;
  padding: 0 12px;
  font-size: 12px;
}

.output-detail .icon-download {
  width: 28px;
  min-height: 24px;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.output-detail .icon-download:hover {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.icon-download svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.preview-modal {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 24px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.preview-modal::backdrop {
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(2px);
}

.preview-modal-frame {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  place-items: center;
  width: 100%;
  height: 100%;
}

.preview-modal-image {
  display: block;
  max-width: min(100%, 1200px);
  max-height: calc(100dvh - 108px);
  border: 1px solid var(--line-strong);
  background: #000000;
  object-fit: contain;
  box-shadow: 0 0 36px rgba(255, 255, 255, 0.12);
}

.preview-modal-caption {
  max-width: min(100%, 960px);
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  text-overflow: clip;
  white-space: nowrap;
}

.preview-modal-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--surface-raised);
  color: var(--ink);
  cursor: pointer;
}

.preview-modal-close:hover {
  background: #1d1d1d;
}

.preview-modal-close svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

@media (max-width: 900px) {
  .shell {
    padding: 16px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .controls,
  .result {
    padding: 18px;
  }

  .result {
    min-height: auto;
  }

}

@media (max-width: 560px) {
  .shell {
    padding: 10px;
  }

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

  h1 {
    font-size: clamp(34px, 14vw, 48px);
  }

  .output-detail,
  .download:not(.icon-download) {
    grid-template-columns: 1fr;
    grid-row: auto;
    grid-column: auto;
    width: 100%;
  }

  .output-detail .icon-download {
    width: 28px;
    justify-self: end;
  }

  .output-detail .download {
    grid-row: 2;
    grid-column: 2;
  }
}
