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

/* A layer, not a section: closed, it costs the menu no height at all, which is
   what keeps Enter Arena above the fold. It never takes a click — only the
   panel does — so the menu underneath stays operable while it is open. */
.sp-howto {
  position: fixed;
  inset: 0;
  /* Over the menu, the settings gear and the account row: it is the thing the
     player just asked for, and nothing else is theirs to reach meanwhile. */
  z-index: 42;
  pointer-events: none;
}

/* Decoration, not a scrim: it dims the menu without swallowing clicks, so this
   dialog is honestly aria-modal="false". */
.sp-howto[data-open]::before {
  content: "";
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, var(--sp-space-0) 58%, transparent);
  animation: sp-howto-dim var(--sp-dur) var(--sp-ease-out) both;
}

.sp-howto__panel {
  position: fixed;
  top: 50%;
  left: 50%;
  display: grid;
  /* Head, tabs, body: only the body flexes and scrolls. With one flexible row
     for three children the tab bar took it and a landscape phone crushed it
     to 8px. */
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  width: min(860px, calc(100vw - 32px));
  /* Bounded by the viewport, with the body scrolling inside it: at 520 × 800,
     on a landscape phone, or with a large system font, every line is still
     reachable and the title and close button never leave. */
  max-height: calc(100dvh - 40px);
  padding: 16px 18px 18px;
  color: var(--sp-text);
  background: var(--sp-glass);
  border: 1px solid var(--sp-line-strong);
  border-radius: var(--sp-radius);
  box-shadow: 0 30px 90px -34px var(--sp-space-0);
  backdrop-filter: blur(14px);
  pointer-events: auto;
  transform: translate(-50%, -50%);
  animation: sp-howto-in var(--sp-dur) var(--sp-ease-out) both;
}

.sp-howto__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--sp-line);
}

.sp-howto__title {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.26em;
  text-indent: 0.26em; /* balances the trailing letter-spacing */
  text-transform: uppercase;
  color: var(--sp-text);
}

/* A thumb target, and the only way out: no key is bound by this block. */
.sp-howto__close {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  font-size: 15px;
  color: var(--sp-text-dim);
  border: 1px solid transparent;
  border-radius: 50%;
  transition: color var(--sp-dur-fast), border-color var(--sp-dur-fast);
}

.sp-howto__close:hover {
  color: var(--sp-text);
  border-color: var(--sp-line-strong);
}

/* The four pages. A row of pills under the title; it scrolls sideways
   rather than wrap on a narrow phone, so the body never jumps down a line. */
.sp-howto__tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  padding: 4px;
  overflow-x: auto;
  border: 1px solid var(--sp-line);
  border-radius: 999px;
  scrollbar-width: none;
}

.sp-howto__tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--sp-text-dim);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.sp-howto__tab:hover { color: var(--sp-text); }

/* A thumb gets a full 44px tab; a mouse keeps the slimmer pill. */
@media (pointer: coarse) {
  .sp-howto__tab { min-height: 44px; }
}

/* A phone cannot fit four pills on a line: two rows of two, every tab in view. */
@media (max-width: 560px) {
  .sp-howto__tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-radius: 20px;
  }
  .sp-howto__tab {
    padding: 0 8px;
    font-size: 0.75rem;
  }
}

.sp-howto__tab[aria-selected="true"] {
  color: var(--sp-text);
  background: color-mix(in oklab, var(--sp-accent) 26%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--sp-accent) 55%, transparent);
}

.sp-howto__tab:focus-visible {
  outline: 2px solid var(--sp-accent-2);
  outline-offset: 2px;
}

.sp-howto__line .sp-kbd {
  margin: 0 2px;
}

.sp-howto__body {
  display: grid;
  gap: 18px 30px;
  align-content: start;
  overflow-y: auto;
  padding-right: 4px; /* room for the scrollbar, so text never sits under it */
}

/* Two columns once the panel is wide enough for the controls to stand on their
   own: the keys a player needs first, the reasons to care beside them. */
@media (min-width: 780px) {
  .sp-howto__body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  .sp-howto__section--controls {
    grid-row: 1 / span 2;
  }
}

.sp-howto__section {
  display: grid;
  gap: 7px;
  align-content: start;
}

.sp-howto__heading {
  margin: 0;
  color: var(--sp-accent-2);
}

.sp-howto__line {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--sp-text-dim);
}

/* Rows, not paragraphs: glyphs in one column, two or three words in the next,
   so the labels line up and the eye runs straight down them. */
.sp-howto__control {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  gap: 4px 14px;
  padding: 5px 0;
}

.sp-howto__control + .sp-howto__control {
  border-top: 1px solid var(--sp-line);
}

.sp-howto__keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.sp-howto__or {
  font-size: 12px;
  color: var(--sp-text-faint);
}

.sp-howto__control-label {
  font-size: 13px;
  line-height: 1.35;
  color: var(--sp-text);
}

/* Narrow: the keys sit over their words rather than squeezing both onto one
   row, and the panel takes the width it is given. */
@media (max-width: 480px) {
  .sp-howto__panel {
    padding: 14px 14px 16px;
  }

  .sp-howto__control {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  .sp-howto__control-label {
    font-size: 12px;
  }
}

/* A landscape phone has almost no height: the panel takes what there is and
   scrolls, and the type steps down so more than two lines fit. */
@media (max-height: 520px) {
  .sp-howto__panel {
    max-height: calc(100dvh - 16px);
    padding: 12px 14px 14px;
    gap: 8px;
  }

  .sp-howto__head {
    padding-bottom: 6px;
  }

  .sp-howto__title {
    font-size: 13px;
  }

  .sp-howto__tabs {
    margin: 0;
  }

  .sp-howto__body {
    gap: 10px 22px;
  }

  .sp-howto__section {
    gap: 4px;
  }

  .sp-howto__control {
    padding: 3px 0;
  }

  .sp-howto__line,
  .sp-howto__control-label {
    font-size: 12px;
    line-height: 1.4;
  }
}

@keyframes sp-howto-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 10px)); }
}

@keyframes sp-howto-dim {
  from { opacity: 0; }
}

/* The tank weight classes side by side: two columns where there is room, one on a phone. */
.sp-howto__classes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin-top: 4px;
}

.sp-howto__class {
  display: grid;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid var(--sp-line);
  border-radius: 6px;
}

.sp-howto__class p { margin: 0; }

.sp-howto__class-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sp-howto__class-name {
  font-family: var(--sp-font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sp-text);
}

.sp-howto__class-blocks { display: inline-flex; gap: 2px; }
.sp-howto__class-blocks i { width: 10px; height: 7px; border-radius: 1px; border: 1px solid var(--sp-line-strong); }
.sp-howto__class-blocks i[data-on="true"] { border-color: var(--sp-accent); background: var(--sp-accent); }

.sp-howto__class-stats {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--sp-accent-2);
}

.sp-howto__class-note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--sp-text-dim);
}
