:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #17233c;
  background: #f4f7fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --ink: #17233c;
  --muted: #718096;
  --line: #e4eaf2;
  --brand: #315ee8;
  --brand-dark: #254ac0;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 50% 0, rgba(49, 94, 232, 0.08), transparent 40rem),
    #f4f7fb;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  width: min(100% - 48px, 1060px);
  margin: 0 auto;
  padding: 66px 0 38px;
}

.intro {
  margin-bottom: 30px;
}

h1,
h2 {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: clamp(30px, 4vw, 40px);
  font-weight: 730;
  letter-spacing: -0.055em;
  line-height: 1.12;
  text-align: center;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  gap: 20px;
}

.card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(34, 54, 91, 0.045);
}

.upload-card,
.output-card {
  grid-column: 1;
  padding: 23px;
}

.output-card {
  grid-row: 2;
}

.card-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 20px;
}

.upload-card .card-heading {
  display: none;
}

.card-heading h2,
.preview-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
}

.file-picker {
  min-height: 92px;
  padding: 15px 16px;
  display: flex;
  align-items: center;
  gap: 13px;
  border: 1px dashed #c8d4e6;
  border-radius: 10px;
  background: #fafcff;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.file-picker:hover,
.file-picker:focus-within {
  border-color: var(--brand);
  background: #f5f8ff;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

#file-input:focus-visible+.file-picker {
  outline: 3px solid rgba(49, 94, 232, 0.22);
  outline-offset: 2px;
}

.upload-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #eaf0ff;
  color: var(--brand);
  font-size: 22px;
}

.file-picker-copy {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 4px;
}

.file-picker-copy strong {
  color: var(--ink);
  font-size: 13px;
}

.file-picker-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browse-button {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid #dce4f0;
  border-radius: 7px;
  background: #fff;
  color: #3a4b66;
  font-size: 11px;
  font-weight: 650;
}

.selected-file {
  overflow: hidden;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message {
  display: none;
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.5;
}

.error {
  color: #bd3333;
}

.output-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: -1px 0 14px;
}

.format-buttons {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
  padding: 3px;
  border: 1px solid #dce4f0;
  border-radius: 9px;
  background: #f4f7fb;
}

.format-button {
  min-height: 31px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #52627a;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.format-button:hover {
  color: var(--brand);
}

.format-button.is-selected {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(34, 54, 91, 0.16);
}

.format-button:focus-visible {
  outline: 3px solid rgba(49, 94, 232, 0.22);
  outline-offset: 2px;
}

.button {
  min-height: 39px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 670;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:not(:disabled):active {
  transform: translateY(1px);
}

.button-primary {
  background: var(--brand);
  color: #fff;
}

.button-primary:not(:disabled):hover {
  background: var(--brand-dark);
}

.button-secondary {
  border-color: #dce4f0;
  background: #fff;
  color: #354660;
}

.button-secondary:not(:disabled):hover {
  border-color: #b9c8df;
  background: #f8faff;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.code-output {
  width: 100%;
  min-height: 238px;
  padding: 14px;
  display: block;
  resize: vertical;
  border: 1px solid #202b3d;
  border-radius: 9px;
  outline: none;
  background: #111a29;
  color: #d9e4f5;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.65;
  tab-size: 2;
}

.code-output:focus-visible {
  border-color: #7393ff;
  box-shadow: 0 0 0 3px rgba(49, 94, 232, 0.13);
}

.copy-status {
  min-height: 17px;
  margin: 9px 0 0;
  color: #27805c;
  font-size: 11px;
  line-height: 1.5;
}

.preview-card {
  position: sticky;
  top: 20px;
  grid-column: 2;
  grid-row: 1 / span 2;
  padding: 20px;
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.preview-heading h2 {
  font-size: 22px;
  letter-spacing: -0.04em;
}

.preview-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid #d8e0ec;
  border-radius: 9px;
  background-color: #f8fafc;
  background-image: linear-gradient(45deg, #edf1f6 25%, transparent 25%),
    linear-gradient(-45deg, #edf1f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1f6 75%),
    linear-gradient(-45deg, transparent 75%, #edf1f6 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.preview-placeholder {
  color: #8b98aa;
  font-size: 11px;
  text-align: center;
}

.preview-placeholder::before {
  content: "Choose an image to preview";
}

.preview-canvas-container {
  position: absolute;
  inset: 0;
}

.preview-canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  object-fit: fill;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 32px, 560px);
    padding-top: 42px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-card {
    position: static;
    grid-column: 1;
    grid-row: auto;
  }

  .output-card {
    grid-row: auto;
  }

  .preview-frame {
    max-height: 220px;
  }
}

@media (max-width: 460px) {
  .app-shell {
    width: calc(100% - 28px);
    padding-top: 32px;
  }

  .upload-card,
  .output-card,
  .preview-card {
    padding: 17px;
  }

  .file-picker {
    gap: 9px;
    padding: 12px 10px;
  }

  .file-picker-copy span {
    max-width: 150px;
  }

  .browse-button {
    padding: 7px 8px;
  }

  .output-actions {
    flex-wrap: wrap;
  }

  .format-buttons {
    margin-left: 0;
  }
}