/*
  Un cahier d'écolier : réglure Seyès, stylo quatre couleurs, surligneur.
  - imprimé (questions, réglages)  : Andika, encre noire
  - écrit à la main (noms, verdicts) : Playwrite FR Moderne
  - bleu = joueur 1, vert = joueur 2, rouge = correction, jaune = surligneur
*/

@font-face {
  font-family: "Andika";
  src: url("/fonts/andika-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Andika";
  src: url("/fonts/andika-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Playwrite FR Moderne";
  src: url("/fonts/playwrite-fr-moderne.woff2") format("woff2");
  font-weight: 100 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #fdfdfb;
  --rule: #c5c0ec;
  --rule-faint: #e4e1f6;
  --margin-line: #ef8296;
  --ink: #1c1c28;
  --muted: #56566b;
  --blue: #1f3fb5;
  --green: #0b7a45;
  --red: #d3202d;
  --fluo: #fff04a;
  --pen: var(--blue);
  --u: 8px;
  --hand: "Playwrite FR Moderne", "Snell Roundhand", "Segoe Script", cursive;
  --print: "Andika", "Trebuchet MS", system-ui, sans-serif;
  --wobble: 14px 18px 13px 19px / 18px 13px 19px 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--print);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(var(--rule-faint) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size:
    100% calc(var(--u) * 4),
    100% var(--u),
    calc(var(--u) * 4) 100%;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.hand {
  font-family: var(--hand);
  font-weight: 400;
}

.red {
  color: var(--red);
}

.pen-one {
  --pen: var(--blue);
}

.pen-two {
  --pen: var(--green);
}

.fluo {
  padding: 0.04em 0.3em;
  border-radius: 0.3em 0.12em 0.34em 0.1em;
  background: var(--fluo);
}

.badge {
  display: inline-block;
  margin-left: 10px;
  padding: 1px 8px;
  border: 2px solid var(--red);
  border-radius: var(--wobble);
  color: var(--red);
  font: 700 0.75rem/1.5 var(--print);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  transform: rotate(-3deg);
}

/* Gribouillages */

.head {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.head__skin {
  fill: var(--head-fill, var(--paper));
}

.tally {
  display: block;
  width: auto;
  height: 20px;
}

.icon {
  flex: none;
  width: 22px;
  height: 22px;
}

.mark {
  width: 1.1em;
  height: 1.05em;
  margin-right: 0.3em;
  color: var(--red);
  vertical-align: -0.18em;
}

.mark path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.35s 0.1s ease-out forwards;
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* Feuille : réglages et bilan */

.sheet {
  --margin: max(clamp(18px, 6vw, 72px), calc((100vw - 760px) / 2));
  position: relative;
  min-height: 100dvh;
  padding: 24px 20px 64px calc(var(--margin) + 18px);
}

.sheet::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin);
  width: 2px;
  background: var(--margin-line);
}

.sheet__body {
  max-width: 620px;
}

.date {
  min-height: 32px;
  margin: 0;
  color: var(--blue);
  font-size: 0.9375rem;
  line-height: 32px;
  text-align: right;
}

.title {
  display: inline-block;
  margin: 0 0 16px;
  padding: 0 8px 0 2px;
  border-bottom: 3px solid var(--red);
  color: var(--blue);
  font-size: clamp(1.875rem, 8.5vw, 2.75rem);
  line-height: 1.55;
}

.lede {
  max-width: 34em;
  margin: 0 0 24px;
}

.field {
  min-width: 0;
  margin: 0 0 24px;
  padding: 0;
  border: 0;
}

.field legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: 700;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 8px 16px;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  background: var(--paper);
  font-weight: 700;
  line-height: 1.2;
  text-align: left;
}

.choice small {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
}

.choice.is-on {
  padding: 7px 15px;
  border-width: 3px;
  background: var(--fluo);
}

.choice.is-on small {
  color: var(--ink);
}

.roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 24px;
  margin: 0 0 24px;
}

.card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  column-gap: 12px;
  align-items: end;
  color: var(--pen);
}

.card__head {
  grid-row: 1 / span 2;
  align-self: center;
  width: 84px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
}

.card__name {
  display: grid;
}

.card__label {
  color: var(--muted);
  font-size: 0.8125rem;
}

.card__name input {
  width: 100%;
  padding: 0 2px 2px;
  border: 0;
  border-bottom: 2px dotted currentColor;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: 1.0625rem;
  line-height: 1.8;
}

.card__name input::placeholder {
  color: currentColor;
  opacity: 0.45;
}

.card__hint {
  grid-column: 2;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 22px;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}

.btn--go {
  min-height: 60px;
  padding: 12px 34px;
  border-width: 3px;
  background: var(--fluo);
  font-size: 1.3125rem;
}

.btn:active {
  transform: scale(0.97);
}

/* Sur un petit écran, « Commencer » reste en bas de l'écran pendant qu'on règle. */
.start {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 1;
  display: flex;
}

/* Un liseré de papier détache le bouton de ce qui défile dessous. */
.start .btn--go {
  box-shadow: 0 0 0 6px var(--paper);
}

@media (max-width: 560px) {
  .start .btn--go {
    flex: 1;
  }
}

@media (hover: hover) {
  .btn:hover,
  .choice:hover {
    transform: rotate(-1deg);
  }

  .card__head:hover {
    transform: rotate(-5deg);
  }
}

.records {
  margin-top: 40px;
}

.records h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.records dl,
.stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 24px;
  margin: 0;
  line-height: 32px;
}

.records dt,
.stats dt {
  color: var(--muted);
}

.records dd,
.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.records .fluo,
.stats dd {
  font-weight: 700;
}

/* Partie : une page par joueur */

.arena {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.arena--solo {
  grid-template: "bar" auto "one" minmax(0, 1fr) / minmax(0, 1fr);
}

.arena--side {
  grid-template: "bar bar" auto "one two" minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr);
}

/* Face à face : la page du joueur 2 est retournée, la barre fait la reliure. */
.arena--face {
  grid-template: "two" minmax(0, 1fr) "bar" auto "one" minmax(0, 1fr) / minmax(0, 1fr);
}

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 2px 6px;
  border-bottom: 2px solid var(--rule);
  background: var(--paper);
}

.arena--face .bar {
  border-top: 2px solid var(--rule);
}

.bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 700;
}

.bar__btn:disabled {
  cursor: default;
  opacity: 0.28;
}

.bar__btn--text {
  min-height: 38px;
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
}

.bar__ask {
  margin-right: auto;
  padding-left: 8px;
  font-weight: 700;
}

/* Un mot dans la reliure serait à l'envers pour l'un des deux joueurs. */
.arena--face .bar__label {
  display: none;
}

.dots {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dot {
  width: 13px;
  height: 13px;
  border: 2px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
}

.dot--now {
  border-color: var(--ink);
  background: var(--fluo);
}

.dot--one {
  border-color: var(--blue);
  background: var(--blue);
}

.dot--two {
  border-color: var(--green);
  background: var(--green);
}

.dot--none {
  border-color: var(--red);
  background: linear-gradient(135deg, transparent 42%, var(--red) 42% 58%, transparent 58%) var(--paper);
}

.page {
  container: page / size;
  min-width: 0;
  min-height: 0;
}

.page--one {
  grid-area: one;
}

.page--two {
  grid-area: two;
}

.page--flipped {
  transform: rotate(180deg);
}

.arena--side .page--two {
  border-left: 2px solid var(--rule);
}

/* Celui qui écrit regarde son pavé : le calcul descend juste au-dessus. */
.page--answering .page__in {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.page--answering .sum {
  align-self: end;
}

.page__in {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(2px, 1.8cqb, 14px);
  max-width: 600px;
  height: 100%;
  margin: 0 auto;
  padding: clamp(6px, 2.4cqb, 24px) clamp(12px, 5cqi, 32px) clamp(8px, 3cqb, 28px);
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 30px;
  color: var(--pen);
}

.who__head {
  flex: none;
  width: 34px;
}

.who__name {
  min-width: 0;
  overflow: hidden;
  font-size: 0.9375rem;
  line-height: 30px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who__score {
  flex: none;
}

.chrono {
  margin-left: auto;
  color: var(--ink);
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sum {
  margin: 0;
  font-size: min(15cqi, 15cqb, 5.25rem);
  font-weight: 700;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.sum--long {
  font-size: min(7.6cqi, 12cqb, 3rem);
}

.sum__times {
  margin: 0 0.22em;
  font-weight: 400;
}

.sum__equals {
  margin: 0 0.25em;
  font-weight: 400;
}

.sum__answer {
  color: var(--pen);
}

.sum__answer--right {
  color: var(--ink);
}

.caret {
  display: inline-block;
  width: 0.5em;
  height: 0.09em;
  margin-left: 0.06em;
  background: currentColor;
  animation: blink 1s steps(2, jump-none) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.sum--count {
  color: var(--red);
  font-weight: 400;
}

.pop {
  display: inline-block;
  animation: pop 0.6s ease-out both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(1.6);
  }

  25% {
    opacity: 1;
  }

  to {
    transform: scale(1);
  }
}

.stage {
  display: grid;
  min-height: 0;
}

.stage__in {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 2cqb, 14px);
  min-height: 0;
  text-align: center;
}

.stage__in--row {
  flex-direction: row;
  gap: clamp(8px, 4cqi, 24px);
  text-align: left;
}

.stage__in--pad {
  justify-content: flex-end;
}

.stage__in--result {
  justify-content: space-evenly;
}

/* La tête : cerclée d'un trait plein, c'est un buzzer ; en pointillés, elle attend. */
.buzz {
  display: grid;
  place-items: center;
  flex: none;
  width: min(50cqi, 50cqb, 240px);
  aspect-ratio: 1;
  padding: 0;
  border: 3px dashed var(--rule);
  border-radius: 47% 53% 51% 49% / 52% 48% 53% 47%;
  background: var(--paper);
  color: var(--pen);
}

.buzz .head {
  width: 106%;
}

.buzz--live {
  border-style: solid;
  border-color: currentColor;
  animation: bob 2.6s ease-in-out infinite;
}

.buzz--live:active {
  --head-fill: var(--fluo);
  background: var(--fluo);
  animation: none;
  transform: scale(0.95);
}

@keyframes bob {
  0%,
  100% {
    transform: rotate(-1.5deg);
  }

  50% {
    transform: rotate(1.5deg) translateY(-2%);
  }
}

.stage__in--row .buzz {
  width: min(30cqi, 34cqb, 130px);
}

.hint {
  margin: 0;
  font-size: clamp(0.8125rem, 4.2cqi, 1rem);
  line-height: 1.35;
}

kbd {
  display: inline-block;
  padding: 0 7px;
  border: 1.5px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: var(--paper);
  font: 700 0.8125rem/1.5 var(--print);
}

/* Le temps qu'il reste pour écrire la réponse. */
.fuse {
  flex: none;
  width: 100%;
  max-width: 440px;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--rule-faint);
}

.fuse i {
  display: block;
  height: 100%;
  background: var(--pen);
  transform-origin: 0 50%;
  animation: fuse linear both;
}

@keyframes fuse {
  0% {
    transform: scaleX(1);
  }

  70% {
    background: var(--pen);
  }

  72% {
    background: var(--red);
  }

  100% {
    background: var(--red);
    transform: scaleX(0);
  }
}

.pad {
  display: grid;
  flex: none;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(4px, 1.6cqb, 10px);
  width: 100%;
  max-width: 440px;
  height: min(380px, 60cqb);
}

.key {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid var(--pen);
  border-radius: var(--wobble);
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(1.25rem, min(8cqi, 9cqb), 2rem);
  font-weight: 700;
  line-height: 1;
}

.key:active {
  background: var(--fluo);
  transform: scale(0.96);
}

.key--ok {
  border-width: 3px;
  background: var(--fluo);
}

.key--erase .icon {
  width: 1.2em;
  height: 1.2em;
}

/* Page basse (téléphone posé entre deux joueurs) : le pavé passe sur deux rangées. */
@container page (max-height: 340px) {
  .pad {
    grid-template-rows: repeat(2, minmax(0, 1fr));
    grid-template-columns: repeat(6, minmax(0, 1fr));
    max-width: none;
    height: min(210px, 52cqb);
  }

  .key--erase {
    grid-area: 1 / 6;
  }

  .key--zero {
    grid-area: 2 / 5;
  }

  .key--ok {
    grid-area: 2 / 6;
  }
}

.result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 4cqi, 24px);
  min-height: 0;
  text-align: left;
}

.result__head {
  flex: none;
  width: min(26cqi, 32cqb, 130px);
  color: var(--pen);
}

.verdict {
  min-width: 0;
}

.verdict p {
  margin: 0;
}

.verdict__word {
  color: var(--red);
  font-size: clamp(1.0625rem, min(6.4cqi, 9cqb), 1.75rem);
  line-height: 1.7;
  white-space: nowrap;
}

.verdict__time {
  font-size: clamp(1.125rem, min(6.4cqi, 9cqb), 1.75rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.struck {
  color: var(--pen);
  font-family: var(--print);
  font-weight: 700;
  text-decoration-line: line-through;
  text-decoration-color: var(--red);
  text-decoration-thickness: 2.5px;
}

.btn--next {
  flex: none;
  width: min(100%, 340px);
  min-height: clamp(40px, 16cqb, 56px);
  border-width: 3px;
  background: var(--fluo);
}

/* Bilan */

.headline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  margin: 8px 0 32px;
}

.headline__head {
  width: 112px;
  color: var(--pen);
}

.headline__note {
  display: grid;
  justify-items: start;
  gap: 4px;
  color: var(--red);
}

.grade {
  padding: 2px 26px 6px;
  border: 3px solid currentColor;
  border-radius: 50%;
  font-size: 2.25rem;
  line-height: 1.5;
  transform: rotate(-5deg);
}

.comment {
  margin: 0;
  color: var(--red);
  font-size: 1.375rem;
  line-height: 1.8;
  transform: rotate(-1.5deg);
  transform-origin: left;
}

.stats {
  flex-basis: 100%;
}

.headline--duel {
  display: block;
}

.headline--duel .comment {
  margin-top: 16px;
}

.duo {
  display: flex;
  align-items: end;
  gap: clamp(16px, 6vw, 48px);
}

.contender {
  display: grid;
  flex: 0 1 132px;
  justify-items: center;
  min-width: 0;
  color: var(--pen);
}

.contender__head {
  width: min(100%, 120px);
}

.contender__score {
  color: var(--ink);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;
}

.contender__name {
  font-size: 1rem;
  line-height: 1.8;
}

.recap {
  margin: 0 0 32px;
  padding: 0 0 0 1.6em;
}

.recap__row {
  line-height: 32px;
}

.recap__row::marker {
  color: var(--muted);
  font-size: 0.875rem;
}

.recap__sum {
  margin-right: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.recap__out {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  color: var(--pen);
  white-space: nowrap;
}

.recap__out.red {
  color: var(--red);
}

.recap__out .hand {
  font-size: 0.9375rem;
}

.recap__time {
  color: var(--ink);
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .buzz--live,
  .pop,
  .caret {
    animation: none;
  }

  .mark path {
    stroke-dashoffset: 0;
    animation: none;
  }

  .btn:hover,
  .choice:hover,
  .card__head:hover {
    transform: none;
  }
}
