/* ui/PilotProfile — contract: ./PilotProfile.spec.md. Tokens from ui/Theme; the panel's plate is
   ui/Theme's skin. A Sproks pilot's page: the ship on the lift, who they are, six numbers, the
   three weapon lines, the boards, the last runs. */

/* A layer over the menu. Closed, it holds nothing and takes no pointer. */
.sp-pilot-profile {
  position: fixed;
  inset: 0;
  z-index: 44;
  pointer-events: none;
}

/* Modal: the scrim dims the menu and takes the pointer; a click closes. */
.sp-pilot-profile__scrim {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, var(--sp-space-0) 72%, transparent);
  pointer-events: auto;
  animation: sp-pilot-profile-dim var(--sp-dur) var(--sp-ease-out) both;
}

/* Desktop: a centred panel, bounded by the viewport, whose body scrolls under a fixed head. */
.sp-pilot-profile__panel {
  position: fixed;
  top: 50%;
  left: 50%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  box-sizing: border-box;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  color: var(--sp-text);
  background: var(--sp-space-1);
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius);
  overflow: hidden;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  animation: sp-pilot-profile-in var(--sp-dur) var(--sp-ease-out) both;
}

/* A thumb target, top right, above the hero. */
.sp-pilot-profile__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 15px;
  color: var(--sp-text);
  background: var(--sp-space-2);
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 var(--sp-edge-light), 0 2px 0 var(--sp-edge-dark);
  cursor: pointer;
}
.sp-pilot-profile__close:hover { background: color-mix(in srgb, var(--sp-text) 10%, var(--sp-space-2)); }

/* The head: the bay with the pilot's ship on the left, who they are on the right, a seam under it. */
.sp-pilot-profile__hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  padding: 18px 64px 16px 20px;
  border-bottom: 3px solid var(--sp-seam);
  background: linear-gradient(180deg, var(--sp-space-2), var(--sp-space-1));
  box-shadow: inset 0 1px 0 var(--sp-edge-light);
}

/* The bay: the ship under the bay light, a strip of hazard tape for the lift's edge, its brass
   tag, and under the tag which run it is from. */
.sp-pilot-profile__bay {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 6px;
  width: 168px;
}
.sp-pilot-profile__ship {
  width: 148px;
  height: 132px;
  background:
    var(--sp-tape) center bottom / 120px 8px no-repeat,
    radial-gradient(ellipse 60% 80% at 50% 0%, color-mix(in srgb, var(--sp-quanta) 10%, transparent), transparent 72%);
}
.sp-pilot-profile__ship-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 4px 10px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--sp-quanta) 80%, white), color-mix(in srgb, var(--sp-quanta) 86%, black));
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 color-mix(in srgb, white 45%, transparent), 0 2px 0 var(--sp-edge-dark);
}
.sp-pilot-profile__ship-name {
  min-width: 0;
  overflow: hidden;
  font: 600 14px/1.2 var(--sp-font-display);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--sp-ink);
}
.sp-pilot-profile__ship-from {
  margin: 0;
  font: 500 13px/1 var(--sp-font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sp-text-faint);
}

/* A tier chip: light on a row, dark on the brass tag. */
.sp-pilot-profile__tier {
  flex: none;
  padding: 2px 6px;
  font: 700 12px/1 var(--sp-font-mono);
  color: var(--sp-text);
  border: 1px solid var(--sp-line-strong);
  border-radius: 2px;
}
.sp-pilot-profile__ship-tag .sp-pilot-profile__tier { color: var(--sp-ink); border-color: var(--sp-ink); }

.sp-pilot-profile__who {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.sp-pilot-profile__name {
  margin: 0;
  overflow: hidden;
  font: 700 34px/1.05 var(--sp-font-display);
  letter-spacing: 0.03em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 3px 0 var(--sp-edge-dark);
}
.sp-pilot-profile__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

/* The title, as ui/PilotTag draws it, whole: a profile has the room. */
.sp-pilot-profile__title {
  --rarity: var(--sp-rarity-common);
  padding: 2px 8px;
  border-radius: 2px;
  background: color-mix(in oklab, var(--rarity) 18%, transparent);
  color: color-mix(in oklab, var(--rarity) 80%, var(--sp-text));
  font: 700 12px/18px var(--sp-font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sp-pilot-profile__title[data-rarity="rare"] { --rarity: var(--sp-rarity-rare); }
.sp-pilot-profile__title[data-rarity="epic"] { --rarity: var(--sp-rarity-epic); }
.sp-pilot-profile__title[data-rarity="legendary"] { --rarity: var(--sp-rarity-legendary); }

/* "You": this is the selected pilot, so it is the selection's blue. */
.sp-pilot-profile__you {
  padding: 2px 8px;
  border-radius: 2px;
  background: var(--sp-select);
  color: var(--sp-ink);
  font: 700 12px/18px var(--sp-font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sp-pilot-profile__meta {
  margin: 0;
  font-size: 13px;
  color: var(--sp-text-dim);
}

/* One column, never wider than the panel: nothing on it scrolls sideways. */
.sp-pilot-profile__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 16px;
  padding: 16px 20px 24px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sp-pilot-profile__notice {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  color: var(--sp-text-dim);
}
.sp-pilot-profile__none {
  margin: 0;
  font-size: 13px;
  color: var(--sp-text-faint);
}

/* The six numbers: small riveted plates, the label stamped over the figure. */
.sp-pilot-profile__stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}
.sp-pilot-profile__stat {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 10px 10px 9px;
  background: var(--sp-plate);
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 var(--sp-edge-light), 0 2px 0 var(--sp-edge-dark);
}
.sp-pilot-profile__stat dt {
  font: 500 13px/1.1 var(--sp-font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sp-text-faint);
  overflow-wrap: anywhere;
}
.sp-pilot-profile__stat dd {
  margin: 0;
  font: 600 20px/1 var(--sp-font-mono);
  font-variant-numeric: tabular-nums;
}
/* What was earned is brass; the rest is plain. */
.sp-pilot-profile__stat[data-stat="best"] dd,
.sp-pilot-profile__stat[data-stat="extractions"] dd { color: var(--sp-quanta); }
.sp-pilot-profile__flown {
  margin: -6px 0 0;
  font: 400 12px/1.3 var(--sp-font-mono);
  color: var(--sp-text-faint);
}

.sp-pilot-profile__section {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.sp-pilot-profile__section h3 { margin: 0; }
.sp-pilot-profile__list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A weapon line: its name in its own colour, its mastery, a gauge of how much it is flown. */
.sp-pilot-profile__weapon {
  --weapon: var(--sp-accent);
  display: grid;
  grid-template-columns: minmax(84px, 120px) 78px minmax(60px, 1fr) minmax(64px, auto) minmax(96px, auto);
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 6px 12px;
  background: var(--sp-space-1);
  border: 1px solid var(--sp-seam);
  border-left: 4px solid var(--weapon);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 var(--sp-edge-light);
}
.sp-pilot-profile__weapon[data-weapon="laser"] { --weapon: var(--sp-ship-laser); }
.sp-pilot-profile__weapon[data-weapon="scatter"] { --weapon: var(--sp-ship-scatter); }
.sp-pilot-profile__weapon[data-weapon="rocket"] { --weapon: var(--sp-ship-rocket); }
.sp-pilot-profile__weapon-name {
  font: 600 15px/1.1 var(--sp-font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--weapon);
}
.sp-pilot-profile__weapon-level {
  font: 600 13px/1 var(--sp-font-mono);
  white-space: nowrap;
}
.sp-pilot-profile__bar {
  height: 8px;
  border: 1px solid var(--sp-seam);
  border-radius: 2px;
  background: linear-gradient(90deg, var(--weapon) calc(var(--share, 0) * 100%), var(--sp-well) calc(var(--share, 0) * 100%));
  box-shadow: var(--sp-inset);
}
.sp-pilot-profile__figure {
  font: 400 12px/1.2 var(--sp-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--sp-text-dim);
  white-space: nowrap;
}

/* The boards: one small plate a placing. */
.sp-pilot-profile__placings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sp-pilot-profile__placing {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--sp-text-dim);
  background: var(--sp-space-1);
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 var(--sp-edge-light);
}
.sp-pilot-profile__placing strong {
  font: 700 15px/1 var(--sp-font-mono);
  color: var(--sp-quanta);
}

/* A recent run: the ship, its name and tier, how it ended, its numbers, its score, when. The name
   gives way (ellipsis) before the numbers do. */
.sp-pilot-profile__run {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 4px 12px 4px 6px;
  background: var(--sp-space-1);
  border: 1px solid var(--sp-seam);
  border-radius: var(--sp-radius-sm);
  box-shadow: inset 0 1px 0 var(--sp-edge-light);
}
.sp-pilot-profile__run-art {
  width: 44px;
  height: 44px;
}
.sp-pilot-profile__run-ship {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.sp-pilot-profile__run-name {
  min-width: 0;
  overflow: hidden;
  font: 600 14px/1.2 var(--sp-font-display);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
/* How it ended is a stamped word, never a colour alone. */
.sp-pilot-profile__outcome {
  padding: 3px 7px 2px;
  font: 600 13px/1 var(--sp-font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--sp-text-dim);
  border: 1px solid var(--sp-line-strong);
  border-radius: 2px;
}
.sp-pilot-profile__outcome[data-outcome="extracted"] { color: var(--sp-ink); background: var(--sp-quanta); border-color: var(--sp-seam); }
.sp-pilot-profile__outcome[data-outcome="destroyed"] { color: var(--sp-danger); border-color: color-mix(in srgb, var(--sp-danger) 60%, transparent); }
.sp-pilot-profile__unranked { color: var(--sp-text-faint); }
.sp-pilot-profile__score {
  min-width: 56px;
  font: 600 15px/1 var(--sp-font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.sp-pilot-profile__when {
  min-width: 58px;
  font: 400 12px/1 var(--sp-font-mono);
  color: var(--sp-text-faint);
  text-align: right;
  white-space: nowrap;
}

/* Hide my stats: your own profile only. */
.sp-pilot-profile__privacy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}
.sp-pilot-profile__switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0;
  font: 600 14px/1 var(--sp-font-ui);
  color: var(--sp-text);
  background: none;
  border: 0;
  cursor: pointer;
}
.sp-pilot-profile__switch:disabled { opacity: 0.55; cursor: progress; }
.sp-pilot-profile__switch-track {
  flex: none;
  width: 40px;
  height: 22px;
  padding: 2px;
  background: var(--sp-well);
  border: 1px solid var(--sp-seam);
  border-radius: 3px;
  box-shadow: var(--sp-inset);
}
.sp-pilot-profile__switch-knob {
  display: block;
  width: 16px;
  height: 16px;
  background: var(--sp-text-dim);
  border-radius: 2px;
  transition: transform var(--sp-dur-fast) var(--sp-ease-out);
}
.sp-pilot-profile__switch[aria-checked="true"] .sp-pilot-profile__switch-track { background: var(--sp-select); }
.sp-pilot-profile__switch[aria-checked="true"] .sp-pilot-profile__switch-knob { background: var(--sp-ink); transform: translateX(18px); }
.sp-pilot-profile__privacy-note {
  font-size: 12px;
  color: var(--sp-text-faint);
}

/* Report pilot: quiet, never hidden. */
.sp-pilot-profile__report {
  display: grid;
  justify-items: start;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--sp-line);
}
.sp-pilot-profile__report-button {
  min-height: 44px;
  padding: 0;
  font: 500 13px/1 var(--sp-font-ui);
  color: var(--sp-text-faint);
  text-decoration: underline;
  background: none;
  border: 0;
  cursor: pointer;
}
.sp-pilot-profile__report-button:hover { color: var(--sp-text-dim); }
.sp-pilot-profile__report-confirm {
  display: grid;
  gap: 8px;
  width: 100%;
}
.sp-pilot-profile__report-question {
  margin: 0;
  font-weight: 600;
}
.sp-pilot-profile__error {
  margin: 0;
  font-size: 13px;
  color: var(--sp-danger);
}
.sp-pilot-profile__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* No Theme minimum width here: a 280 px primary once widened the sheet past a phone. */
.sp-pilot-profile__actions .sp-button {
  min-width: 0;
  min-height: 44px;
  padding: 0 18px;
}

/* A short landscape (a phone on its side): the panel takes the whole height, the head is one
   compact row, and the numbers stay six across. */
@media (max-height: 560px) and (min-width: 600px) {
  .sp-pilot-profile__panel {
    width: min(760px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: calc(100dvh - 8px);
  }
  .sp-pilot-profile__hero { gap: 12px; padding: 8px 60px 8px 12px; }
  .sp-pilot-profile__bay { grid-template-columns: auto auto; align-items: center; width: auto; gap: 4px 10px; }
  .sp-pilot-profile__ship { grid-row: span 2; width: 72px; height: 64px; background-size: 60px 6px, auto; }
  .sp-pilot-profile__ship-tag { align-self: end; }
  .sp-pilot-profile__ship-from { align-self: start; justify-self: start; }
  .sp-pilot-profile__name { font-size: 24px; }
  .sp-pilot-profile__who { gap: 4px; }
  .sp-pilot-profile__body { gap: 12px; padding: 10px 12px 16px; }
  .sp-pilot-profile__stat { padding: 7px 8px 6px; gap: 4px; }
  .sp-pilot-profile__stat dd { font-size: 17px; }
  /* Six across a 667 px phone is 79 px a label: 12 px and tighter, so "Extractions" stays one word. */
  .sp-pilot-profile__stat dt { font-size: 12px; letter-spacing: 0.02em; }
}

/* Phone, portrait: a bottom sheet. */
@media (max-width: 599px), (max-width: 899px) and (min-height: 561px) {
  .sp-pilot-profile__panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 92dvh;
    border-bottom: 0;
    border-radius: var(--sp-radius) var(--sp-radius) 0 0;
    transform: none;
    animation-name: sp-pilot-profile-up;
  }
  .sp-pilot-profile__hero { gap: 12px; padding: 14px 60px 12px 14px; }
  .sp-pilot-profile__bay { width: 124px; }
  .sp-pilot-profile__ship { width: 112px; height: 100px; background-size: 92px 7px, auto; }
  .sp-pilot-profile__name { font-size: 24px; white-space: normal; overflow-wrap: anywhere; }
  .sp-pilot-profile__body { padding: 14px 14px calc(28px + env(safe-area-inset-bottom)); }
  .sp-pilot-profile__stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* A weapon line on two rows: name and level, then the figures; the gauge is the desktop's. */
  .sp-pilot-profile__weapon { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
  .sp-pilot-profile__bar { display: none; }
  /* A run on three rows: the ship and how it ended; its numbers (which may wrap) and its score;
     when. Nothing shares a cell, so a long language never runs one figure into the next. */
  .sp-pilot-profile__run { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 3px 8px; padding: 6px 10px 6px 6px; }
  .sp-pilot-profile__run-art { grid-row: 1 / span 3; align-self: start; }
  .sp-pilot-profile__run-ship { grid-column: 2; grid-row: 1; }
  .sp-pilot-profile__outcome { grid-column: 3; grid-row: 1; justify-self: end; }
  .sp-pilot-profile__run-detail { grid-column: 2; grid-row: 2; white-space: normal; }
  .sp-pilot-profile__score { grid-column: 3; grid-row: 2; min-width: 0; }
  .sp-pilot-profile__when { grid-column: 2 / span 2; grid-row: 3; min-width: 0; text-align: left; }
}

@keyframes sp-pilot-profile-dim { from { opacity: 0; } }
@keyframes sp-pilot-profile-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)); } }
@keyframes sp-pilot-profile-up { from { transform: translateY(24px); opacity: 0; } }
