/* ui/ModeSelect — the build-mode chooser.
   Contract: ./ModeSelect.spec.md
   Basic is cyan, square and drafted on a blueprint grid; Roguelike is magenta,
   bevelled and dealt like cards. Shape and marker differ as well as hue, so
   the modes never rely on colour alone.                                     */

.qc-modes {
  container: qc-modes / inline-size;
  display: grid;
  /* minmax(0, 1fr), never a bare auto or 1fr: those grow to their content and a
     long translated word (SÉLECTIONNÉ, Entraînement) pushed the cards past the panel. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  color: var(--qc-text);
}

.qc-modes__title {
  margin: 0;
}

.qc-modes__cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

/* ---- the card, shared -------------------------------------------------- */

.qc-mode {
  --mode-bg: color-mix(in srgb, var(--mode-primary) 7%, var(--qc-space-1));
  --mode-edge: color-mix(in srgb, var(--mode-primary) 38%, var(--qc-line));
  --mode-edge-width: 1px;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 44px;
  padding: 18px 20px;
  font: inherit;
  text-align: left;
  color: var(--qc-text);
  background: var(--mode-bg);
  border: 0;
  cursor: pointer;
  transition:
    opacity var(--mode-dur) var(--mode-ease),
    box-shadow var(--mode-dur) var(--mode-ease),
    background var(--mode-dur) var(--mode-ease);
}

/* The other card dims while one is hovered. */
.qc-modes__cards:hover .qc-mode:not(:hover) {
  opacity: 0.7;
}

.qc-mode[data-selected="true"] {
  --mode-edge: var(--mode-primary);
  --mode-edge-width: 2px;
  --mode-bg: color-mix(in srgb, var(--mode-primary) 14%, var(--qc-space-1));
}

.qc-mode[data-available="false"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.qc-modes__cards:hover .qc-mode[data-available="false"]:not(:hover) {
  opacity: 0.45;
}

.qc-mode__head {
  display: flex;
  flex-wrap: wrap; /* the Selected chip drops under a long name rather than past the card */
  align-items: center;
  gap: 8px 12px;
}

.qc-mode__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mode-primary);
}

.qc-mode__chip {
  flex: 0 0 auto;
  padding: 3px 8px;
  font: 600 12px/1.2 var(--qc-font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--qc-space-0);
  background: var(--mode-primary);
}

.qc-mode__tagline {
  display: block;
  line-height: 1.45;
  color: var(--qc-text-dim);
}

.qc-mode__bullets {
  display: grid;
  gap: 4px;
}

.qc-mode__bullet {
  display: block;
  padding-left: 1.4em;
  text-indent: -1.4em;
  font-size: 0.92rem;
  color: var(--qc-text);
}

.qc-mode__bullet::before {
  display: inline-block;
  width: 1.4em;
  text-indent: 0;
  color: var(--mode-primary);
}

.qc-mode__note {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--qc-text-faint);
}

/* ---- evolution preview -------------------------------------------------- */

.qc-mode__evolution {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--qc-line);
}

.qc-mode__forms {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

/* The parent sets the canvas's pixel size; this is its box. */
.qc-mode__preview {
  display: block;
  width: 56px;
  height: 56px;
}

.qc-mode__preview[data-slot="current"] {
  opacity: 0.7;
}

.qc-mode__arrow {
  color: var(--qc-text-faint);
}

.qc-mode__next,
.qc-mode__complete {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.qc-mode__next-level {
  font: 600 12px/1.2 var(--qc-font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mode-primary);
}

.qc-mode__next-name {
  font-weight: 600;
}

.qc-mode__next-role {
  font-size: 0.85rem;
  color: var(--qc-text-dim);
}

.qc-mode__complete {
  font-size: 0.9rem;
  color: var(--qc-text-dim);
}

/* ---- icons: pure CSS, decorative ---------------------------------------- */

.qc-mode__icon {
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
}

.qc-mode__glyph {
  position: absolute;
  bottom: 2px;
  background: var(--mode-primary);
  transition: transform var(--mode-dur) var(--mode-ease), height var(--mode-dur) var(--mode-ease);
}

/* ---- Basic: cyan, square, blueprint grid, snappy ------------------------ */

.qc-mode--basic {
  --mode-primary: var(--qc-accent-2);
  --mode-secondary: color-mix(in srgb, var(--qc-accent-2) 22%, var(--qc-space-0));
  --mode-dur: var(--qc-dur-fast);
  --mode-ease: linear;
  border-radius: 0;
  box-shadow: inset 0 0 0 var(--mode-edge-width) var(--mode-edge);
  background:
    linear-gradient(color-mix(in srgb, var(--mode-primary) 7%, transparent) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, color-mix(in srgb, var(--mode-primary) 7%, transparent) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--mode-bg);
}

.qc-mode--basic:hover,
.qc-mode--basic:focus-visible {
  background:
    linear-gradient(color-mix(in srgb, var(--mode-primary) 14%, transparent) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, color-mix(in srgb, var(--mode-primary) 14%, transparent) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--mode-bg);
}

.qc-mode--basic .qc-mode__chip {
  border-radius: 0;
}

.qc-mode--basic .qc-mode__bullet::before {
  content: "▪";
}

/* Rising bar stack. */
.qc-mode--basic .qc-mode__glyph {
  width: 6px;
}

.qc-mode--basic .qc-mode__glyph:nth-child(1) { left: 2px; height: 10px; }
.qc-mode--basic .qc-mode__glyph:nth-child(2) { left: 11px; height: 16px; }
.qc-mode--basic .qc-mode__glyph:nth-child(3) { left: 20px; height: 22px; }

.qc-mode--basic:hover .qc-mode__glyph,
.qc-mode--basic:focus-visible .qc-mode__glyph {
  transform: translateY(-2px);
}

/* ---- Roguelike: magenta, bevelled, dealt cards -------------------------- */

.qc-mode--roguelike {
  --mode-primary: var(--qc-paint-magenta);
  --mode-secondary: var(--qc-rarity-epic);
  --mode-dur: var(--qc-dur);
  --mode-ease: cubic-bezier(0.34, 1.4, 0.64, 1);
  --bevel: 16px;
  /* The card is painted in its edge colour and clipped; ::before lays the face
     over it, inset by the edge width, so the bevels keep a visible border. */
  background: var(--mode-edge);
  clip-path: polygon(
    var(--bevel) 0, calc(100% - var(--bevel)) 0, 100% var(--bevel),
    100% calc(100% - var(--bevel)), calc(100% - var(--bevel)) 100%,
    var(--bevel) 100%, 0 calc(100% - var(--bevel)), 0 var(--bevel)
  );
}

.qc-mode--roguelike::before {
  content: "";
  position: absolute;
  inset: var(--mode-edge-width);
  z-index: -1;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mode-primary) 12%, transparent), transparent 45%,
      color-mix(in srgb, var(--mode-secondary) 10%, transparent)),
    var(--mode-bg);
  clip-path: polygon(
    calc(var(--bevel) - 0.6px) 0, calc(100% - var(--bevel) + 0.6px) 0, 100% calc(var(--bevel) - 0.6px),
    100% calc(100% - var(--bevel) + 0.6px), calc(100% - var(--bevel) + 0.6px) 100%,
    calc(var(--bevel) - 0.6px) 100%, 0 calc(100% - var(--bevel) + 0.6px), 0 calc(var(--bevel) - 0.6px)
  );
}

/* Clipping hides the Theme focus outline, so draw it inside. */
.qc-mode--roguelike:focus-visible {
  outline: none;
}

.qc-mode--roguelike:focus-visible::before {
  box-shadow: inset 0 0 0 2px var(--qc-accent-2);
}

.qc-mode--roguelike .qc-mode__chip {
  clip-path: polygon(5px 0, 100% 0, calc(100% - 5px) 100%, 0 100%);
  padding-inline: 10px;
}

.qc-mode--roguelike .qc-mode__bullet::before {
  content: "◆";
  color: var(--mode-secondary);
}

/* Fanned cards. */
.qc-mode--roguelike .qc-mode__glyph {
  left: 9px;
  width: 11px;
  height: 17px;
  border: 1px solid var(--qc-space-1);
  border-radius: 2px;
  transform-origin: 50% 100%;
}

.qc-mode--roguelike .qc-mode__glyph:nth-child(1) { transform: rotate(-18deg); background: var(--mode-secondary); }
.qc-mode--roguelike .qc-mode__glyph:nth-child(2) { transform: rotate(0deg); }
.qc-mode--roguelike .qc-mode__glyph:nth-child(3) { transform: rotate(18deg); background: var(--mode-secondary); }

.qc-mode--roguelike:hover .qc-mode__glyph:nth-child(1),
.qc-mode--roguelike:focus-visible .qc-mode__glyph:nth-child(1) { transform: rotate(-24deg); }
.qc-mode--roguelike:hover .qc-mode__glyph:nth-child(3),
.qc-mode--roguelike:focus-visible .qc-mode__glyph:nth-child(3) { transform: rotate(24deg); }

/* ---- start here --------------------------------------------------------- */

.qc-modes__start {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 20px;
  font-weight: 600;
  color: var(--qc-rarity-legendary);
  background: color-mix(in srgb, var(--qc-rarity-legendary) 10%, var(--qc-space-1));
  border: 1px solid color-mix(in srgb, var(--qc-rarity-legendary) 55%, var(--qc-line));
  border-radius: 999px;
}

.qc-modes__start:hover {
  background: color-mix(in srgb, var(--qc-rarity-legendary) 18%, var(--qc-space-1));
}

.qc-modes__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--qc-rarity-legendary);
  animation: qc-modes-breathe 1.6s ease-in-out infinite;
}

@keyframes qc-modes-breathe {
  0%, 100% { opacity: 0.45; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ---- narrow: stacked, compact previews ---------------------------------- */

@container qc-modes (max-width: 640px) {
  .qc-modes__cards {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .qc-mode {
    padding: 14px 16px;
  }

  .qc-mode__next,
  .qc-mode__complete {
    display: none;
  }

  .qc-mode__preview {
    width: 44px;
    height: 44px;
  }
}

/* ---- short: a landscape phone ----------------------------------------- */

/* 360-390px of height holds both cards only side by side and only as name
   plus tagline, so the choice is whole above ui/PlayModal's pinned buttons.
   This comes after the narrow rule on purpose: a landscape phone's panel can
   be under 640px wide and must still not stack. */
@media (max-height: 520px) {
  .qc-modes {
    gap: 6px;
  }

  .qc-modes__cards {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
  }

  .qc-mode {
    gap: 4px;
    padding: 8px 14px 10px;
  }

  .qc-mode__icon {
    width: 22px;
    height: 22px;
  }

  .qc-mode__name {
    font-size: 1rem;
  }

  .qc-mode__tagline {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .qc-mode__bullets,
  .qc-mode__evolution {
    display: none;
  }
}

/* ---- reduced motion: nothing loops -------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .qc-modes__dot {
    animation: none;
    opacity: 1;
  }

  .qc-mode,
  .qc-mode__glyph {
    transition: none;
  }
}
