.morph-gallery {
  color: var(--ink);
}

.morph-gallery-intro {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 21px;
}

.morph-gallery-intro p {
  margin-top: 7px;
  color: var(--muted);
  font-size: .94rem;
  line-height: 1.6;
}

.morph-visit { flex: none; }
.morph-visit pixel-art { width: 25px; height: 25px; }

.morph-filters {
  display: flex;
  gap: 9px;
  margin: 0 0 18px;
  border-bottom: 1px dashed #a9b09a;
  padding-bottom: 13px;
}

.morph-filter,
.morph-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 2px solid var(--line);
  border-radius: 4px;
  box-shadow: 2px 2px 0 var(--line);
  color: var(--ink);
  font-size: .88rem;
  line-height: 1.35;
  font-weight: 800;
}

.morph-filter {
  padding: 6px 11px;
  background: var(--paper);
}

.morph-filter span {
  color: #526443;
  font: 800 .79rem/1 var(--mono);
  padding: 2px 0 2px 6px;
  border-left: 1px solid #a5b294;
}

.morph-filter[aria-pressed="true"] { background: #d8e7bc; }
.morph-filter:hover,
.morph-action:hover { filter: brightness(1.035); }
.morph-filter:active,
.morph-action:active { transform: translate(2px,2px); box-shadow: none; }

.morph-grid {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  align-items: stretch;
  gap: 20px;
}

.morph-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 5px;
  box-shadow: var(--shadow);
}

.morph-tone-reed { --morph-back: #dce8c7; --morph-grain: #c4d4ac; }
.morph-tone-pool { --morph-back: #d0e6df; --morph-grain: #b3d1c5; }
.morph-tone-blush { --morph-back: #f0dbcd; --morph-grain: #dcc3b3; }
.morph-tone-slate { --morph-back: #dbe2d5; --morph-grain: #c2c9ba; }
.morph-tone-sand { --morph-back: #eee0be; --morph-grain: #d8c8a7; }

.morph-picture,
.morph-portrait {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 15px;
  background-color: var(--morph-back,#dce8c7);
  background-image: radial-gradient(circle,var(--morph-grain,#c4d4ac) .8px,transparent 1.1px);
  background-size: 6px 6px;
}

.morph-picture {
  width: 100%;
  aspect-ratio: 1.68;
  border: 0;
  border-bottom: 2px solid var(--line);
  cursor: zoom-in;
}

.morph-picture:focus-visible { outline-offset: -5px; }
.morph-picture img,
.morph-portrait img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.morph-picture img { transition: transform .18s ease-out; }
.morph-picture:hover img,
.morph-picture:focus-visible img { transform: scale(1.035); }

.morph-zoom {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 20px;
  height: 20px;
  background: #faf8eadd;
  border: 1px solid #89947e;
  border-radius: 3px;
}

.morph-zoom::before,
.morph-zoom::after { content: ""; position: absolute; }
.morph-zoom::before {
  width: 8px;
  height: 8px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  border: 1.5px solid #4f604b;
}
.morph-zoom::after {
  top: 11px;
  left: 11px;
  width: 5px;
  height: 2px;
  background: #4f604b;
  transform: rotate(45deg);
  transform-origin: left;
}

.morph-card-copy {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 13px 15px 15px;
}
.morph-card-copy h2 { font-size: 1.2rem; line-height: 1.4; font-weight: 900; }
.morph-card-copy p {
  margin: 5px 0 14px;
  color: #56614f;
  font-size: .91rem;
  line-height: 1.65;
}
.morph-card-actions { margin-top: auto; }
.morph-action { padding: 6px 12px; background: #f5d683; }
.morph-action.is-housed { background: #e3ebd2; }
.morph-action > span { font: 800 1.06rem/1 var(--mono); }

.morph-empty {
  display: grid;
  justify-items: center;
  gap: 15px;
  padding: 36px 18px;
  text-align: center;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 5px;
  box-shadow: var(--shadow);
}
.morph-empty pixel-art { width: 64px; height: 55px; }
.morph-empty p { color: #586650; }

.dialog:has(.morph-detail) { width: min(570px,calc(100% - 30px)); }
.dialog:has(.morph-detail) .dialog-head { position: sticky; top: 0; z-index: 1; }
.morph-portrait {
  aspect-ratio: 1.94;
  padding: 16px 8%;
  border: 1.5px solid #88967c;
  border-radius: 4px;
}
.morph-notes { margin: 16px 0; }
.morph-portrait.is-magnified img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 202%;
  height: auto;
  max-width: none;
  transform: translate(var(--focus-x), var(--focus-y));
  image-rendering: pixelated;
}
.morph-regions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.morph-regions button {
  padding: 5px 11px;
  border: 1px solid #a3ad92;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: .83rem;
  cursor: pointer;
}
.morph-regions button[aria-pressed="true"] {
  border-color: #5d7650;
  background: #d8e7bc;
  font-weight: 750;
}
.morph-notes > div {
  display: grid;
  grid-template-columns: 4.5em minmax(0,1fr);
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed #c4c9b4;
  font-size: .91rem;
  line-height: 1.65;
}
.morph-notes dt { color: #5c6a50; font-weight: 750; }
.morph-notes dd { margin: 0; }
.resident-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.morph-detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.morph-references { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.morph-source {
  text-decoration: underline;
  text-underline-offset: 3px;
  color: #456447;
  font-size: .9rem;
  font-weight: 700;
}
.morph-source span { display: inline-block; margin-left: 3px; }

@media (max-width:1100px) {
  .morph-grid { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
}
@media (max-width:780px) {
  .morph-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width:550px) {
  .morph-gallery-intro { align-items: flex-start; margin-bottom: 14px; }
  .morph-gallery-intro h1 { font-size: clamp(1.35rem,5.8vw,1.8rem); }
  .morph-gallery-intro p { font-size: .85rem; }
  .morph-visit { min-height: 33px; padding: 5px 8px; font-size: .78rem; gap: 4px; }
  .morph-visit pixel-art { width: 19px; height: 19px; }
  .morph-grid { gap: 12px; }
  .morph-picture { aspect-ratio: 1.48; padding: 10px; }
  .morph-zoom { top: 4px; right: 4px; }
  .morph-card-copy { padding: 9px 10px 12px; }
  .morph-card-copy h2 { font-size: 1.05rem; }
  .morph-card-copy p { font-size: .83rem; margin-bottom: 9px; }
  .morph-action { padding: 5px 8px; }
}
@media (max-width:350px) {
  .morph-gallery-intro { flex-wrap: wrap; }
  .morph-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion:reduce) {
  .morph-picture img { transition: none; }
}
