/* The How-to-Play dialog.
 *
 * Each mode page used to carry its rules as a ~500-word <section class="content-section">
 * sitting directly under #history. That prose is not optional — styles/content.css
 * explains why it exists at all — but it does not need to be on screen, and
 * below the board it pushed the answer box and everything after it off the
 * page. So the words moved in here verbatim: still in the document, still the
 * page's publisher content, opened from the button in the sub-bar.
 *
 * The markup is a plain <div hidden> rather than <dialog>. showModal() would
 * give the focus trap, the backdrop and Escape for free, but ::backdrop is not
 * styleable to the same degree across the browsers this site sees. js/howto.js
 * does those four jobs instead.
 */

.howto-backdrop[hidden] { display: none; }

.howto-backdrop {
  position: fixed;
  inset: 0;
  /* Above anything AdSense injects into the page. A dimmed page with an ad
     punched through it is worse than no dimming at all. */
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vh 4vw;
  /* Dim to focus: this is a modal task, so the page behind it is pushed back
     rather than left as a live parallel surface. */
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(0px);
  opacity: 0;
  transition: opacity var(--dur-enter) var(--ease-out),
              backdrop-filter var(--dur-enter) var(--ease-out);
}

/* Added a frame after `hidden` comes off, so the browser has a painted start
   state to move away from — set both in the same frame and there is no
   transition, just a pop. */
.howto-backdrop.is-open {
  opacity: 1;
  backdrop-filter: blur(6px);
}

/* Scale and the backdrop's blur run on the same curve and duration, so the
   panel reads as a surface arriving rather than an opacity fade over a page
   that went blurry independently. 0.96 rather than something smaller: this is
   a large surface, and a big scale on a big object reads as a zoom effect
   instead of as something being placed. */
.howto-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  /* The prose inside is capped at 68ch by .content-section; this leaves room
     for the panel's own padding around that measure. */
  max-width: 76ch;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  /* The deepest shadow in the set — the largest floating surface on the site,
     and the only one that has to read as being well clear of the page. */
  box-shadow: var(--shadow-lg);
  scale: 0.96;
  transition: scale var(--dur-enter) var(--ease-out);
}

.howto-backdrop.is-open .howto-panel { scale: 1; }

/* Sticky, so the title and the close button stay reachable through a long
   scroll. Translucent rather than opaque because prose passes underneath it. */
.howto-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: rgba(20, 20, 20, 0.82);
  backdrop-filter: blur(12px) saturate(160%);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.howto-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-caps-lg);
  text-transform: uppercase;
  color: var(--text);
  margin: 0;
}

/* Quiet outline, same family as #soundBtn and .howto-trigger — closing is
   chrome, not an action worth an accent fill. */
.howto-close {
  flex-shrink: 0;
  font-size: var(--text-lg);
  line-height: var(--leading-none);
  padding: 8px 13px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.howto-close:hover {
  background: transparent;
  border-color: var(--accent);
  color: var(--text);
}

.howto-body {
  overflow-y: auto;
  padding: 24px;
  /* .content-section carries `margin: 0 auto 40px` for its life on a page; in
     here the panel's own padding is the spacing, and a trailing 40px reads as
     the scroll having stopped short. */
  margin: 0 auto;
}

/* The first heading of the moved prose is now the panel's title, so the body
   starts on a paragraph. Reclaims the top margin .content-section h3 carries
   for headings that follow text. */
.howto-body > :first-child { margin-top: 0; }

@media (max-width: 640px) {
  /* Full-bleed on a phone: a centred card with 4vw showing on each side wastes
     the only dimension this content needs. */
  .howto-backdrop { padding: 0; align-items: stretch; }
  .howto-panel {
    max-width: none;
    max-height: 100vh;
    border: 0;
    border-radius: 0;
  }
  .howto-head { border-radius: 0; padding: 14px 18px; }
  .howto-body { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  /* Cross-fade rather than a surface that travels. The global block in
     base.css already flattens the durations; this stops the panel scaling at
     all, so what is left is a plain opacity change. */
  .howto-panel { scale: 1; }
  .howto-backdrop { backdrop-filter: none; }
  .howto-backdrop.is-open { backdrop-filter: none; }
}

/* base.css dropped its prefers-reduced-transparency block when the header
   stopped being translucent — nothing on the site used a backdrop-filter any
   more. This file reintroduces two, so the preference has something to answer
   again: both surfaces go solid and the blur goes entirely. */
@media (prefers-reduced-transparency: reduce) {
  .howto-backdrop,
  .howto-backdrop.is-open {
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: none;
  }
  .howto-head {
    background: var(--surface);
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .howto-panel { border-color: var(--text-muted); }
}
