.slot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(286.5px, 1fr));
  gap: 10px;
}

#slot-acc1,
#slot-acc2,
#slot-acc3 {
  grid-column: 1;
}

#slot-chest,
#slot-legs {
  grid-column: 2;
}

#slot-acc1,
#slot-chest {
  grid-row: 1;
}

#slot-acc2,
#slot-legs {
  grid-row: 2;
}

#slot-acc3 {
  grid-row: 3;
}

@container builder (width < 583px) {
  .slot-grid {
    grid-template-columns: 1fr;
  }

  #slot-chest,
  #slot-legs,
  #slot-acc1,
  #slot-acc2,
  #slot-acc3 {
    grid-column: auto;
    grid-row: auto;
  }
}

.slot {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 0;
}

.slot.invalid {
  border-color: var(--bad);
}

.slot-weapon [data-action="pick-modifier"],
.slot-weapon [data-action="pick-faction-modifier"],
.slot-weapon .gem-row {
  display: none;
}

.slot-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.slot-title h2 {
  font-size: 12px;
}

.slot-warning {
  color: var(--bad);
  font-size: 11px;
  text-align: right;
}

.slot-main {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 8px;
}

.pick-button {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  overflow: hidden;
}

.pick-button img {
  max-width: 64px;
  max-height: 64px;
  object-fit: contain;
}

.picked-item {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
}

.picked-item[hidden] {
  display: none;
}

.picked-item-image {
  display: grid;
  place-items: center;
  width: 100%;
  height: 36px;
}

.picked-item-image:empty {
  display: none;
}

.picked-item-name {
  position: relative;
  z-index: 10;
  width: 100%;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  line-clamp: 2;
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}

.pick-button .empty {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--dim);
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  padding: 4px;
}

.pick-button[data-rarity="Common"] {
  border-color: #8e8f92;
}
.pick-button[data-rarity="Uncommon"] {
  border-color: #a9954d;
}
.pick-button[data-rarity="Rare"] {
  border-color: #7775ef;
}
.pick-button[data-rarity="Mystic"] {
  border-color: #c977dc;
}
.pick-button[data-rarity="Limited"] {
  border-color: #e8d074;
}

.composite-image {
  position: relative;
  width: 64px;
  height: 64px;
  display: block;
}

.composite-image img {
  position: absolute;
  object-fit: contain;
}

.composite-image .base {
  inset: 0;
  width: 64px;
  height: 64px;
}

.composite-image .overlay {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  z-index: 2;
}

.slot-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  min-width: 0;
}

.slot-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.compact-field {
  display: flex;
  align-items: center;
  gap: 4px;
  width: auto;
}

.compact-field input[type="number"] {
  width: 44px;
  min-height: 26px;
  padding: 2px 5px;
  text-align: center;
}

.clear-button {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: 26px;
  padding: 2px 8px;
}

.level-stepper {
  display: grid;
  grid-template-columns: repeat(2, 24px);
  gap: 4px;
}

.level-stepper-button {
  min-width: 24px;
  min-height: 26px;
  padding: 0;
  text-align: center;
}

.item-name {
  min-height: 19px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 6px;
}

.button-row .mini-button {
  max-width: none;
}

.modifier-button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.05;
  white-space: normal;
}

.modifier-name {
  width: 100%;
}

.modifier-boost {
  width: 100%;
  color: var(--dim);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.gem-row {
  display: grid;
  grid-template-columns: repeat(auto-fit);
  gap: 6px;
}

.gem-control {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.jewel-summary-button {
  width: 100%;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.jewel-summary-button:hover {
  border-color: var(--accent);
}

.optimistic-jewel-slot {
  border-color: color-mix(in srgb, var(--warn) 72%, var(--border));
  background: color-mix(in srgb, var(--warn) 12%, var(--panel));
}

.optimistic-jewel-slot:hover {
  border-color: var(--warn);
}

.jewel-head,
.jewel-saved-row,
.jewel-part {
  display: grid;
  gap: 4px;
}

.jewel-head {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.jewel-head span,
.jewel-secondary {
  color: var(--dim);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jewel-secondary-lines {
  display: grid;
  gap: 2px;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  white-space: normal;
}

.jewel-secondary-lines > span {
  display: flex;
  flex-wrap: wrap;
  column-gap: 4px;
  overflow: visible;
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: normal;
}

.jewel-secondary-lines > span:first-child {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.jewel-summary-row {
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  width: 100%;
}

.jewel-summary-stat-row {
  justify-content: space-between;
}

.jewel-summary-secondary-row {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.jewel-summary-stats {
  min-width: 0;
  flex: 1 1 auto;
}

.jewel-summary-ep {
  flex: 0 0 auto;
  color: var(--muted);
  white-space: nowrap;
}

.stat-chunk {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.jewel-saved-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.jewel-save-only {
  justify-self: start;
}

.custom-jewel-button {
  width: fit-content;
  min-width: max-content;
  max-width: none;
  flex: 0 0 auto;
}

.jewel-part {
  grid-template-columns: 72px 72px 72px minmax(0, 1fr);
  align-items: end;
  gap: 6px;
}

.jewel-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.jewel-field {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.jewel-field span {
  color: var(--dim);
  font-size: 11px;
}

.jewel-choice-button {
  width: 72px;
  height: 72px;
}

.jewel-choice-button:hover {
  border-color: var(--accent);
}

.jewel-choice-button .picked-item {
  display: grid;
  grid-template-areas: "layer";
}

.jewel-choice-image {
  grid-area: layer;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.jewel-choice-image img {
  max-width: 100%;
  max-height: 100%;
}

.jewel-choice-name {
  grid-area: layer;
  align-self: end;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
}

.jewel-field select {
  width: 100%;
  max-width: 104px;
  min-height: 34px;
}

.jewel-tier-field {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 6px;
  justify-self: end;
  min-width: 0;
}

.jewel-tier-field span {
  color: var(--dim);
  font-size: 11px;
}

.jewel-part-details {
  display: grid;
  gap: 3px;
  align-self: end;
  justify-self: stretch;
  padding: 0 2px 0 0;
  color: var(--dim);
  font-size: 11px;
  line-height: 1.25;
}

.jewel-part-details.empty {
  align-self: end;
}

.jewel-part-line {
  display: grid;
  grid-template-columns: minmax(76px, max-content) minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: 6px;
  overflow-wrap: anywhere;
}

.jewel-part-primary {
  color: var(--text);
  font-weight: 600;
}

.jewel-part-primary .jewel-summary-ep {
  color: var(--muted);
  font-weight: 500;
}

.jewel-part-source {
  color: var(--muted);
}

.jewel-part-source::after {
  content: ":";
}

.jewel-part-value {
  min-width: 0;
}

.jewel-part-secondary {
  display: grid;
  gap: 2px;
  color: var(--dim);
}

.jewel-part-secondary .jewel-part-line {
  padding-left: 0;
  font-size: 10.5px;
}

.jewel-extra {
  display: grid;
  gap: 6px;
}

.jewel-extra[open] {
  padding-top: 2px;
}

.jewel-extra summary {
  color: var(--dim);
  cursor: pointer;
  font-size: 12px;
}

.picker-panel.jewel-editor-panel {
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: min(500px, calc(100vw - 24px));
  height: fit-content;
  min-height: 0;
  max-height: calc(100dvh - 24px);
  overflow: hidden;
}

.jewel-editor-body {
  flex: 0 1 auto;
  display: grid;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.jewel-editor-summary,
.jewel-editor-section {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}

.jewel-editor-summary span {
  color: var(--dim);
}

.jewel-editor-section h3 {
  margin: 0;
  font-size: 14px;
}

.jewel-editor-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.jewel-editor-actions > button {
  max-width: none;
  width: 100%;
}

.jewel-editor-footer {
  display: flex;
  justify-content: flex-end;
}

.compact-empty {
  margin: 0;
  padding: 8px;
}
