:root {
  color: #20211f;
  background: #f4f4ef;
  font-family: "Aptos", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(32, 33, 31, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(32, 33, 31, 0.05) 1px, transparent 1px),
    #f4f4ef;
  background-size: 28px 28px;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1680px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  border-bottom: 2px solid #20211f;
  padding-bottom: 16px;
}

.kicker {
  margin: 0 0 6px;
  color: #d24a2f;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.95;
  text-transform: uppercase;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 8px;
}

.stats span {
  border: 2px solid #20211f;
  background: #fffdfa;
  padding: 10px;
  color: #5c625c;
  font-size: 0.82rem;
  font-weight: 800;
}

.stats strong {
  display: block;
  color: #20211f;
  font-size: 1.35rem;
}

.controls {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(260px, 1.5fr) repeat(2, minmax(150px, 0.5fr));
  gap: 8px;
  margin: 14px 0;
  border: 2px solid #20211f;
  background: #f4f4ef;
  padding: 8px;
}

label {
  display: grid;
  gap: 5px;
}

label span {
  color: #5c625c;
  font-size: 0.74rem;
  font-weight: 900;
}

input,
select {
  min-height: 42px;
  width: 100%;
  border: 2px solid #20211f;
  border-radius: 0;
  background: #fffdfa;
  color: #20211f;
  outline: none;
  padding: 0 10px;
}

input:focus,
select:focus {
  border-color: #008f83;
  box-shadow: 0 0 0 3px rgba(0, 143, 131, 0.22);
}

.result-line {
  color: #5c625c;
  font-weight: 800;
}

.result-line strong {
  color: #20211f;
  font-size: 1.25rem;
}

.gallery {
  column-count: 6;
  column-gap: 12px;
}

.tile {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  margin: 0 0 12px;
  border: 2px solid #20211f;
  border-radius: 8px;
  background: #fffdfa;
  text-align: left;
  break-inside: avoid;
  page-break-inside: avoid;
}

.tile:hover,
.tile:focus-within {
  border-color: #d24a2f;
  box-shadow: 5px 5px 0 #20211f;
  transform: translate(-2px, -2px);
}

.thumb-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  padding: 0;
}

.thumb-button:focus-visible,
.copy-card:focus-visible {
  outline: 3px solid rgba(0, 143, 131, 0.34);
  outline-offset: -3px;
}

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

.tile-info {
  display: grid;
  gap: 7px;
  border-top: 2px solid #20211f;
  padding: 8px;
}

.tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.model-tag {
  display: inline-flex;
  max-width: 100%;
  overflow: hidden;
  border: 2px solid #20211f;
  border-radius: 999px;
  background: #cfff4f;
  padding: 3px 8px;
  color: #20211f;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 900;
}

.prompt-excerpt {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #3d423d;
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.copy-card {
  flex: 0 0 auto;
  min-height: 28px;
  border: 2px solid #20211f;
  border-radius: 999px;
  background: #fffdfa;
  color: #20211f;
  cursor: pointer;
  padding: 0 9px;
  font-size: 0.72rem;
  font-weight: 900;
}

.load-more {
  display: flex;
  justify-content: center;
  padding: 24px 0 0;
}

.load-more button,
.viewer-actions button,
.viewer-actions a {
  min-height: 42px;
  border: 2px solid #20211f;
  border-radius: 8px;
  background: #cfff4f;
  color: #20211f;
  cursor: pointer;
  padding: 0 14px;
  text-decoration: none;
  font-weight: 900;
  line-height: 38px;
}

dialog {
  width: min(1380px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  border: 2px solid #20211f;
  border-radius: 8px;
  background: #fffdfa;
  color: #20211f;
  padding: 0;
}

dialog::backdrop {
  background: rgba(32, 33, 31, 0.78);
}

dialog[open] {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
}

.close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 38px;
  height: 38px;
  border: 2px solid #20211f;
  border-radius: 8px;
  background: #d24a2f;
  color: #fffdfa;
  cursor: pointer;
  font-weight: 900;
}

#viewerImage {
  width: 100%;
  height: min(82vh, 900px);
  background: #20211f;
  object-fit: contain;
}

dialog aside {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  max-height: min(82vh, 900px);
  min-height: 0;
  border-left: 2px solid #20211f;
}

#viewerModel {
  margin: 0;
  border-bottom: 2px solid #20211f;
  padding: 14px;
  color: #008f83;
  font-weight: 900;
}

#viewerTitle {
  margin: 0;
  border-bottom: 2px solid #20211f;
  padding: 14px;
  font-size: 1.05rem;
  line-height: 1.35;
}

#viewerPrompt {
  margin: 0;
  overflow: auto;
  padding: 14px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.64;
  white-space: pre-wrap;
  word-break: break-word;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 2px solid #20211f;
  padding: 12px 14px;
}

.viewer-actions a {
  background: #fffdfa;
}

@media (max-width: 900px) {
  .topbar,
  .controls,
  dialog[open] {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

  .gallery {
    column-count: 3;
  }

  dialog aside {
    border-left: 0;
    border-top: 2px solid #20211f;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 16px, 1680px);
  }

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

  .gallery {
    column-count: 2;
    column-gap: 8px;
  }

  .tile {
    margin-bottom: 8px;
  }
}
