/* Pixel Art Generator (/pixel-art): a pixel-art workshop sketchbook. Warm
   graph paper, a light table for the selected drawing, and the gallery laid
   out on the same 75px grid the Stimulus controller uses for its tiles.
   Everything is scoped to .pxg. */

html:has(.pxg),
body:has(.pxg) {
  background: #f7f1e3;
  color: #2d2a26;
  color-scheme: light;
}

.pxg {
  --pxg-paper: #f7f1e3;
  --pxg-sheet: #fffdf7;
  --pxg-ink: #2d2a26;
  --pxg-ink-soft: #6b6359;
  --pxg-ink-faint: #9a9083;
  --pxg-line: rgba(70, 120, 175, 0.11);
  --pxg-line-major: rgba(70, 120, 175, 0.2);
  --pxg-accent: #d9583b;
  --pxg-accent-soft: rgba(217, 88, 59, 0.24);
  --pxg-pencil: #f2c14e;
  --pxg-tape: rgba(242, 214, 140, 0.78);
  --pxg-shadow: 0 1px 0 rgba(45, 42, 38, 0.06), 0 8px 24px -12px rgba(45, 42, 38, 0.28);
  --pxg-ui: "FF Meta", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --pxg-read: Charter, Georgia, ui-serif, serif;
  --pxg-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pxg-tile: 75px;

  display: block;
  min-height: 100svh;
  padding: 0 16px 40px;
  background-color: var(--pxg-paper);
  background-image:
    linear-gradient(var(--pxg-line-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--pxg-line-major) 1px, transparent 1px),
    linear-gradient(var(--pxg-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--pxg-line) 1px, transparent 1px);
  background-size: 125px 125px, 125px 125px, 25px 25px, 25px 25px;
  background-position: -1px -1px;
  color: var(--pxg-ink);
  font-family: var(--pxg-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

.pxg *,
.pxg *::before,
.pxg *::after {
  box-sizing: border-box;
}

.pxg img {
  image-rendering: pixelated;
  /* Hide alt text on images that fail to load; the frame shows instead. */
  color: transparent;
  font-size: 0;
}

.pxg a {
  color: inherit;
}

.pxg :focus-visible {
  outline: 3px solid var(--pxg-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Top bar ---------------------------------------------------------------- */

.pxg .pxg-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 0 0;
}

.pxg .pxg-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px 0 10px;
  margin-left: -10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  transition: background-color 120ms ease;
}

.pxg .pxg-home:hover {
  background: rgba(45, 42, 38, 0.06);
}

.pxg .pxg-home-arrow {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  background: var(--pxg-ink);
  color: var(--pxg-sheet);
  font-size: 14px;
  line-height: 1;
}

.pxg .pxg-topbar-tag {
  font-family: var(--pxg-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pxg-ink-faint);
  white-space: nowrap;
}

/* Hero ------------------------------------------------------------------- */

.pxg .pxg-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 0 32px;
}

@media (min-width: 860px) {
  .pxg .pxg-hero {
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    align-items: end;
    gap: 56px;
    padding: 56px 0 40px;
  }
}

.pxg .pxg-mark {
  display: block;
  width: 48px;
  height: 48px;
  margin-bottom: 18px;
}

.pxg .pxg-title {
  margin: 0;
  font-family: var(--pxg-ui);
  font-weight: 800;
  font-size: clamp(38px, 7vw, 64px);
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--pxg-ink);
}

.pxg .pxg-lede {
  max-width: 36em;
  margin: 18px 0 0;
  font-family: var(--pxg-read);
  font-size: clamp(17px, 2.2vw, 19px);
  line-height: 1.55;
  color: var(--pxg-ink-soft);
}

/* The sunset notice, pinned to the page like a note. */
.pxg .pxg-note {
  position: relative;
  max-width: 420px;
  padding: 26px 24px 22px;
  background: #fff6c9;
  color: #4a3f22;
  box-shadow: var(--pxg-shadow);
  transform: rotate(-1.2deg);
}

.pxg .pxg-note-tape {
  position: absolute;
  top: -11px;
  left: 50%;
  width: 96px;
  height: 22px;
  margin-left: -48px;
  background: var(--pxg-tape);
  transform: rotate(2deg);
  box-shadow: 0 1px 2px rgba(45, 42, 38, 0.08);
}

.pxg .pxg-note-kicker {
  margin: 0 0 6px;
  font-family: var(--pxg-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pxg-accent);
}

.pxg .pxg-note-body {
  margin: 0;
  font-family: var(--pxg-read);
  font-size: 17px;
  line-height: 1.5;
}

/* Workbench -------------------------------------------------------------- */

.pxg .pxg-workbench {
  max-width: 1080px;
  margin: 0 auto;
}

/* Light table: the selected drawing, one tile per model. */
.pxg .pxg-table {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 0 14px;
  background: linear-gradient(var(--pxg-paper) 80%, rgba(247, 241, 227, 0));
}

.pxg .pxg-table-surface {
  position: relative;
  padding: 22px 20px 18px;
  border: 1px solid rgba(45, 42, 38, 0.1);
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 50% 0%, #ffffff 0%, rgba(255, 255, 255, 0) 70%),
    var(--pxg-sheet);
  box-shadow: var(--pxg-shadow);
}

.pxg #pixel-art-result:empty {
  display: none;
}

.pxg .pxg-table-empty {
  display: none;
  margin: 0;
  padding: 26px 8px;
  text-align: center;
  font-family: var(--pxg-read);
  font-size: 17px;
  color: var(--pxg-ink-faint);
}

.pxg .pxg-table-surface:has(#pixel-art-result:empty) .pxg-table-empty {
  display: block;
}

.pxg #pixel-art-prompt-row {
  margin-bottom: 14px;
  gap: 4px;
}

.pxg #pixel-art-prompt-row > p {
  margin: 0;
  font-family: var(--pxg-read) !important;
  font-size: clamp(18px, 2.6vw, 23px);
  line-height: 1.3;
  color: var(--pxg-ink);
}

.pxg [data-download-icon] {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: var(--pxg-ink-faint);
  transition: background-color 120ms ease, color 120ms ease;
}

.pxg [data-download-icon]:hover {
  background: rgba(45, 42, 38, 0.06);
  color: var(--pxg-ink);
}

/* The controller sets an inline grid-template-columns sized for 180px cards.
   A flex row lets the cards shrink to fit three across on a phone. */
.pxg #pixel-art-result-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 14px;
}

.pxg #pixel-art-result-grid > * {
  flex: 0 0 min(200px, calc((100% - 28px) / 3));
  min-width: 0;
}

.pxg .pxg-card {
  width: 100%;
}

.pxg .pxg-card-frame {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 1;
  border-radius: 6px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #f1ece1 25%, transparent 25%, transparent 75%, #f1ece1 75%),
    linear-gradient(45deg, #f1ece1 25%, transparent 25%, transparent 75%, #f1ece1 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  box-shadow: 0 0 0 1px rgba(45, 42, 38, 0.12), 0 6px 14px -10px rgba(45, 42, 38, 0.5);
}

.pxg .pixel-art-model-name {
  margin: 6px 0 0;
  font-family: var(--pxg-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--pxg-ink-soft);
}

/* Gallery ---------------------------------------------------------------- */

.pxg .pxg-gallery {
  margin-top: 28px;
}

.pxg .pxg-gallery-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 24px;
  margin-bottom: 14px;
}

.pxg .pxg-gallery-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--pxg-ui);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.pxg .pxg-gallery-title::before {
  content: "";
  width: 12px;
  height: 12px;
  background: var(--pxg-accent);
  box-shadow: 12px 0 0 var(--pxg-pencil);
  margin-right: 12px;
}

.pxg .pxg-gallery-hint {
  max-width: 34em;
  margin: 0;
  font-size: 15px;
  color: var(--pxg-ink-soft);
}

.pxg .pxg-admin:not(.hidden) {
  display: flex;
  justify-content: center;
  padding-bottom: 14px;
}

.pxg .pxg-admin label {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(45, 42, 38, 0.15);
  border-radius: 999px;
  background: var(--pxg-sheet);
  font-size: 14px;
  color: var(--pxg-ink);
}

.pxg .pxg-gallery-sheet {
  padding: 0;
  border-radius: 14px;
  background: var(--pxg-sheet);
  box-shadow: var(--pxg-shadow);
  border: 1px solid rgba(45, 42, 38, 0.1);
  overflow: hidden;
}

/* The tile area is sized to whole 75px columns by the controller; the paper
   grid lines up with those tiles. */
.pxg .pxg-gallery-section {
  max-width: 100%;
  padding: 0;
}

.pxg .pxg-gallery-list {
  padding: 0;
  background-image:
    linear-gradient(var(--pxg-line-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--pxg-line-major) 1px, transparent 1px);
  background-size: var(--pxg-tile) var(--pxg-tile);
  box-shadow: 1px 1px 0 var(--pxg-line-major);
}

.pxg .pxg-gallery-list > div {
  padding: 5px !important;
}

.pxg .pxg-gallery-list > div.bg-indigo-300 {
  background-color: var(--pxg-accent-soft);
}

.pxg .pxg-gallery-list [data-pixel-art-thumbnail] {
  position: relative;
  display: block;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(45, 42, 38, 0.1), 0 2px 4px -2px rgba(45, 42, 38, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.pxg .pxg-gallery-list [data-pixel-art-thumbnail]:hover {
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px rgba(45, 42, 38, 0.16), 0 8px 14px -8px rgba(45, 42, 38, 0.55);
}

.pxg .pxg-gallery-list [data-pixel-art-thumbnail]:focus-visible {
  z-index: 1;
  outline-offset: 1px;
}

.pxg .pxg-gallery-list > div.bg-indigo-300 [data-pixel-art-thumbnail] {
  box-shadow: 0 0 0 2px var(--pxg-accent), 0 2px 4px -2px rgba(45, 42, 38, 0.35);
}

/* Loading and empty states, driven by data-history-state on the controller. */
.pxg .pxg-gallery-status {
  display: none;
  margin: 0;
  padding: 44px 16px;
  text-align: center;
  font-family: var(--pxg-read);
  font-size: 17px;
  color: var(--pxg-ink-faint);
}

.pxg .pxg-workbench:not([data-history-state]) .pxg-gallery-status--loading,
.pxg .pxg-workbench[data-history-state="empty"] .pxg-gallery-status--empty {
  display: block;
}

/* Footer ----------------------------------------------------------------- */

.pxg .pxg-footer {
  max-width: 1080px;
  margin: 36px auto 0;
  text-align: center;
}

.pxg .pxg-footer-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid rgba(45, 42, 38, 0.18);
  background: var(--pxg-sheet);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  transition: border-color 120ms ease;
}

.pxg .pxg-footer-link:hover {
  border-color: var(--pxg-ink);
}

/* Small screens ---------------------------------------------------------- */

@media (max-width: 640px) {
  .pxg .pxg-topbar-tag {
    display: none;
  }

  .pxg .pxg-hero {
    padding: 20px 0 24px;
  }

  .pxg .pxg-mark {
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
  }

  .pxg .pxg-note {
    transform: none;
    padding: 22px 18px 18px;
  }

  .pxg .pxg-table-surface {
    padding: 16px 12px 12px;
  }

  .pxg #pixel-art-result-grid {
    gap: 12px 10px;
  }

  .pxg #pixel-art-result-grid > * {
    flex-basis: calc((100% - 20px) / 3);
  }

  .pxg .pixel-art-model-name {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pxg *,
  .pxg *::before,
  .pxg *::after {
    transition: none !important;
    animation: none !important;
  }

  .pxg .pxg-gallery-list [data-pixel-art-thumbnail]:hover {
    transform: none;
  }
}
