/* How to play: a full-screen page over the game that scrolls on its own.
   Above the waiting screen (2000), under game over and quit (3000).
   rules.js sets the colours from the game config; these are the fallbacks. */
.rules {
  --c1: #41e83f;
  --c2: #cf3df2;
  --c3: #f5e63c;
  --c4: #3cdcf2;
  --bay: #41e83f; /* this window's own colour */
  --wild: linear-gradient(
    135deg,
    #41e83f 0% 25%,
    #cf3df2 25% 50%,
    #f5e63c 50% 75%,
    #3cdcf2 75% 100%
  );
  --pane: 14px; /* pane width in the pictures; panes are 1.5 times taller, as on the façade */
  --gap: 2px;
  --muted: #a8a8a8;
  --line: #232323;
  --panel: #121212;

  position: fixed;
  inset: 0;
  z-index: 2500;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: #0a0a0a;
  color: #ddd;
  /* The same on the start page, which has a font of its own */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  text-align: left;
  letter-spacing: normal;
  text-transform: none;
  animation: rules-in 0.2s ease-out;
}

.rules[hidden],
.rules [hidden] {
  display: none !important;
}

/* The page under it stays put while the rules scroll (the start page scrolls) */
body:has(.rules:not([hidden])) {
  overflow: hidden;
}

@keyframes rules-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.rules:focus {
  outline: none;
}

.rules b {
  color: #fff;
}

/* Title and Close stay in reach while scrolling */
.rules-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #0a0a0a;
  border-bottom: 1px solid var(--line);
}

.rules-bar h2 {
  font-size: 20px;
  color: #fff;
}

.rules-close,
.rules-done {
  font-size: 15px;
  font-weight: bold;
  color: #000;
  background: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
}

.rules-close {
  padding: 9px 18px;
}

.rules-done {
  display: block;
  width: 100%;
  margin-top: 24px;
  padding: 14px;
  font-size: 16px;
}

.rules-body {
  max-width: 520px;
  margin: 0 auto;
  padding: 4px 16px 32px;
}

/* Shown when opened during a game */
.rules-live {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px 12px;
  font-weight: 600;
  color: #c9f7c8;
  background: rgba(65, 232, 63, 0.1);
  border: 1px solid rgba(65, 232, 63, 0.35);
  border-radius: 8px;
  text-wrap: balance;
}

.rules-live::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c1);
  box-shadow: 0 0 8px var(--c1);
  animation: rules-pulse 1.2s ease-in-out infinite alternate;
}

/* Sections take turns with the colours in play */
.rules-section {
  --accent: var(--c1);
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.rules-section:nth-of-type(4n + 2) {
  --accent: var(--c2);
}

.rules-section:nth-of-type(4n + 3) {
  --accent: var(--c3);
}

.rules-section:nth-of-type(4n + 4) {
  --accent: var(--c4);
}

/* Each heading starts with a lit pane */
.rules-section h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 18px;
  color: #fff;
}

.rules-section h3::before {
  content: "";
  flex: none;
  width: 10px;
  height: 15px;
  border-radius: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.rules-section p,
.rules-list li {
  margin-bottom: 8px;
}

.rules-section p:last-child,
.rules-list li:last-child {
  margin-bottom: 0;
}

.rules-list {
  padding-left: 18px;
}

.rules-list li::marker {
  color: var(--accent);
}

/* A picture beside its words; below them when there is no room */
.rules-side {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
}

.rules-side > :last-child {
  flex: 1 1 150px;
  min-width: 0;
}

.rules-figs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.rules figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.rules-figs figure {
  flex: 1 1 0;
  min-width: 64px;
}

/* Boards of different heights sit in the middle of their cards */
.rules figure > [data-pic] {
  flex: 1;
  display: flex;
  align-items: center;
}

/* Balanced, so a caption that wraps keeps "8 touch" together */
.rules figcaption {
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
  color: var(--muted);
}

.rules figcaption.yes::before {
  content: "✓ ";
  font-weight: bold;
  color: var(--c1);
}

.rules figcaption.no::before {
  content: "✗ ";
  font-weight: bold;
  color: #ff6b6b;
}

/* Chain: three steps in one row with arrows between */
.rules-steps {
  flex-wrap: nowrap;
  gap: 4px;
}

.rules-steps figure {
  min-width: 0;
  padding: 10px 4px;
}

.rules-arrow {
  flex: none;
  align-self: center;
  color: var(--muted);
}

/* Countdown: the window and the number the phone shows, in the window's colour */
.rules-countdown {
  justify-content: center;
}

.rules-countdown figure {
  flex: 0 1 64px;
}

.rules figcaption.count {
  font-size: 20px;
  font-weight: bold;
  line-height: 1;
  color: var(--bay);
  text-shadow: 0 0 12px var(--bay);
}

/* Pictures: panes in a grid, a numbered window as its windows stacked */
[data-pic="single"],
[data-pic="domino"],
[data-pic="ell"],
[data-pic="wild"] {
  --pane: 16px;
}

[data-pic^="chain"] {
  --pane: 12px;
}

[data-pic^="countdown"] {
  --pane: 4px;
  --gap: 1px;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--pane));
  grid-auto-rows: calc(var(--pane) * 1.5);
  gap: var(--gap);
}

/* The brickwork between windows is about a pane wide */
.mini-bay {
  display: flex;
  flex-direction: column;
  gap: var(--pane);
}

.pane {
  position: relative;
  border-radius: 1px;
  background: #1f1f1f;
}

.pane.none {
  visibility: hidden;
}

.pane.lit {
  background: var(--c);
  box-shadow: 0 0 calc(var(--pane) * 0.5) var(--c);
}

.pane.wild {
  background: var(--wild);
  box-shadow: 0 0 calc(var(--pane) * 0.5) rgba(255, 255, 255, 0.5);
}

/* Panes that clear flash white */
.pane.clears::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #fff;
  opacity: 0;
  animation: rules-flash 1.8s ease-in-out infinite;
}

/* The phone's buttons, small */
.mini-pad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 40px);
  gap: 5px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mini-pad span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 2px;
  font-size: 9px;
  font-weight: bold;
  text-transform: uppercase;
  color: #bbb;
  background: #222;
  border: 1px solid #444;
  border-radius: 6px;
}

.mini-pad img {
  width: 14px;
  height: 14px;
}

.pad-left {
  grid-column: 1;
  grid-row: 1 / span 2;
}

.pad-right {
  grid-column: 3;
  grid-row: 1 / span 2;
}

.pad-rotate {
  grid-column: 2;
  grid-row: 1;
}

.pad-down {
  grid-column: 2;
  grid-row: 2;
}

.mini-pad .pad-drop {
  grid-column: 1 / span 3;
  grid-row: 3;
  padding: 7px;
  font-size: 11px;
  color: #fff;
}

@keyframes rules-flash {
  0%,
  45%,
  100% {
    opacity: 0;
  }
  60%,
  80% {
    opacity: 0.9;
  }
}

@keyframes rules-pulse {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

/* Still pictures: the panes that clear get a white ring instead of a flash */
@media (prefers-reduced-motion: reduce) {
  .rules,
  .pane.clears::after,
  .rules-live::before {
    animation: none;
  }
  .pane.clears {
    outline: 2px solid #fff;
    outline-offset: -2px;
  }
}
