/* Gameplay page: the stage modals (js/stage-modal.js, docs 050). No box: the screen darkens, a big
   glowing title, the cards in one row scrolled sideways, a glass strip behind them, small pill
   buttons. Loaded after the other stylesheets (it overrides their .modal-box / #stack-inner). */
:root {
  --stage-card-h: clamp(150px, 32vh, 300px);
  --stage-card-w: calc(var(--stage-card-h) * 5 / 7);
}

/* ── The overlay: dark, the stage centred ───────────────────────────────── */
.modal-overlay.stage, #stack-popup.stage {
  background: transparent;
  padding: 3vh 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
#stack-popup.stage { position: fixed; inset: 0; z-index: 340; align-items: center; justify-content: center; }
#stack-popup.closing, .modal-overlay.closing { pointer-events: none; }
.stage-dim {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, rgba(0,0,0,.52), rgba(0,0,0,.72));
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}

/* ── The box: open, centred, the glass strip behind it ───────────────────── */
.stage > .modal-box, .stage > #stack-inner {
  --stage-accent: #f0883e;
  position: relative; z-index: 1; isolation: isolate;
  margin: auto;
  width: auto; min-width: min(420px, 100%); max-width: min(1180px, 100%);
  max-height: none; overflow: visible;
  padding: 26px 30px 22px;
  background: transparent; border: none; border-radius: 18px; box-shadow: none;
  text-align: center;
}
/* The glass (js/stage-modal.js placeGlass()): behind the title and text, and behind the buttons;
   none behind the cards (they lie open over the dark, as the hand's picks). */
/* (placed in px by placeGlass) */
.stage-glass, .stage-glass-foot {
  position: absolute; left: 0; top: 0; z-index: -1; pointer-events: none;
  border-radius: 18px;
  /* Neutral, half see-through dark (no tint of the pop-up's colour). */
  background: rgba(13, 17, 23, .62);
  border: 2px solid rgba(255, 255, 255, .22);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#kw-modal.degen-mode > .modal-box { --stage-accent: #3fb950; border: none; box-shadow: none; }
#kw-modal.weapon-mode > .modal-box { --stage-accent: #f0883e; border: none; box-shadow: none; }
#surr-modal > .modal-box, #game-surr-modal > .modal-box { --stage-accent: #f85149; }
#stack-popup > #stack-inner { --stage-accent: #58a6ff; }

/* The title: big, glowing in the accent; the count beside it; View Field a small pill. */
.stage .modal-head { position: relative; display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.stage > .modal-box h3, .stage #stack-title {
  font-size: 28px; font-weight: 800; line-height: 1.2; color: #fff; margin: 0 0 6px;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  letter-spacing: .01em;
}
.stage .modal-head h3 { margin: 0; }
.stage .modal-head .pick-count { margin: 0; font-size: 24px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.stage .modal-head .m-peek { margin: 0; border-radius: 999px; padding: 5px 12px; background: rgba(13,17,23,.55); }
/* View Field shown: the text under the head kept clear of it. */
.stage .modal-head:has(.m-peek:not([style*="none"])) { margin-bottom: 14px; }
.stage > .modal-box > p {
  /* Left aligned, the block (as wide as its text, 620 px at most) centred under the title. */
  width: fit-content; text-align: left;
  max-width: 620px; margin: 4px auto 6px; font-size: 15.5px; line-height: 1.5; color: #c9d1d9;
}
.stage .modal-head:has(.pick-count:not(:empty)) + p { margin-top: 4px; }
/* A question with no text (It's Evolving!'s flip): no gap for it. */
#kw-modal-desc:empty { display: none; }

/* ── The cards: one row, sideways ────────────────────────────────────────── */
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row {
  display: flex; flex-wrap: nowrap; gap: 14px;
  overflow-x: auto; overflow-y: hidden;
  /* Room for a card lifted, glowing or torn (Unity), and to scroll past the strip's edge. */
  /* (Room above for a card lifted with its badge, clear of the text's glass.) */
  padding: 36px 6px 16px; margin: 18px -14px 8px;
  scroll-snap-type: x proximity; scroll-padding: 0 24px;
  scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--stage-accent) 55%, #30363d) transparent;
  overscroll-behavior-x: contain;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row:empty { display: none; }
/* Centred while they fit, scrolled from the first when they don't (auto margins, not
   justify-content: centring would cut the first ones off). */
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row > :first-child { margin-left: auto; }
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row > :last-child { margin-right: auto; }
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row::-webkit-scrollbar { height: 8px; }
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--stage-accent) 50%, #30363d); border-radius: 999px; }

.stage .modal-card-item, .stage #stack-cards .sc-card {
  flex: none; width: var(--stage-card-w);
  scroll-snap-align: center;
  border-radius: 10px;
  transition: translate .18s ease-out, box-shadow .18s, border-color .15s;
}
.stage .modal-card-item img, .stage #stack-cards .sc-card img {
  width: 100%; height: auto; aspect-ratio: 5 / 7; object-fit: cover; display: block; border-radius: 8px;
  box-shadow: 0 10px 26px rgba(0,0,0,.55);
}
.stage .modal-card-item:not(.disabled):not(.mci-locked):hover { translate: 0 -6px; }
.stage .modal-card-item.selected { translate: 0 -14px; box-shadow: 0 0 0 2px var(--gold), 0 0 26px rgba(240,192,64,.6); }
/* An order's badge (1st, 2nd… Sähkötalo, Fire) sits over the card's corner: the row (clipped
   top and bottom, as it scrolls sideways) gets the room for it over a lifted card. */
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row:has(.retrig-badge) { padding-top: 40px; }
.stage .modal-card-item:has(> .retrig-badge) { position: relative; }
.stage .modal-card-item > .retrig-badge { z-index: 2; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.stage .modal-card-item .mci-name { font-size: 12.5px; margin-top: 6px; white-space: normal; }
.stage #stack-cards .sc-label { font-size: 13px; margin-top: 6px; }
/* The Weapon question: its small cards (keyword-fx.css) stay small. */
#kw-modal.weapon-mode .stage-row .modal-card-item { width: calc(var(--stage-card-w) * .62); }
#kw-modal.weapon-mode.weapon-pick .stage-row .modal-card-item { width: var(--stage-card-w); }
/* Lingering effects: tiles of text in the row. */
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row > .lingering-effect-item { flex: none; width: min(320px, 78vw); text-align: left; padding: 12px; border: 1px solid #30363d; border-radius: 12px; background: rgba(13,17,23,.6); white-space: normal; }
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row > .lingering-effect-item + .lingering-effect-item { border-top: 1px solid #30363d; }
/* Anything else in a row (an RPS guess, a reel, a note) keeps its own size. */
:is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row > :not(.modal-card-item):not(.sc-card):not(.lingering-effect-item) { flex: none; }

/* ── The buttons: small pills in a row ───────────────────────────────────── */
.stage > .modal-box > .modal-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 4px; }
.stage > .modal-box > .modal-btns button, .stage #stack-close {
  border-radius: 999px; padding: 8px 20px; font-size: 14px; font-weight: 700; min-height: 36px;
  border: 1px solid; cursor: pointer; transition: transform .1s, opacity .15s, background .15s;
}
.stage > .modal-box > .modal-btns button:active, .stage #stack-close:active { transform: translateY(1px); }
.stage #stack-close { margin-top: 6px; background: rgba(13,17,23,.6); color: var(--text); border-color: #30363d; }
.stage #stack-close:hover { background: #21262d; }
.stage > .modal-box .m-cancel { background: rgba(13,17,23,.6); }

/* Cards too many for one row (StageModal.fitRows()): three to a column, the columns side by side,
   scrolled sideways; the cards sized so the three fit the screen's height. */
:is(#stack-popup, #kw-modal).stage .stage-row.stage-grid {
  --grid-card-h: clamp(96px, calc((100vh - 300px) / 3 - 40px), 210px);
  display: grid; grid-template-rows: repeat(3, auto); grid-auto-flow: column;
  grid-auto-columns: calc(var(--grid-card-h) * 5 / 7);
  gap: 24px 14px; justify-content: safe center;
}
:is(#stack-popup, #kw-modal).stage .stage-row.stage-grid > .sc-card, :is(#stack-popup, #kw-modal).stage .stage-row.stage-grid > .modal-card-item { width: auto; margin: 0; }
#stack-popup.stage #stack-cards.stage-grid > .sc-card, #kw-modal.stage #kw-modal-cards.stage-grid > .modal-card-item { width: auto; }
:is(#stack-popup, #kw-modal).stage .stage-row.stage-grid > :first-child { margin-left: 0; }
:is(#stack-popup, #kw-modal).stage .stage-row.stage-grid > :last-child { margin-right: 0; }
:is(#stack-popup, #kw-modal).stage .stage-row.stage-grid .sc-label, :is(#stack-popup, #kw-modal).stage .stage-row.stage-grid .mci-name { font-size: 11.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Phones ──────────────────────────────────────────────────────────────── */
@media (max-width: 760px), (pointer: coarse) and (max-height: 500px) {
  :root { --stage-card-h: clamp(150px, 30vh, 250px); }
  .modal-overlay.stage, #stack-popup.stage { align-items: center; padding: 10px 8px; }
  .stage > .modal-box, .stage > #stack-inner { min-width: 0; width: 100%; padding: 18px 14px 14px; max-height: none; }
  .stage > .modal-box h3, .stage #stack-title { font-size: 22px; }
  .stage > .modal-box > p { font-size: 14.5px; }
  :is(#stack-popup, #kw-modal, #tut-pop, #surr-modal, #game-surr-modal).stage .stage-row { gap: 10px; margin: 16px -10px 6px; padding: 32px 4px 12px; }
  .stage .modal-card-item, .stage #stack-cards .sc-card { width: var(--stage-card-w); }
  .stage .modal-card-item img, .stage #stack-cards .sc-card img { width: 100%; height: auto; }
  .stage > .modal-box > .modal-btns button { flex: 0 1 auto; min-height: 42px; }
  .stage #stack-close { width: auto; min-height: 42px; }
}
@media (pointer: coarse) and (max-height: 500px) {
  :root { --stage-card-h: clamp(120px, 40vh, 200px); }
}
/* Flush (Infernoid): a section per graveyard, side by side in the row, each its cards in a line. */
:is(#kw-modal).stage .stage-row > .grave-section { flex: none; display: flex; flex-direction: column; text-align: left; }
:is(#kw-modal).stage .stage-row > .grave-section + .grave-section { margin-top: 0; border-top: none; padding-top: 0; padding-left: 16px; border-left: 1px solid #30363d; }
:is(#kw-modal).stage .stage-row .grave-section-cards { flex-wrap: nowrap; gap: 12px; }
