/* =========================================================================
   legion.css - the Meet the Legion page only (loaded after theme.css).

   Three parts:
     1. The Hellboard Hot 10 (the live top 10 of the vote)
     2. The grid of demon cards, with the rank chips and the search box
     3. The flip: a tapped card lifts to the middle of the screen and turns
        over (CSS 3D). People whose phone asks for less motion get a simple
        fade instead.
   Colours come from the variables in theme.css (--gold, --red, ...).
   ========================================================================= */

/* The "hidden" attribute always wins on this page (some boxes below set their
   own display, which would otherwise un-hide them). */
.page-legion [hidden] { display: none !important; }

/* Keeps a space for the scrollbar, so the page does not jump sideways when the
   pop-up card locks the scrolling. */
html { scrollbar-gutter: stable; }
html.legion-locked,
html.legion-locked body { overflow: hidden; }

/* ======================= 1. Hellboard Hot 10 ============================== */

.hellboard { margin-bottom: 40px; }

.hellboard-panel {
  position: relative;
  padding: 20px 18px 22px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 0%, rgba(179, 38, 47, 0.35), transparent 70%),
    var(--panel);
  box-shadow: var(--shadow), var(--glow);
}

.hellboard-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}
.hellboard-title { margin: 0; font-size: clamp(1.7rem, 6vw, 2.4rem); }
.hellboard-total { margin: 0; color: var(--gold); font-weight: 700; }
.hellboard-how { margin: 6px 0 14px; color: var(--muted); font-size: 0.95rem; }
.hellboard-mine { margin: 0 0 14px; color: var(--cream); }
.hellboard-mine button {
  /* Looks like a link, but is a thumb-sized (44px tall) tap target. */
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font: inherit;
  color: var(--gold);
  background: none;
  border: 0;
  padding: 0 4px;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.hellboard-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
/* Wide screens: two columns, 1-5 down the left and 6-10 down the right. */
@media (min-width: 760px) {
  .hellboard-list {
    grid-auto-flow: column;
    grid-template-rows: repeat(5, auto);
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
  }
}

.hb-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 6px 14px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--cream);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.hb-btn:hover { border-color: var(--line-strong); background: #2d1c20; }

.hb-place {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--gold);
}
/* The top three get medals: gold, cream, red. */
.hb-row:nth-child(1) .hb-place { background: var(--gold); color: var(--bg); border-color: var(--gold); box-shadow: 0 0 16px rgba(230, 184, 79, 0.55); }
.hb-row:nth-child(2) .hb-place { background: var(--cream); color: var(--bg); border-color: var(--cream); }
.hb-row:nth-child(3) .hb-place { background: var(--red-hi); color: var(--cream); border-color: var(--red-hi); }
.hb-row:nth-child(1) .hb-btn { border-color: var(--line-strong); }

.hb-thumb {
  flex: none;
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.hb-who {
  flex: 1 1 auto;
  min-width: 0; /* lets long names wrap instead of pushing the count off-screen */
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.hb-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--gold);
  overflow-wrap: anywhere;
}
.hb-rank { font-size: 0.8rem; color: var(--muted); }
.hb-votes { flex: none; font-weight: 700; font-size: 0.95rem; white-space: nowrap; }

.hellboard-empty {
  margin: 4px 0 0;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--gold);
}

/* ======================= 2. The grid of cards ============================= */

.legion-title { text-align: center; margin-bottom: 16px; }
.legion-title:focus { outline: none; } /* it only gets focus as a landing spot */

.legion-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}
.legion-search {
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-pill);
  padding-inline: 20px;
}
.rank-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.chip-count {
  font-size: 0.78rem;
  opacity: 0.75;
}
.legion-count { margin: 0; color: var(--muted); font-size: 0.9rem; min-height: 1.6em; }

.legion-grid {
  display: grid;
  /* Two cards side by side on a 360px phone, more as the screen widens. */
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (min-width: 720px) {
  .legion-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
}

.demon-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 12px 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* The chibi sits in a soft red glow on the dark panel - cheap to draw, so
     125 cards still scroll smoothly on a phone. */
  background:
    radial-gradient(circle at 50% 40%, rgba(179, 38, 47, 0.38), transparent 62%),
    var(--panel);
  color: var(--cream);
  font: inherit;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .demon-card:hover {
    transform: translateY(-4px) rotate(-1deg);
    border-color: var(--line-strong);
    box-shadow: var(--shadow), var(--glow);
  }
}
.demon-card:active { transform: scale(0.98); }
/* While a card is lifted into the pop-up, its spot in the grid is empty. */
.is-lifted { visibility: hidden; }

/* Every picture gets the same square, whatever its shape, so the names line up. */
.demon-art {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden; /* stops a tall picture stretching the square */
}
.demon-art img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.demon-name {
  display: block;
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.1;
  color: var(--gold);
  overflow-wrap: anywhere;
}
.demon-rank {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: rgba(142, 27, 34, 0.35);
  color: var(--cream);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legion-loading {
  margin: 24px auto;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold);
}
.legion-loading .btn { margin-top: 12px; }

/* ======================= 3. The flip ====================================== */

.flip-overlay {
  /* The card's size: as big as the screen allows, with a 16px edge,
     and no wider than a comfortable reading width. */
  --card-w: min(calc(100vw - 32px), 540px);
  --card-h: min(calc(100vh - 32px), 820px);
  --flip-time: 0.6s;
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Phones: 100dvh is the screen height that is really visible (without the
   browser's own address bar), so the buttons at the bottom are never hidden. */
@supports (height: 100dvh) {
  .flip-overlay { --card-h: min(calc(100dvh - 32px), 820px); }
}

.flip-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 6, 0.84);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.flip-overlay.is-shown .flip-backdrop { opacity: 1; }

.flip-lift {
  position: relative;
  flex: none;
  width: var(--card-w);
  height: var(--card-h);
  perspective: 2000px; /* how "deep" the flip looks */
  transform-origin: 50% 50%;
  transition: transform var(--flip-time) cubic-bezier(0.2, 0.75, 0.25, 1), opacity 0.3s ease;
}

.flip-card {
  position: relative;
  width: 100%;
  height: 100%;
  /* Both faces live in one 3D space, so turning the card shows the back. The
     -webkit- copies are for iPhone Safari. */
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform var(--flip-time) cubic-bezier(0.2, 0.75, 0.25, 1);
}
.flip-card.is-flipped { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  /* Hide each face while it is turned away (the -webkit- copy is for iPhones). */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Front: the same look as the card in the grid, only bigger. */
.flip-front {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 28px;
  border: 2px solid var(--line-strong);
  background:
    radial-gradient(circle at 50% 40%, rgba(179, 38, 47, 0.45), transparent 62%),
    var(--panel);
  text-align: center;
  transform: rotateY(0deg); /* iPhone Safari needs a 3D transform here to hide the face */
}
.flip-front-img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  object-fit: contain;
}
.flip-front-name {
  margin-top: 12px;
  font-family: var(--font-display);
  font-size: 2rem;
  line-height: 1.1;
  color: var(--gold);
}

/* Back: everything about the demon. The middle part scrolls; the buttons stay put. */
.flip-back {
  display: flex;
  flex-direction: column;
  /* No "overflow: hidden" here on purpose: older iPhone Safari can forget to
     hide a face that clips its contents. The bar below rounds its own corners. */
  border: 2px solid var(--line-strong);
  background: linear-gradient(180deg, var(--panel-2), var(--panel) 45%);
  box-shadow: 0 0 44px rgba(179, 38, 47, 0.5);
  transform: rotateY(180deg);
}

/* Once the flip has finished, the card is laid flat (no 3D at all). Same picture
   on screen, but phones scroll the long text and press the buttons reliably,
   and the text is pin-sharp. app.js adds and removes this. */
.flip-overlay.is-settled .flip-lift { perspective: none; }
.flip-overlay.is-settled .flip-card {
  -webkit-transform-style: flat;
  transform-style: flat;
  transform: none;
  transition: none;
}
.flip-overlay.is-settled .flip-front { display: none; }
.flip-overlay.is-settled .flip-back {
  -webkit-backface-visibility: visible;
  backface-visibility: visible;
  transform: none;
}

/* Used by app.js to jump to a starting position without animating. */
.flip-overlay.no-anim,
.flip-overlay.no-anim * { transition: none !important; }

/* Less motion: no lift and no flip - the back just fades in. (theme.css turns
   transitions off for these visitors, so the !important puts the fade back.) */
.flip-overlay.is-fade {
  opacity: 0;
  transition: opacity 0.25s ease !important;
}
.flip-overlay.is-fade.is-shown { opacity: 1; }
.flip-overlay.is-fade .flip-backdrop { opacity: 1; }

.back-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain; /* scrolling the card never scrolls the page behind */
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px 8px;
  font-size: 0.98rem;
  line-height: 1.6;
}
/* Keyboard users can Tab onto the text box to scroll it: show the gold ring
   INSIDE its edge (outside, it would be cut off by the card's own border). */
.back-scroll:focus-visible {
  outline-offset: -3px;
  border-radius: 20px 20px 0 0;
}

.back-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.back-art {
  flex: none;
  width: 96px;
  height: 96px;
  object-fit: contain;
  filter: drop-shadow(0 0 14px rgba(179, 38, 47, 0.6));
}
.back-name {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  overflow-wrap: anywhere;
}
.back-name:focus { outline: none; } /* focus lands here so screen readers start at the name */
.back-badge { margin: 4px 0 0; }

.back-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(12, 9, 10, 0.45);
}
.back-facts dt {
  font-family: var(--font-display);
  color: var(--gold);
}
.back-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .back-facts { grid-template-columns: 1fr; gap: 0; }
  .back-facts dd + dt { margin-top: 8px; }
}

.back-section { margin-bottom: 18px; }
.back-section h3 { margin-bottom: 0.3em; font-size: 1.2rem; }
.back-section p { margin: 0; }

.back-quote {
  margin: 0 0 18px;
  padding: 14px 16px 14px 18px;
  border-left: 4px solid var(--red-hi);
  border-radius: 0 14px 14px 0;
  background: rgba(142, 27, 34, 0.18);
  font-style: italic;
  font-size: 1.02rem;
  color: var(--cream);
}
.back-quote blockquote,
.back-quote p { margin: 0; }

.back-sources ol {
  margin: 0;
  padding-left: 1.3em;
  font-size: 0.9rem;
}
.back-sources li { margin-bottom: 8px; overflow-wrap: anywhere; }
.back-sources li::marker { color: var(--gold); }
.source-more { color: var(--muted); }

.back-actions {
  flex: none;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-strong);
  border-radius: 0 0 20px 20px; /* the card's 22px corner, inside its 2px edge */
  background: var(--panel);
}
.vote-note { margin: 0 0 2px; font-size: 0.88rem; color: var(--muted); text-align: center; }
.vote-msg { margin: 0 0 6px; font-size: 0.9rem; color: var(--gold); text-align: center; min-height: 0; }
.vote-msg:empty { display: none; }
.vote-msg.is-error { color: #ff9a9a; }

.back-buttons {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.back-buttons .btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.6em 0.9em;
  font-size: 1.05rem;
}
.back-buttons .back-btn { flex: 0 1 auto; }
/* Already your vote (or on its way): the button stays focusable but looks "done". */
.vote-btn[aria-disabled="true"],
.vote-btn[aria-disabled="true"]:hover {
  cursor: default;
  background: var(--panel-2);
  color: var(--gold);
  box-shadow: none;
  transform: none;
}
.vote-btn[aria-busy="true"] { opacity: 0.75; cursor: progress; }
