/*
 * Title, pause, win and lose. Like the briefing, it sits over the whole page rather than
 * inside the stage: the stage is only as tall as the canvas (a 960x640 ratio, so ~693px
 * at full width) and only as wide as the level's map, and it is `overflow: hidden` — so
 * an absolutely positioned panel in there gets its bottom row sliced off rather than
 * scrolled. Six levels and a key list do not fit that box.
 */
.menu {
  position: fixed;
  inset: 0;
  /* Below `.briefing`'s 10: the title menu stays up underneath while the briefing reads. */
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 5, 14, 0.82);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.menu--hidden {
  display: none;
}

.menu__panel {
  /* 680 rather than 580 so the six-level picker is three columns wide and two rows tall;
     at 580 it wrapped to three rows and pushed the panel past the window. */
  width: min(680px, 100%);
  max-height: min(88vh, 860px);
  display: flex;
  flex-direction: column;
  padding: 30px 32px 26px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow:
    0 30px 70px -30px rgba(0, 0, 0, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  text-align: left;
}

.menu__title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

.menu[data-screen="won"] .menu__title { color: var(--good); }
.menu[data-screen="lost"] .menu__title { color: var(--bad); }

/*
 * The one part of the panel that varies: everything the screen has to say. It scrolls so
 * that a short window shortens the reading rather than clipping it, while the title above
 * and the buttons below stay put — an unreachable "Empezar" is a dead game. Scrollbar
 * treatment copied from `.briefing__grid`, which scrolls for the same reason.
 */
.menu__body {
  flex: 1 1 auto;
  /* Load-bearing: a flex item's default `min-height: auto` refuses to shrink below its
     content, so without this the panel grows and the cap above never engages. */
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.menu__body::-webkit-scrollbar {
  width: 10px;
}

.menu__body::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
  background-color: rgba(255, 255, 255, 0.28);
}

.menu__line {
  margin: 0 0 12px;
  font-size: 19.5px;
  line-height: 1.6;
  color: #ded7f2;
}

.menu__line--quiet {
  color: var(--ink-quiet);
  font-size: 17.5px;
}

.menu__line strong {
  color: var(--accent);
}

.menu__keys {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 18.5px;
  color: #ded7f2;
}

.menu__key {
  display: inline-block;
  min-width: 108px;
  margin-right: 10px;
  padding: 3px 10px;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  color: var(--backdrop-deep);
  background: var(--accent);
}

.menu__score {
  list-style: none;
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.menu__score-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0;
  font-size: 17.5px;
  color: #ded7f2;
}

.menu__score-row span:last-child {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--good);
}

.menu__score-row--total {
  margin-top: 6px;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 19px;
  font-weight: 600;
}

.menu__score-row--total span:last-child {
  font-size: 25px;
  color: var(--accent);
}

.menu__buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.menu__secondary {
  padding: 13px 24px;
  border: 0;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  cursor: pointer;
  transition: background 120ms ease;
}

.menu__secondary:hover {
  background: rgba(255, 255, 255, 0.17);
}

.menu__secondary:focus-visible {
  outline: 3px solid var(--good);
  outline-offset: 3px;
}

/*
 * The ghost button means different things per screen — the catalogue on the title, a way
 * back to the ladder on the end screens — so it is shown on all of them. It used to be
 * hidden everywhere but the title, which with six levels would strand the player on the
 * win screen.
 */

.menu__action {
  margin-top: 4px;
  padding: 15px 32px;
  border: 0;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  color: var(--backdrop-deep);
  background: var(--accent);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.menu__action:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.menu__action:focus-visible {
  outline: 3px solid var(--good);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .menu__action { transition: none; }
}

/*
 * The ladder. Locked rungs are drawn rather than hidden: seeing that there are six
 * houses and that you are on the first is the point of showing it at all.
 */
.menu__levels {
  list-style: none;
  margin: 8px 0 16px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 6px;
}

.menu__level {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 17px;
  text-align: left;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 120ms ease;
}

.menu__level:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.menu__level:focus-visible {
  outline: 3px solid var(--good);
  outline-offset: 2px;
}

.menu__level:disabled {
  color: var(--ink-quiet);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  cursor: not-allowed;
}

.menu__level-number {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--backdrop-deep);
  background: var(--accent);
}

.menu__level:disabled .menu__level-number {
  color: var(--ink-quiet);
  background: rgba(255, 255, 255, 0.1);
}

.menu__level--done .menu__level-number {
  background: var(--good);
}

.menu__level-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .menu__level { transition: none; }
}
