/* Sectors: the campaign map (js/sections/sectors.js), after the game's SECTOR MAP screen.
   Desktop: war status bar, then list | globe | card.
   Under 1240px the list becomes a row of chips; under 760px everything stacks, globe first. */

.sectors__layout {
  --sx-gap: 28px;
  display: grid;
  grid-template-columns: clamp(280px, 23vw, 336px) minmax(0, 1fr) clamp(320px, 26vw, 380px);
  grid-template-areas: "hud hud hud" "list globe card";
  column-gap: var(--sx-gap);
}

/* ---------- state marks: shape + word + colour (retaken: bone disc + check, next: amber disc + arrow,
   infested: hollow flesh ring + lock), the same glyphs as the game's list, card and legend ---------- */
.sx-mark {
  position: relative; z-index: 1; display: inline-grid; place-items: center; flex: none;
  width: 18px; height: 18px; border-radius: 50%;
}
.sx-mark svg { width: 64%; height: 64%; }
.sx-mark--secured { background: var(--bone); color: var(--bg-0); box-shadow: 0 0 0 3px var(--bg-0); }
.sx-mark--next { background: var(--amber); color: var(--amber-ink); box-shadow: 0 0 0 3px var(--bg-0), 0 0 0 6px rgba(255, 177, 46, 0.28), 0 0 16px var(--amber-glow); }
.sx-mark--locked { background: var(--bg-0); color: var(--flesh); box-shadow: inset 0 0 0 1.5px var(--flesh), 0 0 0 3px var(--bg-0); }
.sx-mark--locked svg { width: 54%; height: 54%; }

.sx .pill svg { width: 12px; height: 12px; flex: none; }
/* the stance reads as data, not as a state: neutral whatever the stance, as on the game's sector card */
.sx-card__tags .pill { color: var(--bone-2); background: rgba(236, 230, 217, 0.04); box-shadow: inset 0 0 0 1px var(--line-3); }

/* ---------- war status ---------- */
.sx-hud {
  grid-area: hud; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px 28px; padding-bottom: 18px; border-bottom: 1px solid var(--line);
}
.sx-hud__op { font-size: var(--t-small); font-weight: 500; color: var(--bone-3); }
.sx-war { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.sx-war__count { display: flex; align-items: baseline; gap: 8px; font-size: var(--t-small); font-weight: 500; color: var(--bone-2); white-space: nowrap; }
.sx-war__count b { font-family: var(--f-display); font-weight: 700; font-size: 1.6rem; line-height: 1; color: var(--bone); font-variant-numeric: tabular-nums; }
.sx-war__count .sx-reclaimed {
  display: inline-block; padding: 4px 14px 3px; font-weight: 800; font-size: 1.15rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--amber-ink); background: var(--amber);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  animation: sx-in var(--d-slow) var(--ease-out) both;
}
.sx-pips i { transition: background var(--d-med) var(--ease-out); }
.sx-war__sep { width: 1px; height: 22px; background: var(--line-2); }
.sx-war__hive { display: flex; align-items: baseline; gap: 8px; font-size: var(--t-small); font-weight: 500; color: var(--bone-2); white-space: nowrap; }
.sx-war__hive b { font-family: var(--f-display); font-weight: 700; font-size: 1.3rem; line-height: 1; color: var(--flesh); font-variant-numeric: tabular-nums; }
.sx-bar { width: 88px; height: 3px; background: var(--line-2); }
.sx-bar i { display: block; height: 100%; width: 100%; background: var(--flesh); box-shadow: 0 0 10px var(--flesh-glow); transition: width var(--d-slow) var(--ease-out); }
.sx.is-reclaimed .sx-war__hive b { color: var(--bone-3); }
.sx-reset { min-height: 30px; margin: -4px 0; }
.sx-reset[hidden] { display: none; }

/* ---------- sector list (tabs) ---------- */
.sx-list { grid-area: list; position: relative; align-self: start; margin: 22px 0; border-top: 1px solid var(--line); }
.sx-row {
  position: relative; display: grid; grid-template-columns: 22px 20px minmax(0, 1fr); align-items: center; gap: 0 12px;
  width: 100%; min-height: 56px; padding: 0 12px; text-align: left; border-bottom: 1px solid var(--line);
  transition: background-color var(--d-med) var(--ease-out), box-shadow var(--d-fast);
}
.sx-row:hover { background-color: rgba(236, 230, 217, 0.035); }
.sx-row:focus-visible { outline: 2px solid var(--bone); outline-offset: -2px; }
.sx-row__n { font-family: var(--f-display); font-weight: 600; font-size: var(--t-small); color: var(--bone-3); font-variant-numeric: tabular-nums; transition: color var(--d-fast); }
.sx-row__txt { min-width: 0; padding: 9px 0; }
.sx-row__name {
  display: block; font-family: var(--f-display); font-weight: 600; font-size: 1.15rem; line-height: 1.05;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--bone-2);
  transition: color var(--d-fast), transform var(--d-med) var(--ease-out);
}
.sx-row__reg { display: flex; align-items: center; gap: 5px; margin-top: 3px; font-size: var(--t-micro); font-weight: 500; color: var(--bone-3); }
.sx-row__where { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* stance: a quiet glyph before the region, like the game's list (the card spells it out) */
.sx-row__stance { display: inline-grid; flex: none; }
.sx-row__stance svg { width: 11px; height: 11px; }

/* the campaign track: solid bone into ground that isn't hive-held, dashed flesh into ground that is */
.sx-row__rail { position: relative; align-self: stretch; display: grid; place-items: center; }
.sx-row__rail::before, .sx-row__rail::after { content: ''; position: absolute; left: calc(50% - 1px); width: 2px; }
.sx-row__rail::before { top: 0; height: 50%; }
.sx-row__rail::after { top: 50%; bottom: -1px; }
.sx-row[data-up='on'] .sx-row__rail::before, .sx-row[data-down='on'] .sx-row__rail::after { background: var(--bone-3); }
.sx-row[data-up='off'] .sx-row__rail::before, .sx-row[data-down='off'] .sx-row__rail::after { background: repeating-linear-gradient(180deg, rgba(255, 63, 134, 0.5) 0 3px, transparent 3px 7px); }
.sx-list li:first-child .sx-row__rail::before, .sx-list li:last-child .sx-row__rail::after { display: none; }

.sx-row[data-state='locked'] .sx-row__name { color: var(--bone-3); }
.sx-row[data-state='secured'] .sx-row__name { color: var(--bone-2); }
.sx-row[data-state='next'] { background-image: linear-gradient(90deg, rgba(255, 177, 46, 0.11), rgba(255, 177, 46, 0.03) 70%, transparent); }
.sx-row[data-state='next'] .sx-row__n { color: var(--amber); }

/* selection is neutral (bone spine + hairline), never a state colour */
.sx-row::after {
  content: ''; position: absolute; left: 0; top: 18%; bottom: 18%; width: 3px; background: var(--bone);
  opacity: 0; transform: scaleY(0.2); transition: transform var(--d-med) var(--ease-snap), opacity var(--d-fast);
}
.sx-row[aria-selected='true'] { background-color: rgba(236, 230, 217, 0.05); box-shadow: inset 0 0 0 1px var(--line-2); }
.sx-row[aria-selected='true']::after { opacity: 1; transform: none; }
.sx-row[aria-selected='true'] .sx-row__name { color: var(--bone); transform: translateX(4px); }

/* a sector retaken in front of the visitor: the row flashes, the mark stamps in */
.sx-row.is-retaking::before { content: ''; position: absolute; inset: 0; pointer-events: none; animation: sx-flash 1100ms var(--ease-out) both; }
.sx-row.is-retaking .sx-mark { animation: sx-mark 560ms var(--ease-snap) both; }
@keyframes sx-flash { from { background-color: rgba(236, 230, 217, 0.18); } to { background-color: rgba(236, 230, 217, 0); } }
@keyframes sx-mark { 0% { transform: scale(2.4); opacity: 0; } 55% { transform: scale(0.88); opacity: 1; } 100% { transform: none; opacity: 1; } }

/* ---------- globe ---------- */
.sx-globe { grid-area: globe; position: relative; min-height: 540px; margin: 22px 0; }
/* the holotable's floor grid, fading out from the globe */
.sx-globe::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.6;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 56px 56px; background-position: center 47%;
  -webkit-mask-image: radial-gradient(closest-side at 50% 47%, #000, transparent);
  mask-image: radial-gradient(closest-side at 50% 47%, #000, transparent);
}
.sx-globe__c {
  position: absolute; top: 0; left: calc(-1 * var(--sx-gap)); width: calc(100% + 2 * var(--sx-gap)); height: 100%;
  opacity: 0; transition: opacity 900ms var(--ease-out);
  touch-action: pan-y pinch-zoom; -webkit-tap-highlight-color: transparent; user-select: none;
}
.sx-globe.is-ready .sx-globe__c { opacity: 1; }
.sx-globe__c.is-pin { cursor: url('../assets/cursors/select.png') 3 2, pointer; cursor: image-set(url('../assets/cursors/select.png') 1x, url('../assets/cursors/select@2x.png') 2x) 3 2, pointer; }
.sx-globe__c.is-dragging { cursor: grabbing; }

/* ---------- the selected sector's card ---------- */
.sx-card { grid-area: card; --cut: 14px; display: flex; flex-direction: column; gap: 16px; margin: 22px 0; padding: 22px 22px 20px; }
.sx-card::after { content: ''; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--amber); transition: background var(--d-med) ease; }
.sx-card[data-state='secured']::after { background: var(--bone); }
.sx-card__meta { font-size: var(--t-small); font-weight: 500; color: var(--bone-3); }
.sx-card__name {
  margin: 6px 0 14px; font-family: var(--f-display); font-weight: 800; font-size: clamp(2rem, 2.6vw, 2.5rem);
  line-height: 0.92; letter-spacing: 0.01em; text-transform: uppercase; color: var(--bone);
}
.sx-card__tags { display: flex; flex-wrap: wrap; gap: 8px; }
.sx-card__tags > span { display: inline-flex; }

/* status: arrow + "Next operation" on amber, check + "Retaken" in bone */
.sx-state {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px;
  font-family: var(--f-display); font-weight: 700; font-size: 0.78rem; letter-spacing: var(--track-prompt); text-transform: uppercase;
  border-radius: var(--r-1); transition: background var(--d-med), color var(--d-med);
}
.sx-state svg { width: 12px; height: 12px; }
.sx-state[data-state='next'] { background: var(--amber); color: var(--amber-ink); }
.sx-state[data-state='secured'] { background: rgba(236, 230, 217, 0.1); color: var(--bone); box-shadow: inset 0 0 0 1px var(--line-3); }

/* the sector's real map: slow drift, a hive cast until it is retaken */
.sx-map { position: relative; flex: 1 1 auto; min-height: 200px; margin: 0; overflow: hidden; background: var(--bg-2); border-radius: var(--r-1); isolation: isolate; }
.sx-map__pan { position: absolute; inset: 0; transform: scale(1.16); will-change: transform; }
.sx-map__pan img {
  position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; opacity: 0;
  filter: saturate(0.75) brightness(0.8);
  transition: opacity var(--d-slow) var(--ease-out), filter var(--d-slow) var(--ease-out);
}
.sx-map__pan img.is-on { opacity: 1; }
.sx-card[data-state='secured'] .sx-map__pan img { filter: saturate(1) brightness(0.95); }
.sx-map__tint {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(90% 80% at 50% 45%, rgba(255, 63, 134, 0.05), rgba(92, 15, 44, 0.36));
  transition: opacity var(--d-slow) var(--ease-out);
}
.sx-card[data-state='secured'] .sx-map__tint { opacity: 0; }
/* vignette + corner brackets */
.sx-map__frame {
  position: absolute; inset: 0; pointer-events: none; --c: rgba(236, 230, 217, 0.55); --b: 14px;
  box-shadow: inset 0 0 70px rgba(5, 6, 7, 0.75);
  background:
    linear-gradient(var(--c) 0 0) 10px 10px / var(--b) 1.5px, linear-gradient(var(--c) 0 0) 10px 10px / 1.5px var(--b),
    linear-gradient(var(--c) 0 0) calc(100% - 10px) 10px / var(--b) 1.5px, linear-gradient(var(--c) 0 0) calc(100% - 10px) 10px / 1.5px var(--b),
    linear-gradient(var(--c) 0 0) 10px calc(100% - 10px) / var(--b) 1.5px, linear-gradient(var(--c) 0 0) 10px calc(100% - 10px) / 1.5px var(--b),
    linear-gradient(var(--c) 0 0) calc(100% - 10px) calc(100% - 10px) / var(--b) 1.5px, linear-gradient(var(--c) 0 0) calc(100% - 10px) calc(100% - 10px) / 1.5px var(--b);
  background-repeat: no-repeat;
}
.sx-map__cap {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 22px 16px 11px; font-size: var(--t-micro); font-weight: 500; color: var(--bone-2); white-space: pre;
  background: linear-gradient(180deg, transparent, rgba(5, 6, 7, 0.82));
  font-variant-numeric: tabular-nums;
}
.sx-map__cap span:last-child { display: inline-flex; align-items: center; gap: 6px; }
.sx-map__cap svg { width: 13px; height: 13px; color: var(--bone-3); }
.sx-map__stamp {
  position: absolute; left: 50%; top: 44%; display: inline-flex; align-items: center; gap: 8px; padding: 5px 16px 5px 12px;
  font-family: var(--f-display); font-weight: 800; font-size: 1.7rem; line-height: 1; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--bone); background: rgba(5, 6, 7, 0.5); border: 2.5px solid var(--bone); border-radius: var(--r-2);
  transform: translate(-50%, -50%) rotate(-9deg); opacity: 0; pointer-events: none;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.45);
}
.sx-map__stamp svg { width: 22px; height: 22px; }
.sx-card[data-state='secured'] .sx-map__stamp { opacity: 1; }
.sx-card.is-stamping .sx-map__stamp { animation: sx-stamp 520ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes sx-stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-30deg) scale(2.2); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-9deg) scale(1); }
}
/* retaking: fills while the visitor stays on the sector */
.sx-map__bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(236, 230, 217, 0.1); opacity: 0; transition: opacity var(--d-med); }
.sx-map__bar i { display: block; height: 100%; background: var(--amber); box-shadow: 0 0 10px var(--amber-glow); transform-origin: left; transform: scaleX(0); }
.sx-card.is-dwelling .sx-map__bar { opacity: 1; }

/* the briefing: Col. Reyes, his first line for the sector. On a narrow card the portrait gives up some
   width (down to 56px) so the Play button stays inside. */
.sx-brief { display: grid; grid-template-columns: minmax(56px, 84px) auto; gap: 12px 16px; align-items: end; }
.sx-brief__face { width: 100%; align-self: end; }
.sx-brief__who { display: grid; justify-items: start; gap: 2px; padding-bottom: 4px; }
.sx-brief__spk { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 1rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--bone); }
.sx-brief__role { font-size: var(--t-micro); font-weight: 500; color: var(--bone-3); }
.sx-wave { display: inline-flex; align-items: center; gap: 2px; height: 16px; }
.sx-wave i { width: 2.5px; height: 100%; border-radius: 1px; background: var(--amber); opacity: 0.85; transition: transform 90ms linear; }
.sx-play { margin-top: 10px; }
.sx-play svg { width: 14px; height: 14px; }
.sx-brief__line { grid-column: 1 / -1; min-height: calc(3 * 1.45em); font-size: 1.02rem; line-height: 1.45; color: var(--bone-3); }
.sx-brief__line .sub-line .w { opacity: 1; filter: none; transform: none; color: var(--bone-3); transition: color 260ms ease; }
.sx-brief__line .sub-line .w.on { color: var(--bone); }
.sx-card.is-live .sx-brief__line { color: var(--bone); }

/* a new sector: the head and the line come up */
.sx-card.is-swap .sx-card__head > *, .sx-card.is-swap .sx-brief__line { animation: sx-in var(--d-med) var(--ease-out) both; }
.sx-card.is-swap .sx-card__name { animation-delay: 40ms; }
.sx-card.is-swap .sx-card__tags { animation-delay: 80ms; }
.sx-card.is-swap .sx-brief__line { animation-delay: 120ms; }
@keyframes sx-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }


/* ---------- tablet: chips above, globe | card ---------- */
@media (max-width: 1239px) {
  .sectors__layout {
    grid-template-columns: minmax(0, 1fr) clamp(300px, 40vw, 380px);
    grid-template-areas: "hud hud" "list list" "globe card";
  }
  .sx-list {
    display: flex; gap: 8px; margin: 18px calc(-1 * var(--gutter)) 0; padding: 4px var(--gutter) 8px; border-top: 0;
    overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scroll-padding: 0 var(--gutter);
    scrollbar-width: thin; scrollbar-color: var(--line-3) transparent;
  }
  .sx-list li { flex: none; scroll-snap-align: center; }
  .js .sx-list > [data-reveal] { transform: none; }   /* chips fade in where they are: a rise would overflow the strip */
  .sx-row {
    grid-template-columns: auto auto auto; gap: 0 9px; width: auto; min-height: 44px; padding: 0 14px 0 12px;
    border: 1px solid var(--line-2); border-radius: var(--r-2); white-space: nowrap;
  }
  .sx-row__txt { padding: 0; }
  .sx-row__name { font-size: 1.05rem; }
  .sx-row__reg, .sx-row__rail::before, .sx-row__rail::after { display: none; }
  .sx-row::after { left: 10px; right: 10px; top: auto; bottom: -1px; width: auto; height: 2px; transform: scaleX(0.2); }
  .sx-row[aria-selected='true'] { border-color: var(--line-3); }
  .sx-row[aria-selected='true'] .sx-row__name { transform: none; }
  .sx-mark { width: 16px; height: 16px; }
  .sx-globe__c { left: 0; width: 100%; }
}

/* ---------- phone: hud, globe (square, edge to edge), chips, card ---------- */
@media (max-width: 759px) {
  .sectors__layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "hud" "globe" "list" "card"; }
  .sx-hud { gap: 8px 20px; padding-bottom: 14px; }
  .sx-hud__op { display: none; }
  .sx-war { gap: 10px 14px; }
  .sx-war__sep { display: none; }
  .sx-bar { width: 64px; }
  .sx-globe { min-height: 0; aspect-ratio: 1; margin: 6px calc(-1 * var(--gutter)) 0; }
  .sx-list { margin-top: 22px; }
  .sx-card { margin: 14px 0 0; padding: 20px 18px 18px; }
  .sx-map { flex: none; min-height: 0; aspect-ratio: 16 / 10; }
  .sx-brief { grid-template-columns: minmax(56px, 72px) auto; gap: 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .sx-map__pan { will-change: auto; }
}
:root[data-motion='off'] .sx-map__pan { will-change: auto; }
