/* Modals. They are white whatever the page uses (each restores the light colors inside itself), use the display font in capitals,
   and roll in as if wrapped on a rolling pin. */

dialog {
  color-scheme: light;
  --page-background: #f6f4ef; --panel-background: #ffffff; --text-color: #1d1d1f; --muted-text-color: #6b6b70; --line-color: #d9d5cb;
  --button-background: #1d1d1f; --button-text-color: #ffffff;
  width: min(92vw, 400px); padding: 20px calc(20px + 0.75rem); border: 1px solid var(--line-color); border-radius: 14px;
  background: var(--panel-background); color: var(--text-color);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { font-size: 28px; margin: 0 0 14px; }
dialog fieldset { border: 0; margin: 0 0 22px; padding: 0; }
/* a centered label with a gray line running out to each side (beside the text, not behind it) */
dialog legend { display: flex; align-items: center; gap: 12px; width: 100%; padding: 0; margin-bottom: 6px; color: var(--muted-text-color); font-size: 16px; text-align: center; }
dialog legend::before, dialog legend::after { content: ""; flex: 1; height: 2px; background: var(--line-color); }
.dialog-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 30px; }

/* the display font, made for capitals, with equal space above and below */
.fancy, .fancy * { font-family: var(--display-font); font-feature-settings: "case"; font-weight: 800; text-transform: uppercase; line-height: 1; }
.fancy { font-size: 19px; overflow: visible; padding-top: 40px; --spring-time: 1200ms; --spring: ease; }
/* a springy easing (overshoots, then settles) for the boxes resizing; browsers without linear() keep plain ease */
@supports (transition-timing-function: linear(0, 1)) {
  .fancy {
    --spring: linear(0, 0.012 0.7%, 0.045 1.4%, 0.175 2.9%, 0.896 8.2%, 1.131 10.3%, 1.276 12.3%, 1.317 13.3%, 1.339 14.4%, 1.335 15.9%, 1.292 17.6%, 1.03 23.3%, 0.948 25.5%, 0.904 27.4%, 0.884 29.3%, 0.895 32.1%, 1.009 39.7%, 1.03 41.9%, 1.039 44.1%, 1.036 47.1%, 0.997 54.6%, 0.987 58.9%, 1.004 73.5%, 1);
  }
}
/* the title straddles the top edge; its stroke is the box color, so it reads as part of the box */
.fancy h2 {
  position: absolute; top: 0; left: 50%; margin: 0; transform: translate(-50%, -42%); font-size: 44px; letter-spacing: 0.5px; white-space: nowrap;
  color: var(--text-color); -webkit-text-stroke: 10px var(--panel-background); paint-order: stroke fill; stroke-linejoin: round;
}
/* a band of the modal's own color behind the middle of the title, well inside the letters' outline: the small counters of
   letters like B, A, O, P and G can get their stroke cancelled out, and without this the page behind shows through them */
.fancy h2::before { content: ""; position: absolute; z-index: -1; left: 8px; right: 8px; top: 22%; bottom: 22%; background: var(--panel-background); }

/* a modal rolls in as if wrapped on a rolling pin: it rotates about a horizontal axis 185px behind it, from tilted 60° down (30° off
   flat) to facing forward; on close (the .closing class) it rolls back the other way */
@keyframes dialog-roll-in {
  from { opacity: 0; transform: perspective(700px) translateZ(-185px) rotateX(-60deg) translateZ(185px); }
  to { opacity: 1; transform: perspective(700px) translateZ(-185px) rotateX(0deg) translateZ(185px); }
}
@keyframes dialog-roll-out {
  from { opacity: 1; transform: perspective(700px) translateZ(-185px) rotateX(0deg) translateZ(185px); }
  to { opacity: 0; transform: perspective(700px) translateZ(-185px) rotateX(-60deg) translateZ(185px); }
}
@keyframes backdrop-fade-in { from { opacity: 0; } }
@keyframes backdrop-fade-out { to { opacity: 0; } }
dialog[open] { animation: dialog-roll-in 0.6s cubic-bezier(0.22, 1, 0.36, 1); }   /* zips in, then slows to a stop */
dialog[open]::backdrop { animation: backdrop-fade-in 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
dialog.closing { animation: dialog-roll-out 0.2s ease forwards; }
dialog.closing::backdrop { animation: backdrop-fade-out 0.2s ease forwards; }

/* ---- choices: boxes in a row, the picked one a little bigger ---- */
.choices { display: grid; gap: 8px; column-gap: 12px; }
.choices.two { grid-template-columns: repeat(2, 1fr); }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choices.one { margin-top: 8px; }   /* Absurd: a full-width bar under the other difficulties, once it's unlocked */
.choices.one[hidden] { display: none; }
.choices label { display: block; cursor: pointer; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 54px;
  padding: 14px 4px; border: 2px solid var(--line-color); border-radius: 10px; background: var(--page-background);
  outline: 0 solid var(--button-background); outline-offset: 0;
  transition: outline-width 0.25s ease, outline-offset 0.25s ease, background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.choices span .symbol { width: 38px; height: 38px; }
/* the symbol buttons are reversed: the symbol's color is the background and the symbol and text are white. They are square boxes
   in a row: the picked one takes 36% of the width and the others 32% each, easing when it changes. The row's height is fixed at the
   picked size (36% of the width left after the two 12px gaps, plus the outline room), so the modal doesn't change height. */
.side-choices { container-type: inline-size; }
.choices.sides { display: flex; align-items: center; padding: 5px 0; height: calc((100cqw - 24px) * 0.36 + 10px); }
.choices .side { --side-color: var(--player-1-color); flex: 8 1 0; min-width: 0; transition: flex-grow var(--spring-time) var(--spring); }
.choices .side[data-player="2"] { --side-color: var(--player-2-color); }
.choices .side[data-player="3"] { --side-color: var(--player-3-color); }
.choices .side:has(input:checked) { flex-grow: 9; }
.choices .side span {
  background: var(--side-color); border-color: var(--side-color); color: #fff; aspect-ratio: 1; min-height: 0; padding: 0;
  outline: 0 solid var(--side-color); outline-offset: 0; transition: outline-width 0.25s ease, outline-offset 0.25s ease;
}
.choices .side .symbol { width: 50%; height: auto; aspect-ratio: 1; filter: brightness(0) invert(1); }
.choices .side input:checked + span { outline-width: 3px; outline-offset: 2px; }
/* the text buttons (difficulty) grow a little when picked too, with the same spring, in a row fixed at the picked height so nothing below moves */
.choices.two, .choices.three, .choices.one { display: flex; align-items: center; height: 60px; }
.choices:not(.sides) label { flex: 8 1 0; min-width: 0; transition: flex-grow var(--spring-time) var(--spring); }
.choices:not(.sides) label:has(input:checked) { flex-grow: 9; }
.choices:not(.sides) span {
  height: 54px; min-height: 0;
  transition: height var(--spring-time) var(--spring), outline-width 0.25s ease, outline-offset 0.25s ease, background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.choices:not(.sides) input:checked + span { height: 60px; }
.choices:not(.sides) input:checked + span { border-color: var(--button-background); background: var(--button-background); color: var(--button-text-color); outline-width: 3px; outline-offset: 2px; }
.choices.one input:checked + span { border-color: var(--absurd-color); background: var(--absurd-color); color: #fff; outline-color: var(--absurd-color); }   /* Absurd is picked in purple, a fourth color beside the symbols' */
.choices input:focus-visible + span { outline: 2px solid var(--text-color); outline-offset: 2px; }

/* the line under the symbol boxes: plain text, with the filled-in words in the picked symbol's color. It reserves two lines so
   the modal doesn't change height when the text changes. */
.dialog-note { margin: 14px 0 0; min-height: 1.7em; text-align: center; font-size: 17px; line-height: 1.3; color: var(--muted-text-color); }
@media (max-width: 480px) { .dialog-note { min-height: 3.4em; } }
.dialog-note[data-side="1"] { --note-color: var(--player-1-color); }
.dialog-note[data-side="2"] { --note-color: var(--player-2-color); }
.dialog-note[data-side="3"] { --note-color: var(--player-3-color); }
/* the colored words are a little bigger; the small drop keeps their capitals centered on the plain words' capitals */
.dialog-note .highlight { color: var(--note-color, var(--text-color)); font-size: 1.3em; vertical-align: -0.08em; margin-left: 2px; }
.no-wrap-phrase { white-space: nowrap; }
/* the line under the symbol boxes: "plays THIRD" and "best for BEGINNERS" are two groups with a little room between them, and the line
   never wraps (a narrow phone gets smaller type instead) */
.side-note { white-space: nowrap; }
.side-note .no-wrap-phrase + .no-wrap-phrase { margin-left: 0.5em; }
@media (max-width: 400px) { .side-note { font-size: 16px; } }
@media (max-width: 370px) { .side-note { font-size: 15px; } }
@media (max-width: 340px) { .side-note { font-size: 14px; } }
.unlock-note { --note-color: var(--absurd-color); }
.unlock-note .highlight.neutral { color: var(--text-color); }   /* "hard" in the same larger type, but black */

/* the Game Help message: 20px sentence case like How to Play's words, with "You" or a symbol standing out in the player's color */
.game-help-message, .plain-message { min-height: 0; font-size: 20px; color: var(--text-color); }
.game-help-message, .game-help-message *, .plain-message, .plain-message * { text-transform: none; font-feature-settings: normal; line-height: 1.28; }
.game-help-message .highlight, .plain-message .highlight { text-transform: uppercase; font-feature-settings: "case"; }   /* a name picked out in the text (a difficulty) stays in capitals */
.game-help-message .highlight[data-player="1"] { --note-color: var(--player-1-color); }
.game-help-message .highlight[data-player="2"] { --note-color: var(--player-2-color); }
.game-help-message .highlight[data-player="3"] { --note-color: var(--player-3-color); }
.dialog-note .symbol { width: 1.3em; height: 1.3em; vertical-align: -0.3em; margin-right: 0.15em; }

@media (prefers-reduced-motion: reduce) {
  dialog, dialog::backdrop { animation: none !important; }
  .choices span, .choices:not(.sides) span, .choices:not(.sides) label, .choices .side, .choices .side span { transition: none; }
}
