/* ui/UpgradePicker — contract: ./UpgradePicker.spec.md. Tokens from ui/Theme. */

.qc-picker {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* track = viewport width, so the panel can't overflow */
  justify-items: center;
  /* `safe`: a centred panel taller than the viewport overflows both ends and
     its top can never be scrolled to, which on a landscape phone would hide
     the first card. Safe alignment falls back to start when it would not fit. */
  align-items: safe center;
  padding: 32px 24px;
  overflow-y: auto;
  background: radial-gradient(
    ellipse 90% 80% at 50% 50%,
    color-mix(in oklab, var(--qc-space-0) 62%, transparent),
    color-mix(in oklab, var(--qc-space-0) 88%, transparent)
  );
  backdrop-filter: blur(3px);
  animation: qc-picker-fade var(--qc-dur) ease-out both;
}

.qc-picker__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  width: min(1040px, 100%);
}

.qc-picker__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.qc-picker__title {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 0;
  font-size: clamp(18px, 2.4vw, 26px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: var(--qc-text);
}

.qc-picker__title::before,
.qc-picker__title::after {
  content: "";
  width: 72px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--qc-line-strong));
}

.qc-picker__title::before {
  margin-right: 0.36em; /* matches the trailing letter-spacing on the right */
}

.qc-picker__title::after {
  transform: scaleX(-1);
}

@media (max-width: 560px) {
  .qc-picker__title {
    letter-spacing: 0.24em;
  }

  .qc-picker__title::before,
  .qc-picker__title::after {
    display: none;
  }
}

.qc-picker__meta {
  margin: 0;
  font-size: 13px;
  color: var(--qc-text-dim);
}

.qc-picker__pending {
  color: var(--qc-rarity-legendary);
}

.qc-picker__cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 18px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.qc-picker__slot {
  display: flex;
  flex-direction: column;
  animation: qc-picker-card 460ms var(--qc-ease-out) both;
  animation-delay: calc(var(--i, 0) * 70ms + 60ms);
}

.qc-picker__slot > .qc-card {
  flex: 1;
  min-height: 260px;
}

/* The suggestion: a label above the card and a lit border, and nothing that
   looks like a selection. The player always chooses. */
.qc-picker__suggested {
  align-self: flex-start;
  margin-bottom: 6px;
  padding: 3px 9px;
  font: 700 12px/1.2 var(--qc-font-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--qc-accent-2);
  border: 1px dashed color-mix(in oklab, var(--qc-accent-2) 60%, transparent);
  border-radius: var(--qc-radius-sm);
}

.qc-picker__slot[data-suggested="true"] > .qc-card {
  outline: 1px dashed color-mix(in oklab, var(--qc-accent-2) 55%, transparent);
  outline-offset: 3px;
}

/* The Keystone (level 18): a gold frame, and the title says it too. */
.qc-picker[data-keystone="true"] .qc-picker__panel {
  padding: 20px;
  border: 2px solid var(--qc-rarity-legendary);
  border-radius: var(--qc-radius-sm);
  box-shadow: 0 0 28px -8px color-mix(in oklab, var(--qc-rarity-legendary) 70%, transparent);
}

.qc-picker[data-keystone="true"] .qc-picker__title {
  color: var(--qc-rarity-legendary);
}

/* ------------------------------------------------------------- forms --- */

/* A form's stage sits on top of its card as one piece: the grown hull, and
   an apex's kind under it. The parent draws the hull into the canvas. */
.qc-picker__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 12px 8px;
  background: radial-gradient(ellipse 70% 90% at 50% 60%,
    color-mix(in oklab, var(--qc-rarity-legendary) 14%, transparent), transparent),
    var(--qc-space-1);
  border: 1px solid var(--qc-line-strong);
  border-bottom: none;
  border-radius: var(--qc-radius-sm) var(--qc-radius-sm) 0 0;
}

.qc-picker__hull {
  display: block;
  width: 96px;
  height: 96px;
}

.qc-picker__kind {
  padding: 1px 8px;
  font: 700 12px/1.3 var(--qc-font-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--qc-rarity-legendary);
  border: 1px solid color-mix(in oklab, var(--qc-rarity-legendary) 60%, transparent);
  border-radius: 999px;
}

.qc-picker__slot[data-form="true"] > .qc-card {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* Take suggested (touch): under the pre-highlighted card. */
.qc-picker__take {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.qc-picker__enter .qc-kbd {
  margin-right: 4px;
}

/* A phone (docs/evolution-overhaul.md §5.7): one column, full width, so the
   two forms of an evolution offer stack. */
@media (max-width: 599px) {
  .qc-picker__cards {
    grid-template-columns: minmax(min(190px, 100%), 1fr);
  }
}

/* ------------------------------------------------ build: milestone, tags --- */

.qc-picker__milestone {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
  font-size: 13px;
  color: var(--qc-text-dim);
}

.qc-picker__milestone-pips {
  display: inline-flex;
  gap: 5px;
}

.qc-picker__milestone-pip {
  display: block;
  width: 8px;
  height: 8px;
  border: 1px solid var(--qc-xp);
  border-radius: 1.5px;
  transform: rotate(45deg);
  opacity: 0.5;
}

.qc-picker__milestone-pip[data-filled] {
  background: var(--qc-xp);
  opacity: 1;
}

.qc-picker__milestone-form {
  color: var(--qc-rarity-legendary);
}

.qc-picker__held {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.qc-picker__held-tag {
  padding: 3px 9px;
  font: 600 12px/1.2 var(--qc-font-ui);
  color: var(--qc-text);
  background: color-mix(in oklab, var(--qc-accent-2) 14%, transparent);
  border: 1px solid color-mix(in oklab, var(--qc-accent-2) 55%, transparent);
  border-radius: 999px;
}

.qc-picker__held-count {
  font-family: var(--qc-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--qc-accent-2);
}

/* A tag that already resonates (game/Resonance): the gold of the tier it pays. */
.qc-picker__held-tag[data-resonance] {
  border-color: color-mix(in oklab, var(--qc-rarity-legendary) 70%, transparent);
}

.qc-picker__held-resonance {
  margin-left: 4px;
  font-family: var(--qc-font-mono);
  color: var(--qc-rarity-legendary);
}

.qc-picker__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px 24px;
}

.qc-picker__hint {
  margin: 0;
  font-size: 13px;
  color: var(--qc-text-faint);
}

@keyframes qc-picker-fade {
  from { opacity: 0; }
}

@keyframes qc-picker-card {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
}

/* A landscape phone: three full cards, a title and a footer in ~300px of
   height. The chrome gives up its air first; the cards themselves tighten in
   ui/UpgradeCard. Picking an upgrade is on a timer, so nothing here may need
   scrolling to reach. */
@media (max-height: 520px) {
  .qc-picker { padding: 10px 14px; }
  .qc-picker__panel { gap: 10px; }
  .qc-picker__header { gap: 5px; }
  .qc-picker__title { gap: 12px; font-size: clamp(14px, 1.9vw, 18px); letter-spacing: 0.26em; }
  .qc-picker__title::before,
  .qc-picker__title::after { width: 40px; }
  .qc-picker__meta { font-size: 12px; }
  .qc-picker__cards { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 10px; }
  .qc-picker__slot > .qc-card { min-height: 0; }
  .qc-picker__footer { gap: 8px 16px; }
  .qc-picker__hint { font-size: 12px; }
  .qc-picker__milestone { font-size: 12px; gap: 4px 8px; }
  .qc-picker__held-tag { padding: 2px 7px; font-size: 12px; }
  .qc-picker__suggested { margin-bottom: 3px; padding: 2px 7px; font-size: 12px; }
  .qc-picker__stage { padding: 6px 10px; }
  .qc-picker__hull { width: 56px; height: 56px; }
}

/* ------------------------------------------------------------- touch --- */

/* A phone. The whole offer — every card and the way out — fits one screen
   in either orientation with nothing to scroll: the arena keeps running under
   this screen, and a thumb scrolling a list is a ship standing still.
   The edges are the device's safe area, and the header keeps the top-right
   corner clear for the settings gear (44px at 14px from the corner): the
   heading is left-aligned and the header stops 64px short of the right edge. */
.qc-picker[data-touch="true"] {
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
}

.qc-picker[data-touch="true"] .qc-picker__panel {
  align-items: stretch;
  gap: 12px;
}

.qc-picker[data-touch="true"] .qc-picker__header {
  align-items: flex-start;
  gap: 5px;
  padding-right: 60px;
  text-align: left;
}

.qc-picker[data-touch="true"] .qc-picker__title {
  font-size: 16px;
  letter-spacing: 0.14em;
  line-height: 1.2;
}

.qc-picker[data-touch="true"] .qc-picker__title::before,
.qc-picker[data-touch="true"] .qc-picker__title::after {
  display: none;
}

.qc-picker[data-touch="true"] .qc-picker__meta,
.qc-picker[data-touch="true"] .qc-picker__milestone {
  font-size: 12px;
}

.qc-picker[data-touch="true"] .qc-picker__milestone,
.qc-picker[data-touch="true"] .qc-picker__held {
  justify-content: flex-start;
}

.qc-picker[data-touch="true"] .qc-picker__held-tag {
  padding: 2px 7px;
  font-size: 12px;
}

.qc-picker[data-touch="true"] .qc-picker__cards {
  gap: 10px;
}

.qc-picker[data-touch="true"] .qc-picker__slot > .qc-card {
  min-height: 0;
}

/* The suggestion rides on the card's top edge instead of a line of its own,
   so a suggested card is no taller than the others and the row keeps its
   height budget. */
.qc-picker[data-touch="true"] .qc-picker__slot {
  position: relative;
}

.qc-picker[data-touch="true"] .qc-picker__suggested {
  position: absolute;
  top: -8px;
  left: 10px;
  z-index: 1;
  margin: 0;
  padding: 2px 7px;
  font-size: 12px;
  background: var(--qc-space-1);
}

.qc-picker[data-touch="true"] .qc-picker__footer {
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 12px;
}

.qc-picker[data-touch="true"] .qc-picker__hint {
  font-size: 12px;
}

/* Take suggested: a thumb's target, on the pre-highlighted card. */
.qc-picker[data-touch="true"] .qc-picker__take {
  min-width: 44px;
  min-height: 44px;
}

.qc-picker[data-touch="true"] .qc-picker__slot[data-suggested="true"] > .qc-card {
  outline: 2px solid var(--qc-accent-2);
  outline-offset: 2px;
}

/* A form card stays a thumb target however little text it holds, and its
   stage is smaller so both forms fit a phone screen stacked. */
.qc-picker[data-touch="true"] .qc-picker__slot[data-form="true"] > .qc-card {
  min-height: 44px;
}

.qc-picker[data-touch="true"] .qc-picker__stage {
  padding: 8px 10px 6px;
}

.qc-picker[data-touch="true"] .qc-picker__hull {
  width: 64px;
  height: 64px;
}

/* The way out is a thumb's target, not a link. */
.qc-picker[data-touch="true"] .qc-picker__close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
}

/* Upright: one card above the next, full width. */
@media (orientation: portrait) {
  .qc-picker[data-touch="true"] .qc-picker__cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* On its side: the cards abreast, however narrow the phone. */
@media (orientation: landscape) and (max-height: 520px) {
  .qc-picker[data-touch="true"] .qc-picker__panel { gap: 8px; }
  /* The header runs across instead of down: the title and the level on one
     line, the tracker and the build beside them as room allows. */
  .qc-picker[data-touch="true"] .qc-picker__header {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 16px;
  }
  .qc-picker[data-touch="true"] .qc-picker__cards {
    grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
    gap: 8px;
  }
}
