.saved-formations {
  margin: -6px 0 24px;
  padding: 15px 0;
  border-bottom: 1px solid var(--ink);
}

.saved-formations > header {
  display: flex;
  align-items: end;
  margin-bottom: 10px;
}

.saved-formations > header small {
  font-size: 8px;
  letter-spacing: .14em;
  color: var(--gold);
}

.saved-formations > header h2 {
  margin: 3px 0 0;
  font: 600 17px 'Noto Serif KR';
}

.saved-formations > header span {
  margin-left: auto;
  font-size: 8px;
  color: var(--muted);
}

.saved-formations > div {
  display: flex;
  gap: 8px;
  overflow: auto;
}

.saved-formations > div > p {
  margin: 6px 0 10px;
  font-size: 9px;
  color: var(--muted);
}

.saved-formations article {
  flex: 0 0 250px;
  display: grid;
  grid-template-columns: 1fr 30px;
  border: 1px solid var(--line);
  background: #ece7dc;
}

.saved-formations article > button:first-child {
  display: grid;
  grid-template-columns: 82px 1fr;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  align-items: center;
  padding: 8px;
  border: 0;
  background: none;
  text-align: left;
}

.saved-formations article > button:first-child > span {
  grid-row: 1 / 3;
  display: flex;
}

.saved-formations article img,
.saved-formations article i {
  width: 30px;
  height: 30px;
  margin-left: -4px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--ink);
  color: white;
  display: grid;
  place-items: center;
  font-style: normal;
}

.saved-formations article img:first-child,
.saved-formations article i:first-child { margin-left: 0; }
.saved-formations article b { font: 600 10px 'Noto Serif KR'; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-formations article small { font-size: 8px; color: var(--muted); }
.saved-formations article > button:last-child { border: 0; border-left: 1px solid var(--line); background: none; color: var(--muted); }
.saved-formations article > button:last-child svg { width: 13px; }

@media (max-width: 760px) {
  .saved-formations > header { display: block; }
  .saved-formations > header span { display: block; margin: 5px 0 0; }
  .saved-formations article { flex-basis: 230px; }
}

/* Keep the selected legion art visible in the first desktop viewport. */
@media (min-width: 761px) {
  .workspace { padding-top: 24px; }
  .deck-mode-tabs { margin-bottom: 18px; }
  .tier-page-head { padding-bottom: 16px; }
  .tier-page-head h1 { font-size: 36px; }
  .roster-summary { padding: 12px 0; }
  .roster-summary strong { font-size: 22px; }
  .tier-filter { height: 50px; }
  .tier-deck-index { margin: 7px 0 14px; }
  .tier-deck-index button { padding: 10px 12px; }
  .tier-deck-detail > header { min-height: 116px; padding: 18px 34px; }
  .tier-deck-detail > header h2 { font-size: 27px; }
  .tier-fit-line { margin-top: 10px; }
}

.tier-catalog > article {
  grid-template-columns: 55px minmax(180px, 1fr) 310px 50px 58px;
}

.catalog-open,
.catalog-apply {
  height: 32px;
  border: 1px solid var(--jade);
  background: none;
  color: var(--jade);
  font-size: 9px;
}

.tier-catalog > article.expanded {
  border-bottom-color: var(--ink);
  background: #e9e4d8;
}

.tier-inline-detail {
  margin: 0 0 22px;
  border-bottom: 1px solid var(--ink);
}

.tier-loadout-notes dl {
  margin: 11px 0 14px;
}

.tier-loadout-notes dl > div {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #334138;
}

.tier-loadout-notes dt {
  font-size: 7px;
  color: #7f8d84;
}

.tier-loadout-notes dd {
  margin: 0;
  font-size: 8px;
  line-height: 1.45;
  color: #d2d8d4;
}

.tier-loadout-notes article > div > span {
  font-size: 8px;
  color: #7f8d84;
}

.formation-tabs {
  max-width: 640px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.formation-tabs button { min-width: 54px; }

.picker-method {
  display: block;
  max-width: 390px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.5;
}

.candidate-list > button > em,
.skill-fit-score {
  min-width: 58px;
  text-align: right;
  text-decoration: none;
  font-style: normal;
}

.candidate-list > button > em b,
.skill-fit-score b {
  display: block;
  color: var(--jade);
  font: 600 16px 'Noto Serif KR';
}

.candidate-list > button > em small,
.skill-fit-score small {
  margin-top: 1px;
  font-size: 7px;
  color: var(--muted);
}

.candidate-reason {
  display: block;
  margin-top: 5px;
  color: var(--jade);
  font-size: 8px;
  line-height: 1.4;
  font-style: normal;
}

.candidate-skill-list > button {
  grid-template-columns: 45px minmax(0, 1fr) 62px;
  align-items: center;
}

.candidate-skill-list > button.conflict {
  opacity: .58;
  background: #eaded9;
}

.candidate-skill-list > button.conflict .candidate-reason,
.candidate-skill-list > button.conflict .skill-fit-score b { color: #9a5b49; }

.review-score-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.5;
}

.score-breakdown {
  display: grid;
  gap: 7px;
  margin-top: -12px;
}

.score-breakdown > div {
  display: grid;
  grid-template-columns: 58px 1fr 34px;
  gap: 8px;
  align-items: center;
}

.score-breakdown span,
.score-breakdown em {
  font-size: 8px;
  color: var(--muted);
  font-style: normal;
}

.score-breakdown em { text-align: right; }
.score-breakdown > div > i { height: 3px; background: #d1c9b8; }
.score-breakdown > div > i > b { display: block; height: 100%; background: var(--jade); }

/* Dense codex: the list is for recognition; all stats stay in the detail drawer. */
.hero-codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 14px 10px;
}

.hero-codex-card {
  position: relative;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  content-visibility: auto;
  contain-intrinsic-size: 145px 205px;
}

.hero-codex-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.hero-codex-art {
  display: grid;
  place-items: end center;
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: radial-gradient(circle at 50% 70%, #fff 0, #d8d2c5 72%);
}

.hero-codex-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
}

.hero-codex-art > b {
  align-self: center;
  font: 600 30px 'Noto Serif KR';
  color: var(--muted);
}

.hero-codex-flags {
  position: absolute;
  z-index: 2;
  top: 7px;
  left: 7px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.hero-codex-flags i {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  background: #111714d9;
  color: white;
  font-size: 8px;
  font-style: normal;
  white-space: nowrap;
}
.hero-codex-flags .season.s1 { background: #315b4ae8; }
.hero-codex-flags .season.s2 { background: #9b7135eb; }
.hero-codex-flags .status.internal_hidden { background: #71443fe8; }
.hero-codex-flags .status.official_hidden { background: #5b5650e8; }
.hero-codex-flags .status.story { background: #545b78e8; }
.hero-codex-flags .status.custom { background: #704e70e8; }

.hero-codex-name {
  display: block;
  min-width: 0;
  padding: 9px 2px 11px;
}

.hero-codex-name small {
  display: block;
  color: var(--muted);
  font-size: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-codex-name strong {
  display: block;
  margin-top: 3px;
  font: 600 14px 'Noto Serif KR';
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-codex-card > .own-toggle {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 7px;
  width: 30px;
  height: 30px;
  border: 1px solid #ffffff88;
  background: #111714cc;
  color: white;
}

.hero-codex-card > .own-toggle.owned { background: var(--jade); }
.hero-codex-open:hover .hero-codex-name strong { color: var(--jade); }

.skill-codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 14px 10px;
}

.skill-codex-card {
  position: relative;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  content-visibility: auto;
  contain-intrinsic-size: 145px 205px;
}

.skill-codex-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.skill-codex-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-bottom: 3px solid #817866;
  background: #d8d1c2;
}

.skill-codex-art.q3 { border-bottom-color: var(--gold); }
.skill-codex-art.q2 { border-bottom-color: var(--jade); }
.skill-codex-art img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center; }
.skill-codex-art > b { font: 600 34px 'Noto Serif KR'; color: var(--muted); }
.skill-codex-art > i {
  position: absolute;
  left: 7px;
  top: 7px;
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: #111714d9;
  color: #f5e2ae;
  font-size: 9px;
  font-style: normal;
}

.skill-codex-name { display: block; min-width: 0; padding: 9px 2px 11px; }
.skill-codex-name small { display: block; color: var(--muted); font-size: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skill-codex-name strong { display: block; margin-top: 3px; font: 600 14px 'Noto Serif KR'; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skill-codex-card > .own-skill-toggle {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 7px;
  width: 30px;
  height: 30px;
  border-color: #ffffff88;
  background: #111714cc;
  color: white;
}
.skill-codex-card > .own-skill-toggle.owned { background: var(--jade); border-color: var(--jade); }
.skill-codex-open:hover .skill-codex-name strong { color: var(--jade); }

.skill-filter-stack { margin-bottom: 28px; }
.skill-filter-stack .filter-line { margin-bottom: 0; }
.skill-filter-stack .filter-label {
  flex: 0 0 74px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
}
.skill-origin-line button { min-width: 104px; }

.hero-innate-skill > header {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 15px;
  align-items: center;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}
.hero-innate-skill > header .skill-icon { width: 64px; height: 64px; }
.hero-innate-skill > header small { color: var(--gold); font-size: 9px; letter-spacing: .1em; }
.hero-innate-skill > header h3 { margin: 4px 0; font: 600 20px 'Noto Serif KR'; }
.hero-innate-skill > header p { margin: 0; color: var(--muted); font-size: 10px; }
.hero-innate-skill .ingame-description { margin-top: 20px; }
.hero-innate-skill .meta-list { margin-top: 18px; }

.hero-fate-list { border-top: 1px solid var(--ink); }
.hero-fate-record { padding: 18px 2px; border-bottom: 1px solid var(--line); }
.hero-fate-record > header { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.hero-fate-record > header small { color: var(--gold); font-size: 9px; letter-spacing: .12em; }
.hero-fate-record > header h3 { margin: 4px 0 0; font: 600 17px 'Noto Serif KR'; }
.hero-fate-record > header > b { color: var(--jade); font-size: 10px; white-space: nowrap; }
.hero-fate-record > p { margin: 12px 0 0; color: #403e37; font: 500 12px/1.75 'Noto Serif KR'; }
.hero-fate-members {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.hero-fate-member { min-width: 0; }
.hero-fate-member-art {
  display: block;
  height: 142px;
  overflow: hidden;
  background: var(--paper2);
}
.hero-fate-member-art img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; }
.hero-fate-member-art > b { height: 100%; display: grid; place-items: center; font: 600 24px 'Noto Serif KR'; color: var(--muted); }
.hero-fate-member > strong { display: block; margin-top: 7px; font: 600 12px 'Noto Serif KR'; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-fate-member > small { display: block; margin-top: 2px; color: var(--muted); font-size: 8px; }
.innate-ownership { display: inline-block; margin-top: 14px; color: #d9b76c !important; font-size: 10px !important; letter-spacing: 0 !important; }

.skill-owner-heroes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.skill-owner-heroes button { padding: 0 0 10px; overflow: hidden; }
.skill-owner-art {
  display: block;
  height: 230px;
  overflow: hidden;
  background: var(--paper2);
}
.skill-owner-art img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; }
.skill-owner-art > b { height: 100%; display: grid; place-items: center; font: 600 28px 'Noto Serif KR'; color: var(--muted); }
.skill-owner-heroes button > span:last-child { padding: 0 10px; font: 600 12px 'Noto Serif KR'; }
.skill-owner-heroes button > span:last-child small { margin-top: 3px; font: 400 8px Pretendard; color: var(--muted); }

.fate-detail-heroes {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.fate-detail-heroes button {
  padding: 0 0 10px;
  overflow: hidden;
}

.fate-hero-art {
  display: grid;
  place-items: end center;
  width: 100%;
  height: 150px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 70%, #fff 0, #d9d3c6 72%);
}

.fate-hero-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
}

.fate-detail-heroes button > span:last-child { padding: 0 9px; }
.drawer { overscroll-behavior: contain; }
button, select, input { touch-action: manipulation; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.fate-list > .fate-row { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }

/* Detail views are centered records, not side drawers. Formation pickers remain drawers. */
.detail-modal-shade {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0c110ecc;
  overflow: hidden;
}

.detail-modal-shade .detail-drawer {
  position: relative;
  inset: auto;
  width: min(860px, calc(100vw - 48px));
  height: min(820px, calc(100vh - 48px));
  max-height: none;
  border: 1px solid #b8ae9b;
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  box-shadow: 0 24px 80px #0008;
  animation: none;
  transition: none;
}

.detail-modal-shade .detail-drawer > header {
  position: sticky;
  z-index: 12;
  top: 0;
  background: var(--paper);
}

.detail-modal-shade .hero-detail-art { height: 340px; grid-template-columns: 66% 34%; }
.detail-modal-shade .hero-art-frame { overflow: hidden; }
.detail-modal-shade .hero-art-frame img { object-fit: contain; object-position: center; }
.detail-modal-shade .detail-section { padding: 26px 32px 34px; }

@media (max-width: 760px) {
  .skill-filter-stack { margin: 0 -16px 18px; }
  .skill-filter-stack .filter-line { margin: 0; padding: 0 16px; }
  .skill-filter-stack .filter-label { flex-basis: 62px; }
  .skill-filter-stack .skill-origin-line { overflow: hidden; }
  .skill-filter-stack .skill-origin-line .filter-label { flex-basis: 55px; }
  .skill-origin-line button { min-width: 82px; padding: 0 7px; }
  .hero-codex-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 7px; }
  .skill-codex-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 7px; }
  .hero-codex-name strong { font-size: 13px; }
  .skill-codex-name strong { font-size: 12px; }
  .hero-fate-members { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero-fate-member-art { height: 132px; }
  .skill-owner-heroes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .skill-owner-art { height: 210px; }
  .fate-detail-heroes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fate-hero-art { height: 180px; }
  .detail-modal-shade { padding: 10px; }
  .detail-modal-shade .detail-drawer {
    width: calc(100vw - 20px);
    height: calc(100svh - 20px);
    max-height: none;
  }
  .detail-modal-shade .hero-detail-art {
    height: 390px;
    grid-template-columns: 1fr;
    grid-template-rows: 240px 150px;
  }
  .detail-modal-shade .hero-detail-name { align-self: center; padding: 0 18px 12px; }
  .detail-modal-shade .detail-section { padding: 22px 18px 28px; }
}

@media (max-width: 1000px) {
  .tier-catalog > article { grid-template-columns: 55px 1fr 50px 58px; }
  .catalog-heroes { grid-column: 2 / 5; }
}

@media (max-width: 760px) {
  .tier-catalog > article { grid-template-columns: 42px 1fr 46px 50px; }
  .catalog-heroes { grid-column: 1 / -1; }
  .catalog-open { grid-column: 3; grid-row: 1; }
  .catalog-apply { grid-column: 4; grid-row: 1; }
  .tier-inline-detail { margin-left: -16px; margin-right: -16px; }
  .formation-tabs { max-width: none; flex-wrap: nowrap; justify-content: flex-start; }
}
