.minigame-rules {
  display: grid;
  gap: 18px;
  color: #f4edf9;
  overflow-wrap: anywhere;
}

.minigame-rules section {
  display: grid;
  gap: 8px;
}

.minigame-rules h3, .minigame-rules p, .minigame-rules ol, .minigame-rules dl, .minigame-rules dd {
  margin: 0;
}

.minigame-rules ol {
  display: grid;
  gap: 8px;
  padding-inline-start: 1.5em;
}

.minigame-rules li { padding-inline-start: 4px; }
.minigame-rules li::marker { color: #be99f2; }
.minigame-rules-version { color: #c8b5d6; }

.minigame-rules dl {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border-radius: 12px;
  background: #b3a1c320;
}

.minigame-rules dl div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 8px;
  align-items: baseline;
  padding: 7px 10px;
  background: #21192b;
}

.minigame-rules dd {
  color: #ead9f6;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.minigame-rules .button { justify-self: start; }
.minigame-rules > button { justify-self: end; }

.mini-game-tools { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
#dialog:has(.minigame-rules) { width:min(560px,calc(100% - 24px)); }
#dialog:has(.minigame-rules) .dialog-head { align-items:start; }

html[data-ludik-theme="comic"] #dialog:is(:has(.minigame-rules[data-rules-game="plinko"]), [data-variant="plinko-proof"], [data-variant="plinko-history"]) {
  --rules-ink: #1b120c;
  --rules-cream: #fff1ce;
  --rules-yellow: #ffe323;
  --rules-mint: #95ecab;
  --rules-pink: #fb278c;
  --rules-edge: polygon(
    0 3%, 6% .7%, 13% 2%, 19% .1%, 26% 1.6%, 35% 0, 43% 1.4%, 50% .4%,
    56% 1.8%, 64% .4%, 71% 1.6%, 79% .3%, 87% 1.5%, 94% .3%, 99% 2.8%,
    98.8% 11%, 100% 18%, 98.8% 26%, 99.6% 35%, 98.8% 43%, 100% 50%, 98.7% 59%,
    99.6% 67%, 98.9% 75%, 100% 83%, 98.9% 90%, 99.3% 97%, 93% 100%, 85% 98.2%,
    78% 99.6%, 70% 98.2%, 61% 99.9%, 53% 98.1%, 44% 99.7%, 36% 98.1%, 28% 99.8%,
    21% 98.3%, 14% 99.8%, 8% 98.2%, 1% 99.4%, .2% 91%, 1.3% 82%, .1% 74%,
    1.1% 66%, 0 57%, 1.2% 49%, .2% 39%, 1.1% 30%, 0 22%, 1.2% 14%
  );
  box-sizing: border-box;
  width: min(670px, calc(100% - 22px));
  max-block-size: calc(100dvh - 28px);
  overflow: visible;
  padding: 0;
  color: var(--rules-ink);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;

  &::backdrop { background: #160b0eea; }
  & #dialog-content {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    position: relative;
    isolation: isolate;
    max-block-size: calc(100dvh - 28px);
    padding: clamp(14px, 3vw, 27px);
    gap: clamp(10px, 2vw, 18px);
  }
  & #dialog-content::before,
  & #dialog-content::after {
    position: absolute;
    inset: 0 -3px -5px;
    z-index: -2;
    clip-path: var(--rules-edge);
    background: var(--rules-ink);
    pointer-events: none;
    content: "";
  }
  & #dialog-content::after {
    inset: 2px 0 0;
    z-index: -1;
    background: var(--rules-cream) url("/redesign-art/paper.webp") center / 500px auto;
  }
  & .dialog-head {
    align-items: center;
    margin: 0;
    gap: .6rem;
  }
  & .dialog-head h2 {
    position: relative;
    isolation: isolate;
    margin: 0;
    padding: .38em .52em;
    color: var(--rules-ink);
    font: italic 900 clamp(1.5rem, 4.9vw, 2.65rem)/1.02 var(--ld-display);
    letter-spacing: -.012em;
    overflow-wrap: normal;
  }
  & .dialog-head:has(.dialog-back) h2 { margin-inline-end: auto; }
  & .dialog-head h2::before,
  & .dialog-head h2::after {
    position: absolute;
    inset: 0;
    z-index: -2;
    transform: skew(-5deg) rotate(-1.1deg);
    background: var(--rules-ink);
    clip-path: polygon(1% 3%, 31% 0, 37% 3%, 57% 1%, 84% 5%, 99% 0, 98% 32%, 100% 50%, 98% 71%, 99% 98%, 68% 95%, 62% 100%, 24% 94%, 0 99%, 2% 69%, 0 38%);
    content: "";
  }
  & .dialog-head h2::after { inset: 2px; z-index: -1; background: var(--rules-yellow); }
  & .dialog-head .icon-button {
    flex: 0 0 auto;
    inline-size: 44px;
    block-size: 44px;
    color: var(--rules-ink);
    border: 2px solid var(--rules-ink);
    border-radius: 3px;
    background: var(--rules-cream);
    box-shadow: 2px 3px var(--rules-ink);
    font: 850 1.43rem/1 var(--font-interface);
  }
  & .dialog-head .icon-button:hover { background: #ffd0e0; }
  & :is(.minigame-rules, .comic-plinko-dialog-body) {
    min-block-size: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--rules-ink) transparent;
    padding: 2px 7px 7px 2px;
    gap: clamp(12px, 2.4vw, 18px);
    color: var(--rules-ink);
    font: 590 clamp(.82rem, 1.9vw, 1rem)/1.46 var(--font-interface, system-ui, sans-serif);
  }
  & .dialog-feedback {
    margin: 0;
    padding: .55rem .72rem;
    color: #7b1431;
    border: 2px solid var(--rules-ink);
    border-radius: 3px;
    background: #ffdae3;
  }
  & .minigame-rules section {
    --rule-accent: var(--rules-pink);
    gap: .64rem;
    margin: 0;
    padding: 0 clamp(.68rem, 2vw, 1rem) clamp(.68rem, 2vw, 1rem);
    border: 2px solid var(--rules-ink);
    border-radius: 3px;
    background: #fff4d7;
    box-shadow: 2px 3px var(--rules-ink);
  }
  & .minigame-rules section:nth-child(2) { --rule-accent: var(--rules-yellow); }
  & .minigame-rules section:last-of-type { --rule-accent: var(--rules-mint); }
  & .minigame-rules h3 {
    margin-inline: calc(-1 * clamp(.68rem, 2vw, 1rem));
    padding: .4em .7em;
    color: var(--rules-cream);
    border-inline-start: .33rem solid var(--rule-accent);
    background: var(--rules-ink);
    font: italic 850 clamp(1.12rem, 2.8vw, 1.55rem)/1.15 var(--ld-display);
    word-spacing: .08em;
  }
  & .minigame-rules li::marker { color: #8a194b; font-weight: 880; }
  & .minigame-rules-version { color: #5c3b26; font-size: .85em; font-weight: 760; }
  & .minigame-rules dl {
    gap: 0;
    border: 1.5px solid var(--rules-ink);
    border-radius: 1px;
    background: #fff8e6;
  }
  & .minigame-rules dl div {
    grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr);
    border-block-end: 1px solid #1b120c50;
    background: transparent;
  }
  & .minigame-rules dl div:nth-child(even) { background: #f4e4be; }
  & .minigame-rules dl div:last-child { border-block-end: 0; }
  & .minigame-rules dt { font-weight: 780; }
  & .minigame-rules dd { color: #512b1a; font-weight: 730; }
  & .minigame-rules .button {
    max-width: 100%;
    min-block-size: 44px;
    padding-inline: .86em;
    color: var(--rules-ink);
    border: 2px solid var(--rules-ink);
    border-radius: 3px;
    background: var(--rules-mint);
    box-shadow: 2px 3px var(--rules-ink);
    font-weight: 860;
    white-space: normal;
  }
  & .minigame-rules > .button {
    background: var(--rules-yellow);
    font: italic 850 clamp(1.15rem, 2.6vw, 1.5rem)/1 var(--ld-display);
    transform: skew(-4deg);
  }
  & .minigame-rules .button:hover { background: #ffe99c; }
  & button:focus-visible { outline: 3px solid #ce1768; outline-offset: 2px; }
}
