/* ============================================
   COMBINATION DEMOS
   A small copy of the game screen that plays itself (public/demo.js).
   It is the game's own pieces -- board, strip, dice, ROLL/DONE -- on the
   player's own background, so it reads as the game, not as a video in a
   box. Sizes come from two numbers set by layout() in demo.js: --S, the
   board's side, and --R, the width of the rail with everything else.
   ============================================ */

.demo-overlay {
  position: fixed;
  inset: 0;
  z-index: 92; /* above the options menu (50) it is opened from */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.demo-overlay[hidden] {
  display: none;
}

.demo-dialog {
  --S: 300px;
  --R: 300px;
  /* The rail's em (below), set here too so the dialog's own padding, gaps
     and frame scale with the demo: 13px on a 375px phone, where every em
     value in this file equals the px it replaced; larger on a tablet, where
     fixed px left the header, captions and frame phone-sized next to a
     much bigger board. */
  font-size: round(down, calc(var(--R) * .04267), 1px);
  position: relative;
  display: grid;
  grid-template-columns: var(--S);
  gap: .923em;
  padding: .923em;
  border-radius: 1.54em;
  border: .3077em solid rgba(0, 0, 0, .35);
  background-color: whitesmoke;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  /* The background image runs under the border too (the default starts it
     inside the border), so the translucent border darkens the same image
     all the way round instead of showing the grey fallback colour as a
     second, differently shaped frame. */
  background-origin: border-box;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
}

/* Landscape: board on the left, rail on the right, as in the game. */
.demo-dialog.is-row {
  grid-template-columns: var(--S) var(--R);
  column-gap: 1.23em;
}

/* Portrait: the rail's pieces become rows of the dialog itself, so the
   title can go above the board and the rest below it. */
.demo-dialog:not(.is-row) .demo-rail {
  display: contents;
}

/* Explicit order for both layouts: the game's own classes carry `order`
   values for the game screen (.div-resultsAndCalls 3, .div-dice 4, ...)
   that would otherwise put the caption between the board and the strip. */
.demo-head { order: -1; }
.demo-board { order: 0; }
.demo-strip { order: 1; }
.demo-dice { order: 2; }
.demo-buttons { order: 3; }
.demo-caption { order: 4; }

.demo-rail {
  font-size: round(down, calc(var(--R) * .04267), 1px);
  width: var(--R);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: .77em;
}

/* The game's board, sized by --S instead of the screen. */
.demo-board.div-table {
  font-size: round(down, calc(var(--S) * .045), 1px);
  width: var(--S);
  height: var(--S);
  margin: 0;
}

.demo-strip.div-resultsAndCalls,
.demo-dice.div-dice,
.demo-buttons.div-buttons {
  width: 100%;
  margin: 0;
}

/* The demo plays itself: its board, strip, dice and ROLL/DONE ignore taps
   (no press feedback, nothing happens). Only replay and close respond. */
.demo-board,
.demo-strip,
.demo-dice,
.demo-buttons {
  pointer-events: none;
}

.demo-dice.div-dice {
  height: auto;
  max-height: none;
  padding-block: 4px;
  /* In portrait the game's dice are sized off --board-w and --game-h, which only the game's own
     column defines (.flex-block): without a size here the dice came out 0 by 0 and vanished.
     A die is 17% of the board's width there, so of --S here. */
  --die: calc(var(--S) * .17);
}

.demo-head {
  display: flex;
  align-items: center;
  gap: .615em;
}

.title.demo-title {
  flex: 1;
  width: auto;
  min-width: 0;
  margin: 0;
  font-weight: 400;
  /* 24px on the phone, scaling with the demo; the pill's height, frame and
     corners follow (they are fixed px on the options pages' .title). */
  font-size: 1.846em;
  height: 1.583em;
  border-width: .125em;
  border-radius: .417em;
  /* The look of the menu's cards (Ranking, Stats...): translucent white,
     the app's black-at-low-opacity frame, the brown Changa One. */
  background-color: rgba(255, 255, 255, .82);
  border-color: rgba(0, 0, 0, .35);
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}

.demo-icon-btn {
  position: relative;
  flex: none;
  /* As tall as the title pill next to them (38px on the phone), scaling
     with the demo. font-size: inherit because a <button> doesn't inherit
     it by default. */
  font-size: inherit;
  width: 2.923em;
  height: 2.923em;
  padding: 0;
  border-radius: 50%;
  border: .2308em solid rgba(0, 0, 0, .35); /* 3px on the phone */
  background-color: rgba(255, 255, 255, .82);
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* The tap area still reaches 44px around the 38px circle. */
.demo-icon-btn::after {
  content: "";
  position: absolute;
  inset: min(-3px, -.23em);
  border-radius: 50%;
}

/* Each symbol is one shape: drawn in opaque black inside a group that
   carries the 75% (see iconButton in demo.js), so where the arc meets the
   arrowhead, or the X's bars cross, nothing shows darker. Its line is as
   thick as the border (3px at the phone's 19px symbol = 3.79 of 24 units). */
.demo-icon-btn svg {
  width: 50%;
  height: 50%;
  overflow: visible;
}

.demo-icon-btn:focus-visible,
.rules-play:focus-visible {
  outline: 3px solid #000;
  outline-offset: 2px;
}

/* Karaoke captions: a window about three lines tall, one sentence per
   line. New lines arrive at the bottom and the earlier ones move up,
   faded but readable, then fade out at the top; the box scrolls by hand
   to reread them (see addCaption in demo.js). */
.demo-caption {
  margin: 0;
  /* 16px text, 10/12px padding and 10px corners on the phone (in this
     element's own em from here on). */
  font-size: 1.231em;
  padding: .625em .75em;
  border-radius: .625em;
  background-color: rgba(255, 255, 255, .82);
  color: #000;
  font-family: var(--text-font);
  line-height: 1.45;
  text-align: left;
  height: calc(3 * 1.45em + 1.25em);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 30%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 30%);
}

.demo-caption::-webkit-scrollbar {
  display: none;
}

.demo-lines {
  /* Pushes the stack to the bottom while it is short; once it overflows
     the margin is zero and the box scrolls normally (justify-content:
     flex-end would make the top of an overflowing stack unreachable). */
  margin-top: auto;
  /* Room above the first line: scrolled all the way up, it sits below the
     top fade instead of inside it. */
  padding-top: 1.75em;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform var(--state) var(--ease-out);
}

.demo-line {
  margin: 0;
  opacity: .45;
  transition: opacity var(--state) var(--ease-out);
}

.demo-line.is-current {
  opacity: 1;
  animation: demoLineIn var(--state) var(--ease-out);
}

@keyframes demoLineIn {
  from {
    opacity: 0;
  }
}

/* The finger that taps each control. */
.demo-finger {
  --x: 50%;
  --y: 90%;
  position: absolute;
  left: 0;
  top: 0;
  width: 2.615em;
  height: 2.615em;
  margin: -1.308em 0 0 -1.308em;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, .8);
  border: .154em solid rgba(0, 0, 0, .35);
  box-shadow: 0 .23em .615em rgba(0, 0, 0, .3);
  transform: translate(var(--x), var(--y));
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: transform 420ms var(--ease-out), opacity var(--state) var(--ease-out);
}

.demo-finger.is-visible {
  opacity: 1;
}

.demo-finger.is-tapping {
  transform: translate(var(--x), var(--y)) scale(.75);
  transition-duration: var(--tap);
}

@media (prefers-reduced-motion: reduce) {
  .demo-finger {
    transition: opacity var(--tap) linear;
  }
}

/* ============================================
   The play button on each combination in the help page.
   ============================================ */
.rules-combos > li {
  grid-template-columns: 44px minmax(0, 1fr) 44px;
}

.rules-play {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid var(--btn-border-color); /* a fixed 44px circle */
  background-color: rgba(255, 255, 255, .5);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.rules-play::before {
  content: "";
  width: 13px;
  height: 15px;
  margin-left: 3px; /* a triangle looks centred a little right of centre */
  background-color: rgba(0, 0, 0, .75);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
