/*
 * The rules dialog (screens 14 and 15), on top of style.css, which `public/rules-dialog.js`
 * builds: three steps side by side on a wide screen; one step at a time on a narrower one, in a
 * bottom sheet on a phone.
 */

/* The page does not scroll under the dialog. */
html:has(.rules-dialog[open]) {
  overflow: hidden;
}

.rules-dialog {
  width: calc(100% - 48px);
  max-width: 560px;
  max-height: calc(100dvh - 48px);
  padding: 0;
  border-radius: var(--radius-3xl);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-dialog);
  box-shadow: var(--shadow-dialog);
  color: var(--color-text);
}

.rules-dialog[open] {
  display: flex;
  animation: rules-dialog-in var(--motion-dialog) ease-out;
}

.rules-dialog::backdrop {
  background: var(--color-scrim);
  backdrop-filter: blur(6px);
}

/* The panel fills the dialog, so that a click outside it lands on the backdrop. */
.rules-panel {
  flex: 1;
  min-width: 0;
  padding: 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.rules-handle {
  display: none;
}

.rules-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.rules-heading {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.rules-goal {
  font-size: 16px;
  color: var(--color-text-secondary);
}

.rules-close {
  width: 44px;
  flex-shrink: 0;
  padding: 0;
}

/* The steps: one at a time, until a wide screen shows the three. */
.rules-steps {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rules-step {
  padding: 16px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  background: var(--color-surface-inset);
  display: none;
  flex-direction: column;
  gap: 14px;
}

.rules-step.is-current {
  display: flex;
}

/* The board of a step, drawn by the classes of the board of the game, at its own width. */
.rules-picture {
  container-type: inline-size;
  display: flex;
  justify-content: center;
}

.board-picture {
  --board-width: min(284px, 100cqi);
  --strip-height: calc(var(--board-unit) * var(--strip-full-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--strip-gap);
}

.board-picture .column-button {
  cursor: default;
}

.rules-step-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rules-counter {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.rules-step-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rules-number {
  display: none;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-border);
  font-size: 14px;
  font-weight: 700;
  place-items: center;
}

.rules-step-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.rules-step-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.rules-text-touch {
  display: none;
}

/* The bottom: a dot per step, « Passer » and « Suivant », until a wide screen shows the keys. */
.rules-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.rules-keys {
  display: none;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--color-text-muted);
}

.rules-keys kbd {
  min-width: 26px;
  height: 26px;
}

.rules-dots {
  display: flex;
  gap: 6px;
}

.rules-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--color-handle);
  transition: width var(--motion-fast);
}

.rules-dot.is-current {
  width: 22px;
  background: var(--color-text);
}

.rules-actions {
  display: flex;
  gap: 8px;
}

.rules-skip,
.rules-next,
.rules-start {
  min-height: 48px;
  border-radius: var(--radius-md);
  font-size: 15px;
}

.rules-skip {
  padding: 0 16px;
  color: var(--color-text-secondary);
}

.rules-skip:hover {
  color: var(--color-text);
}

.rules-next {
  padding: 0 22px;
  font-weight: 700;
}

.rules-start {
  display: none;
  padding: 0 26px;
  font-size: 16px;
  font-weight: 700;
}

@keyframes rules-dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

@keyframes rules-sheet-in {
  from {
    transform: translateY(100%);
  }
}

/* Narrow screens: a bottom sheet with its handle, and the text of a touch screen. */
@media (max-width: 599px) {
  .rules-dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 24px);
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
    box-shadow: var(--shadow-sheet);
  }

  .rules-dialog[open] {
    animation: rules-sheet-in var(--motion-sheet) ease-out;
  }

  .rules-panel {
    padding: 12px 20px 24px;
    gap: 16px;
  }

  .rules-handle {
    display: block;
    align-self: center;
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: var(--color-handle);
  }

  .rules-header {
    align-items: center;
  }

  .rules-title {
    font-size: 24px;
  }

  .rules-goal {
    display: none;
  }

  .rules-text-wide {
    display: none;
  }

  .rules-text-touch {
    display: inline;
  }
}

/* Wide screens: the three steps side by side, each numbered, with the keys and « C'est parti ». */
@media (min-width: 960px) {
  .rules-dialog {
    max-width: 1000px;
  }

  .rules-panel {
    padding: 36px;
    gap: 28px;
  }

  .rules-title {
    font-size: 34px;
  }

  .rules-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }

  .rules-step,
  .rules-step.is-current {
    padding: 20px;
    display: flex;
  }

  .rules-picture {
    height: 236px;
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    align-items: center;
  }

  .board-picture {
    --board-width: min(224px, 100cqi);
  }

  .rules-step-body {
    gap: 14px;
  }

  .rules-counter {
    display: none;
  }

  .rules-number {
    display: grid;
  }

  .rules-keys {
    display: flex;
  }

  .rules-dots,
  .rules-skip,
  .rules-next {
    display: none;
  }

  .rules-start {
    display: inline-flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rules-dialog[open] {
    animation: none;
  }

  .rules-dot {
    transition: none;
  }
}
