html.traits-root {
  height: auto;
  min-height: 100%;
  overflow: auto;
  overscroll-behavior: auto;
  scroll-behavior: smooth;
}

body.traits-page {
  height: auto;
  min-height: 100vh;
  padding: clamp(16px, 4vw, 42px) 12px;
  overflow: visible;
  overscroll-behavior: auto;
}

.traits-window { width: min(1280px, 100%); }

.docs-window-controls a:nth-child(2) {
  background: #b99bdd;
}

.traits-layout {
  display: grid;
  grid-template-columns: 205px minmax(0, 1fr);
  align-items: start;
  background: #f1efe8;
}

.traits-sidebar {
  position: sticky;
  top: 28px;
  z-index: 9;
  max-height: calc(100vh - 28px);
  padding: 22px 14px;
  overflow: auto;
  border-right: 1px solid #77756e;
  background: #d8d5cc;
}

.traits-sidebar nav {
  display: grid;
  gap: 1px;
  padding: 1px;
  background: #8b8880;
}

.traits-layer-button {
  appearance: none;
  display: grid;
  min-height: 30px;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  margin: 0;
  padding: 0 7px 0 0;
  border: 0;
  border-radius: 0;
  background: #e5e2da;
  color: #171717;
  font: 8px/1.2 'Courier New', Courier, monospace;
  text-align: left;
  cursor: pointer;
}

.traits-layer-button > span:first-child {
  display: grid;
  align-self: stretch;
  place-items: center;
  margin-right: 7px;
  border-right: 1px solid #aaa79f;
  color: #68655e;
}

.traits-layer-button > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.traits-layer-button small {
  margin-left: 5px;
  color: #77746c;
  font-size: 7px;
}

.traits-layer-button:hover,
.traits-layer-button:focus-visible {
  background: #f4f2ec;
  outline: 1px dotted #111;
  outline-offset: -4px;
}

.traits-layer-button.is-active {
  background: #292824;
  color: #f2efe7;
}

.traits-layer-button.is-active > span:first-child { color: #9fd4c2; border-color: #5b5851; }
.traits-layer-button.is-active small { color: #c4aedf; }

.traits-sidebar-note {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px;
  margin-top: 15px;
  padding: 9px;
  border: 1px solid #8b8880;
  background: #e5e2da;
}

.traits-sidebar-note p {
  margin: 0;
  color: #5c5a53;
  font: 7px/1.4 'Courier New', Courier, monospace;
}

.traits-content {
  min-width: 0;
  min-height: 800px;
  padding: clamp(18px, 3.8vw, 44px);
  background-color: #f1efe8;
  background-image: radial-gradient(#d5d2c9 .6px, transparent .6px);
  background-size: 4px 4px;
}

.traits-toolbar {
  position: sticky;
  z-index: 8;
  top: 28px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin: calc(clamp(18px, 3.8vw, 44px) * -1) calc(clamp(18px, 3.8vw, 44px) * -1) 28px;
  padding: 13px clamp(18px, 3.8vw, 44px);
  border-bottom: 1px solid #77756e;
  background: rgba(222, 219, 211, .96);
  box-shadow: 0 4px 0 rgba(58, 56, 51, .07);
  backdrop-filter: blur(4px);
}

.traits-search {
  position: relative;
  display: grid;
  gap: 5px;
}

.traits-search > span {
  color: #5e5b54;
  font: 7px/1 'Geist Pixel', 'Courier New', monospace;
  letter-spacing: .06em;
}

.traits-search input {
  width: 100%;
  height: 33px;
  padding: 7px 34px 7px 9px;
  border: 1px solid #66635d;
  border-radius: 0;
  outline: 0;
  background: #f5f3ed;
  color: #171717;
  font: 10px/1 'Courier New', Courier, monospace;
  box-shadow: inset 1px 1px #aaa79f, inset -1px -1px #fff;
}

.traits-search input:focus {
  border-color: #4e2c82;
  outline: 1px dotted #4e2c82;
  outline-offset: -4px;
}

.traits-search kbd {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
  border: 1px solid #89867e;
  background: #ddd9d0;
  color: #68655e;
  font: 9px/1 'Courier New', Courier, monospace;
  box-shadow: inset 1px 1px #fff;
}

.traits-tier-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.traits-tier-filter button,
.traits-random,
.traits-empty button {
  appearance: none;
  min-height: 30px;
  padding: 6px 8px;
  border: 1px solid #5c5953;
  border-radius: 0;
  background: #d8d5cc;
  color: #171717;
  font: 700 7px/1 'Courier New', Courier, monospace;
  cursor: pointer;
  box-shadow: inset 1px 1px #fff, inset -1px -1px #9c9991;
}

.traits-tier-filter button:hover,
.traits-tier-filter button:focus-visible,
.traits-random:hover,
.traits-random:focus-visible,
.traits-empty button:hover,
.traits-empty button:focus-visible {
  background: #272622;
  color: #f4f1e9;
  outline: 1px dotted #f4f1e9;
  outline-offset: -4px;
}

.traits-tier-filter button.is-active { background: #272622; color: #f4f1e9; }
.traits-tier-filter button[data-tier='common'].is-active { background: #4e6d62; }
.traits-tier-filter button[data-tier='uncommon'].is-active { background: #3c6580; }
.traits-tier-filter button[data-tier='rare'].is-active { background: #674394; }
.traits-tier-filter button[data-tier='legendary'].is-active { background: #8c651a; }

.traits-random { min-width: 104px; }

.traits-directory-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 17px;
  padding-bottom: 12px;
  border-bottom: 1px solid #8f8c84;
}

.traits-directory-head p {
  margin: 0 0 6px;
  color: #69665f;
  font: 7px/1 'Geist Pixel', 'Courier New', monospace;
  letter-spacing: .07em;
}

.traits-directory-head h2 {
  margin: 0;
  font: 400 clamp(22px, 4vw, 34px)/1 'Geist Pixel', 'Courier New', monospace;
  letter-spacing: .08em;
}

.traits-directory-head output {
  color: #5c5952;
  font: 8px/1.4 'Courier New', Courier, monospace;
  text-align: right;
}

.traits-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.trait-card {
  appearance: none;
  position: relative;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #66635d;
  border-radius: 0;
  background: #d8d5cc;
  color: #171717;
  text-align: left;
  cursor: zoom-in;
  box-shadow: inset 1px 1px #fff, 3px 4px 0 rgba(34, 33, 30, .11);
  content-visibility: auto;
  contain-intrinsic-size: 0 240px;
}

.trait-card::before {
  content: '';
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: #77746d;
}

.trait-card[data-tier='common']::before { background: #6da590; }
.trait-card[data-tier='uncommon']::before { background: #5d8caa; }
.trait-card[data-tier='rare']::before { background: #8054b8; }
.trait-card[data-tier='legendary']::before { background: #d9a223; }

.trait-card:hover,
.trait-card:focus-visible {
  z-index: 2;
  border-color: #252420;
  outline: 1px dotted #171717;
  outline-offset: -5px;
  transform: translateY(-2px);
  box-shadow: inset 1px 1px #fff, 5px 7px 0 rgba(34, 33, 30, .18);
}

.trait-card-preview {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-bottom: 1px solid #77746d;
  background-color: #f1efe8;
  background-image:
    linear-gradient(45deg, #d8d5cd 25%, transparent 25%),
    linear-gradient(-45deg, #d8d5cd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d5cd 75%),
    linear-gradient(-45deg, transparent 75%, #d8d5cd 75%);
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  background-size: 14px 14px;
}

.trait-card-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  transition: transform 120ms steps(2, end);
}

.trait-card:hover .trait-card-preview img,
.trait-card:focus-visible .trait-card-preview img { transform: scale(1.05); }

.trait-card-index {
  position: absolute;
  z-index: 2;
  top: 5px;
  left: 9px;
  padding: 3px 5px;
  border: 1px solid #56534d;
  background: rgba(235, 232, 224, .9);
  color: #4f4d47;
  font: 7px/1 'Courier New', Courier, monospace;
}

.trait-color-chip {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  border: 1px solid #34332f;
  box-shadow: 1px 1px #fff;
}

.trait-card-copy { min-height: 66px; padding: 9px 9px 9px 12px; }

.trait-card-copy strong {
  display: -webkit-box;
  min-height: 27px;
  overflow: hidden;
  font: 9px/1.45 'Courier New', Courier, monospace;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.trait-card-copy span {
  display: flex;
  justify-content: space-between;
  gap: 7px;
  margin-top: 6px;
  color: #65625b;
  font: 7px/1 'Courier New', Courier, monospace;
  text-transform: uppercase;
}

.trait-card-copy em { font-style: normal; }

.traits-empty {
  padding: 70px 20px;
  border: 1px dashed #8b8880;
  background: #e7e4dc;
  text-align: center;
}

.traits-empty span {
  display: block;
  margin-bottom: 8px;
  font: 24px/1 'Geist Pixel', 'Courier New', monospace;
  letter-spacing: .1em;
}

.traits-empty p { margin: 0 0 18px; font: 10px/1.5 'Courier New', Courier, monospace; }

.trait-dialog {
  width: min(760px, calc(100% - 24px));
  max-width: none;
  max-height: min(88vh, 720px);
  margin: auto;
  padding: 0;
  overflow: visible;
  border: 1px solid #4f4e49;
  outline: 2px solid #d8d5cc;
  background: #d7d4cb;
  color: #171717;
  font-family: 'Geist Pixel', 'Courier New', monospace;
  box-shadow: 10px 12px 0 rgba(35, 35, 30, .24);
}

.trait-dialog::backdrop { background: rgba(239, 237, 230, .86); }
.trait-dialog-shell { border: 2px outset #efede6; background: #d7d4cb; }

.trait-dialog-body {
  display: grid;
  max-height: min(72vh, 620px);
  grid-template-columns: minmax(280px, 1fr) minmax(220px, .7fr);
  gap: 26px;
  padding: 28px;
  overflow: auto;
  border-bottom: 1px solid #666;
  background-color: #f1efe8;
  background-image: radial-gradient(#d5d2c9 .6px, transparent .6px);
  background-size: 4px 4px;
}

.trait-dialog-preview {
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid #4f4d47;
  background-color: #f1efe8;
  background-image:
    linear-gradient(45deg, #d8d5cd 25%, transparent 25%),
    linear-gradient(-45deg, #d8d5cd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d5cd 75%),
    linear-gradient(-45deg, transparent 75%, #d8d5cd 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  box-shadow: 4px 5px 0 rgba(34, 33, 30, .15);
}

.trait-dialog-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.trait-dialog-copy { align-self: center; min-width: 0; }
.trait-dialog-copy > p { margin: 0 0 8px; color: #68655e; font-size: 8px; letter-spacing: .08em; }

.trait-dialog-copy h2 {
  margin: 0 0 22px;
  overflow-wrap: anywhere;
  font: 400 clamp(24px, 4vw, 38px)/1.2 'Geist Pixel', 'Courier New', monospace;
  letter-spacing: .05em;
}

.trait-dialog-copy dl { display: grid; margin: 0; border: 1px solid #77756e; }

.trait-dialog-copy dl div {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  border-bottom: 1px solid #aaa79f;
}

.trait-dialog-copy dl div:last-child { border-bottom: 0; }
.trait-dialog-copy dt,
.trait-dialog-copy dd { min-width: 0; margin: 0; padding: 8px; }
.trait-dialog-copy dt { border-right: 1px solid #aaa79f; background: #dedbd3; color: #646159; font-size: 7px; }
.trait-dialog-copy dd { overflow-wrap: anywhere; background: #f7f5ef; font: 8px/1.45 'Courier New', Courier, monospace; }

.trait-dialog-actions { grid-template-columns: 1fr; }

@media (max-width: 980px) {
  .traits-toolbar { grid-template-columns: 1fr auto; }
  .traits-search { grid-column: 1 / -1; }
  .traits-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .traits-layout { grid-template-columns: 1fr; }
  .traits-sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid #77756e;
  }
  .traits-sidebar nav {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }
  .traits-layer-button {
    flex: 0 0 145px;
    scroll-snap-align: start;
  }
  .traits-sidebar-note { display: none; }
  .traits-toolbar { top: 28px; }
  .trait-dialog-body { grid-template-columns: 1fr; }
  .trait-dialog-preview { width: min(360px, 100%); justify-self: center; }
}

@media (max-width: 540px) {
  body.traits-page { padding: 9px 6px 18px; }
  .traits-content { padding: 15px; }
  .traits-toolbar {
    grid-template-columns: 1fr;
    margin: -15px -15px 22px;
    padding: 11px 15px;
  }
  .traits-search { grid-column: auto; }
  .traits-tier-filter { overflow-x: auto; flex-wrap: nowrap; }
  .traits-tier-filter button { flex: 0 0 auto; }
  .traits-random { width: 100%; }
  .traits-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .trait-card-copy { min-height: 62px; padding: 8px 7px 8px 10px; }
  .trait-card-copy strong { font-size: 8px; }
  .traits-directory-head { align-items: start; flex-direction: column; }
  .traits-directory-head output { text-align: left; }
  .trait-dialog { width: calc(100% - 16px); max-height: calc(100vh - 16px); }
  .trait-dialog-body { max-height: calc(100vh - 92px); padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html.traits-root { scroll-behavior: auto; }
  .trait-card,
  .trait-card-preview img { transition: none; }
  .trait-card:hover,
  .trait-card:focus-visible { transform: none; }
}
