:root {
  color-scheme: dark;
  --green: #ccff00;
  --black: #1c180d;
  --text: #ffffff;
  --heather-1: #d4d0c9;
  --heather-2: #b4b1ab;
  --heather-3: #8a8783;
  --muted: var(--heather-2);
  --line: rgba(212, 208, 201, 0.2);
  --surface: #262219;
  --grid-line: rgba(204, 255, 0, 0.035);
  --shadow: 0 20px 60px rgba(8, 7, 3, 0.55);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--black);
}

body {
  min-height: 100%;
  margin: 0;
  background-color: var(--black);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-position: 28px 28px;
  background-size: 72px 72px;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body::before {
  position: fixed;
  z-index: 9999;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='.35'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  content: "";
  mix-blend-mode: soft-light;
  opacity: 0.035;
  pointer-events: none;
}

::selection {
  background: var(--green);
  color: var(--black);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  border-radius: 4px;
}

button {
  min-height: 42px;
  border: 1px solid var(--heather-1);
  background: var(--heather-1);
  color: var(--black);
  cursor: pointer;
  font-weight: 700;
}

.secondary-button {
  border-color: var(--heather-3);
  background: var(--black);
  color: var(--heather-1);
}

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

button:not(:disabled):hover {
  background: var(--green);
  border-color: var(--green);
  color: var(--black);
}

#downloadImage:not(:disabled) {
  animation: download-pulse 1.8s ease-in-out infinite;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.app-shell {
  width: min(1520px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
}

.app-header {
  margin-bottom: 24px;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.8rem);
  font-weight: 600;
  line-height: 0.88;
  letter-spacing: -0.055em;
}

h2 {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.workspace {
  display: grid;
  min-height: calc(100vh - 170px);
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 20px;
}

.control-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--black);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.upload-target {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 88px;
  border: 1px dashed var(--green);
  border-radius: 4px;
  padding: 16px;
  background: var(--surface);
  cursor: pointer;
}

.upload-target.dragging {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--green);
}

.is-dragging .preview-stage {
  box-shadow: inset 0 0 0 3px var(--green);
}

.upload-target input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 4px;
  background: var(--green);
  color: var(--black);
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}

.upload-target strong,
.upload-target small {
  display: block;
}

.upload-target small {
  margin-top: 2px;
  color: var(--muted);
}

.control-group {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.segmented span {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 2px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--green);
  color: var(--black);
}

.stacked-control,
.range-control,
.check-control {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.check-control {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
  cursor: pointer;
}

.check-control input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--green);
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
}

select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--black);
  color: var(--text);
  padding: 0 10px;
}

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

input[type="range"]:disabled {
  opacity: 0.45;
}

output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: auto;
}

#preparePfp {
  display: flex;
  align-items: center;
  justify-content: center;
  grid-column: 1 / -1;
  gap: 0.38em;
}

.x-logo {
  width: 0.86em;
  height: 0.88em;
  flex: 0 0 auto;
  fill: currentColor;
}

@keyframes download-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 0 rgba(204, 255, 0, 0),
      0 0 0 rgba(204, 255, 0, 0);
  }

  50% {
    border-color: var(--green);
    box-shadow:
      0 0 0 4px rgba(204, 255, 0, 0.18),
      0 0 18px rgba(204, 255, 0, 0.55);
  }
}

.preview-panel {
  display: grid;
  min-width: 0;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-toolbar p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-toolbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.preview-download-button {
  min-height: 34px;
  flex: 0 0 auto;
  border-color: var(--green);
  padding: 0 14px;
  background: var(--green);
  color: var(--black);
  font-size: 0.82rem;
  white-space: nowrap;
}

.preview-stage {
  position: relative;
  display: grid;
  min-height: 520px;
  place-items: center;
  overflow: auto;
  background: var(--black);
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-width: min(430px, calc(100% - 40px));
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 28px;
  background: var(--surface);
  text-align: center;
}

.empty-state strong {
  color: var(--green);
  font-size: 1.35rem;
}

.canvas-stack {
  display: none;
  position: relative;
  max-width: calc(100% - 32px);
  max-height: calc(100vh - 245px);
}

canvas {
  display: none;
  background: var(--black);
  image-rendering: auto;
}

.canvas-stack canvas {
  max-width: 100%;
  max-height: calc(100vh - 245px);
}

pre {
  display: none;
  min-width: max-content;
  max-width: none;
  margin: 0;
  padding: 24px;
  background: var(--black);
  color: var(--green);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 8px;
  line-height: 1;
  white-space: pre;
}

.has-image .empty-state {
  display: none;
}

.mode-image .canvas-stack {
  display: grid;
}

.mode-image .canvas-stack canvas {
  grid-area: 1 / 1;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  #downloadImage:not(:disabled) {
    animation: none;
    box-shadow: 0 0 0 4px rgba(204, 255, 0, 0.18);
  }
}

.mode-ascii pre {
  display: block;
}

.crop-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  background: var(--black);
  color: var(--text);
  box-shadow: var(--shadow);
}

.crop-dialog::backdrop {
  background: rgba(28, 24, 13, 0.82);
}

.crop-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.crop-dialog-header h2 {
  margin: 0;
}

.crop-stage {
  display: grid;
  max-height: min(540px, calc(100vh - 260px));
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

#cropCanvas {
  display: block;
  max-width: 100%;
  cursor: grab;
  touch-action: none;
}

#cropCanvas.is-dragging {
  cursor: grabbing;
}

@media (max-width: 880px) {
  .app-shell {
    padding: 18px;
  }

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

  .preview-stage {
    min-height: 420px;
  }

  canvas {
    max-height: none;
  }

  .canvas-stack,
  .canvas-stack canvas {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 12px;
  }

  .button-row,
  .segmented {
    grid-template-columns: 1fr;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
    justify-content: center;
    padding: 12px;
  }

  .preview-toolbar-actions {
    justify-content: space-between;
  }
}
