.sam-window {
  position: fixed;
  top: 72px;
  left: 50%;
  z-index: 20;
  overflow: hidden;
  width: min(1260px, calc(100vw - 28px));
  height: min(780px, calc(100vh - 92px));
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 2px solid #8a6b32;
  border-radius: 8px;
  background: #130f10;
  color: #efe3c8;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.62), inset 0 0 0 1px rgba(255, 230, 168, 0.06);
  transform: translateX(-50%);
}

.sheet-app.header-hidden .sam-window {
  top: 14px;
  height: calc(100vh - 28px);
}

.sam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sam-header h2 {
  margin: 0;
  color: #f0d79a;
  font-size: 20px;
  line-height: 1.2;
}

.sam-header span {
  color: #b7a47f;
  font-size: 13px;
}

.sam-close {
  min-width: 74px;
  border-color: #5c4730;
  background: #1d1718;
  color: #efe3c8;
}

.sam-close:hover {
  background: #2a2020;
}

.sam-window .primary {
  background: #7a1f1f;
  border-color: #b8944a;
  color: #fff4d6;
}

.sam-window .primary:hover {
  background: #9b2929;
}

.sam-window .danger {
  min-width: 116px;
  color: #ffd8d3;
  background: #251416;
  border-color: #7e2a2d;
}

.sam-window .danger:hover {
  color: #fff4f0;
  background: #4b181c;
  border-color: #b64040;
}

.sam-layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(310px, 0.95fr) minmax(360px, 1.15fr);
  gap: 14px;
  overflow: hidden;
}

.sam-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  align-content: start;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding: 2px 4px 8px 2px;
}

.sam-card {
  display: flex;
  min-height: 320px;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px;
  border: 1px solid #4e3c2c;
  border-radius: 8px;
  background: #1a1415;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.38);
  text-align: left;
  overflow: hidden;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

.sam-card.npc-card {
  min-height: 270px;
}

.sam-card:hover {
  transform: translateY(-2px);
  border-color: #9d7a3b;
  background: #21191a;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.36);
}

.sam-card.selected {
  border-color: #b8944a;
  background: #241819;
  box-shadow: 0 0 0 2px rgba(142, 31, 31, 0.52), 0 10px 24px rgba(0, 0, 0, 0.36);
}

.sam-card-preview {
  display: block;
  overflow: hidden;
  border: 1px solid #5e4a31;
  background: #0f0c0c;
  box-shadow: inset 0 0 0 1px rgba(255, 225, 153, 0.08);
}

.sam-light-preview {
  display: grid;
  gap: 6px;
  align-content: center;
  justify-items: center;

  width: 100%;
  min-height: 118px;
  padding: 14px;

  background:
    linear-gradient(
      145deg,
      rgba(126, 42, 45, 0.22),
      rgba(13, 10, 11, 0.96)
    );
}

.sam-light-preview.npc {
  background:
    linear-gradient(
      145deg,
      rgba(157, 122, 59, 0.2),
      rgba(13, 10, 11, 0.96)
    );
}

.sam-light-mark {
  display: inline-grid;
  place-items: center;

  min-width: 64px;
  min-height: 34px;
  padding: 0 10px;

  color: #130f10;
  background: #d6b56d;
  border: 1px solid #f0d79a;
  border-radius: 6px;

  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.sam-light-name,
.sam-light-subtitle {
  display: block;
  max-width: 100%;

  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sam-light-name {
  color: #f2dfb5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 850;
}

.sam-light-subtitle {
  color: #a89473;
  font-size: 0.78rem;
  font-weight: 700;
}

.sam-card-title {
  overflow-wrap: anywhere;
  color: #f2dfb5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.05;
}

.sam-card-subtitle {
  min-height: 18px;
  color: #a89473;
  font-size: 13px;
  font-weight: 650;
}

.sam-card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sam-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid #5a4731;
  border-radius: 4px;
  background: rgba(255, 231, 181, 0.06);
  color: #d6c39d;
  font-size: 12px;
  font-weight: 720;
  padding: 0 8px;
}

.sam-pill.hp {
  color: #d05b52;
}

.sam-pill.gold {
  color: #d0a947;
}

.sam-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: auto;
}

.sam-stat-grid span {
  min-height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid #5f4930;
  border-radius: 4px;
  background: #0c0909;
  color: #f0d79a;
  font-size: 11px;
  font-weight: 800;
}

.sam-viewer {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid #5c4730;
  border-radius: 8px;
  background: #191314;
  overflow: hidden;
}

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

.sam-viewer-head h3 {
  margin: 0;
  overflow-wrap: anywhere;
  color: #f2dfb5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1;
}

.sam-viewer-head span {
  color: #a89473;
  font-size: 13px;
  font-weight: 650;
}

.sam-viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.sam-empty {
  display: grid;
  flex: 1;
  place-items: center;
  color: #a89473;
}

.sam-viewer > .sheet-preview {
  width: min(100%, 720px);
  margin: auto;
  border: 1px solid #4e3c2c;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.42);
}

.sam-viewer > .npc-preview {
  flex: 1;
  min-height: 0;
}

.sam-mobile-summary {
  display: grid;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.sam-mobile-summary .sam-light-preview {
  min-height: 180px;
  border: 1px solid #5e4a31;
  box-shadow: inset 0 0 0 1px rgba(255, 225, 153, 0.08);
}

.sam-mobile-summary p {
  margin: 0;
  color: #cbb892;
  line-height: 1.55;
}

.sam-mobile-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

@media (max-width: 860px) {
  .sam-window {
    top: 8px;
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    padding: 10px;
  }

  .sam-header {
    align-items: flex-start;
  }

  .sam-layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
  }

  .sam-card-grid {
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
    max-height: 220px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
  }

  .sam-card {
    flex: 0 0 min(250px, 78vw);
    min-height: 190px;
  }

  .sam-card.npc-card {
    min-height: 190px;
  }

  .sam-window.compact .sam-card-preview {
    min-height: 118px;
  }

  .sam-viewer {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }

  .sam-viewer-head {
    align-items: stretch;
    flex-direction: column;
  }

  .sam-viewer-actions {
    justify-content: stretch;
  }

  .sam-viewer-actions button {
    flex: 1 1 140px;
  }

  .sam-viewer > .sheet-preview {
    width: 100%;
    margin: 0 auto;
  }
}

@media (max-width: 520px) {
  .sam-window {
    width: 100vw;
    height: 100vh;
    inset: 0 auto auto 0;
    border-radius: 0;
    transform: none;
  }

  .sam-card-grid {
    max-height: 184px;
  }

  .sam-card {
    flex-basis: min(218px, 82vw);
    min-height: 164px;
    padding: 10px;
  }

  .sam-card-row,
  .sam-stat-grid {
    display: none;
  }
}
