:root {
    color-scheme: dark;
    font: 100%/1.45 system-ui, sans-serif;
    --text: #f7f4ed;
    --muted: #b0b7c1;
    --border: #373d46;
    --accent: #ff975a;
    --green: #73cd9c;
    --yellow: #f3cb67;
    --red: #ff8279;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    min-height: 100vh;
    margin: 0;
    padding-bottom: 2rem;
    background: radial-gradient(ellipse at 50% 0, #282e38, #101318 48rem);
    color: var(--text);
}

button, input, select { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, .level:has(:focus-visible) .level-face,
.helmet-option:has(:focus-visible) .helmet-option-face {
    outline: 3px solid #a2d3ff;
    outline-offset: 4px;
}

.sr-only, .level input, .helmet-option input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.shell {
    display: flow-root;
    width: min(60rem, 100% - 2rem);
    margin-inline: auto;
}

.site-header { padding-top: clamp(.85rem, 3vw, 1.5rem); }

.site-logo {
    display: block;
    width: min(100%, 23rem);
    height: auto;
    margin-inline: auto;
}

#setup {
    max-width: 45rem;
    margin: clamp(.85rem, 2.5vh, 1.5rem) auto 0;
}

h1 {
    margin: 0;
    font-size: clamp(2.2rem, 6.8vw, 4.2rem);
    font-weight: 900;
    font-style: italic;
    letter-spacing: -.05em;
    line-height: 1.01;
}
#setup-title { margin-bottom: clamp(1.2rem, 4vw, 2rem); }

fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }

.levels {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .75rem;
}

.level { cursor: pointer; position: relative; }

.level-face {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: .25rem;
    height: 100%;
    min-height: 5.5rem;
    padding: .8rem 1rem;
    border: 1px solid var(--border);
    border-radius: .7rem;
    background: #22262d;
}

.level:hover .level-face { border-color: #818894; }
.level:has(:checked) .level-face {
    border-color: var(--accent);
    background: #322821;
    box-shadow: inset 0 0 0 1px var(--accent);
}
.level-number { font-size: 2.75rem; line-height: 1; font-weight: 900; font-style: italic; }
.swatches { display: flex; gap: .3rem; }
.swatch { width: .55rem; height: .55rem; border-radius: 50%; background: #abb0b8; }
.swatch.vert { background: var(--green); }
.swatch.jaune { background: var(--yellow); }
.swatch.rouge { background: var(--red); }

.helmet-selection legend {
    margin-bottom: .6rem;
    padding: 0;
    font-weight: 750;
}

.helmet-options {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: .5rem;
}

.helmet-option { cursor: pointer; position: relative; }

.helmet-option-face {
    display: grid;
    justify-items: center;
    height: 100%;
    padding: .2rem .1rem .45rem;
    border: 1px solid var(--border);
    border-radius: .55rem;
    background: #22262d;
    color: var(--muted);
    font-size: .85rem;
}

.helmet-option-face img {
    display: block;
    width: min(100%, 4.5rem);
    height: auto;
    opacity: .65;
}

.helmet-option:hover .helmet-option-face { border-color: #818894; }
.helmet-option:has(:checked) .helmet-option-face {
    border-color: var(--accent);
    background: #322821;
    box-shadow: inset 0 0 0 1px var(--accent);
    color: var(--text);
}
.helmet-option:has(:checked) img { opacity: 1; }

.button {
    display: inline-flex;
    gap: .55rem;
    align-items: center;
    justify-content: center;
    min-height: 2.9rem;
    padding: .6rem .95rem;
    border: 1px solid transparent;
    border-radius: .55rem;
    font-weight: 750;
    text-align: center;
}

.primary { background: var(--accent); color: #24160e; }
.primary:hover { background: #ffae80; }
.secondary { background: #242830; border-color: #464d59; color: var(--text); }
.secondary:hover { border-color: #9ca6b3; }
.button:disabled { opacity: .45; }
.setup-actions { display: flex; flex-wrap: wrap; gap: .55rem; }

.manoeuvre-options { display: grid; gap: .55rem; }

.manoeuvre-option {
    display: flex;
    align-items: start;
    gap: .55rem;
    width: fit-content;
    cursor: pointer;
}

.manoeuvre-option input { margin: .3em 0 0; accent-color: var(--accent); }

.rival-selection legend { padding: 0; font-weight: 750; }
.rival-selection p { margin: .25rem 0 .55rem; color: var(--muted); font-size: .85rem; }
.rival-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.rival-options select {
    width: 100%;
    min-height: 2.6rem;
    padding: .35rem .45rem;
    border: 1px solid #464d59;
    border-radius: .45rem;
    background: #242830;
    color: var(--text);
}
.rival-selection #rival-error { margin-bottom: 0; color: var(--accent); }

#race {
    max-width: 50rem;
    margin: clamp(.75rem, 2vh, 1.25rem) auto 0;
}

.race-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

#race-view {
    padding-inline: .65rem;
    text-align: start;
    cursor: pointer;
}

.race-card {
    --pack: #bac4ce;
    padding: clamp(.5rem, 1.65vw, .85rem);
    border: 1px solid #5a626d;
    border-radius: 1rem;
    background: linear-gradient(145deg, #404753, #292f38 75%);
    box-shadow: 0 1rem 2rem #0c0e124f;
}

.race-card[data-pack="vert"] { --pack: var(--green); }
.race-card[data-pack="jaune"] { --pack: var(--yellow); }
.race-card[data-pack="rouge"] { --pack: var(--red); }

.manoeuvre-card {
    width: min(100%, 28rem);
    margin: .85rem auto 0;
    border: 1px solid var(--border);
    border-radius: .85rem;
    overflow: hidden;
    background: #191d23;
}

.manoeuvre-effects {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.manoeuvre-side {
    position: relative;
    display: grid;
    justify-items: center;
    padding-inline: clamp(.55rem, 2.5vw, 1rem);
}

#star-manoeuvre {
    grid-template-rows: auto clamp(1.6rem, 5vw, 2.1rem);
    gap: .2rem;
    padding-block: .9rem .55rem;
    background: #fff;
    color: #575e66;
}

#rival-manoeuvre {
    align-items: center;
    padding-block: .55rem;
    background: #e2cfad;
    color: #655035;
}

.manoeuvre-side.inactive { filter: grayscale(1); opacity: .52; }

.manoeuvre-marker {
    position: absolute;
    top: .4rem;
    left: .5rem;
    font-size: .9rem;
    line-height: 1;
}

.manoeuvre-icon {
    display: block;
    width: min(100%, 10rem);
    height: clamp(3.5rem, 15vw, 5rem);
    object-fit: contain;
}

.manoeuvre-fallback {
    display: block;
    width: auto;
    height: 100%;
}

.card-grid {
    display: grid;
    gap: clamp(2px, .75vw, 7px);
}

.diamond-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: .2rem clamp(2px, .5vw, 5px) clamp(2px, .5vw, 5px);
    border-top: 2px solid var(--pack);
    border-radius: .45rem;
    background: #191d23;
}

.diamond-badge {
    display: grid;
    place-items: center;
    width: clamp(2rem, 7vw, 4.1rem);
    aspect-ratio: 1;
    position: relative;
    margin: .12rem auto .2rem;
}

.diamond-badge img, .helmet img { display: block; width: 100%; height: auto; }
.diamond-badge span {
    position: absolute;
    color: #1b1007;
    font-size: clamp(1.05rem, 3.3vw, 1.95rem);
    font-weight: 900;
    line-height: 1;
}

.helmet-grid {
    flex: 1;
    display: grid;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
    grid-auto-flow: column;
    gap: clamp(2px, .5vw, 5px);
}

.helmet-grid:has(> :only-child) { grid-template-rows: minmax(0, 1fr); }

.helmet-cell {
    display: grid;
    place-items: center;
    gap: .05rem;
    position: relative;
    padding: clamp(.25rem, .9vw, .5rem) .1rem .25rem;
    min-width: 0;
    border-radius: .32rem;
    border-bottom: 2px solid #0003;
    background: var(--helmet-accent);
    background-clip: padding-box;
}

.helmet {
    position: relative;
    width: min(100%, 6.4rem);
}

.helmet .speed {
    position: absolute;
    top: 52%;
    left: 60%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: clamp(1.2rem, 3.96vw, 2.52rem);
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.045em;
    line-height: 1;
    text-shadow: 0 0 2px #000, 0 0 3px #000, 0 2px 4px #000;
}

.star {
    position: absolute;
    z-index: 1;
    top: .07rem;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: clamp(.95rem, 2.65vw, 1.55rem);
    line-height: 1;
    text-shadow: 0 1px 2px black, 0 0 3px black;
}

.rival-badge {
    position: absolute;
    z-index: 1;
    top: .18rem;
    right: .18rem;
    min-width: 1.05rem;
    padding: 0 .16rem;
    border-radius: .2rem;
    background: #24160e;
    color: #ffbe97;
    font-size: .7rem;
    font-weight: 900;
    text-align: center;
}

.tablet {
    display: grid;
    grid-template-columns: clamp(3.4rem, 12vw, 6.25rem) minmax(0, 1fr);
    gap: clamp(.45rem, 1.5vw, .85rem);
    align-items: start;
}

.tablet-helmets {
    display: grid;
    gap: .35rem;
    max-height: clamp(16rem, 62vh, 35rem);
    overflow-y: auto;
    padding: .25rem;
    scrollbar-width: thin;
}

.tablet-helmets button {
    display: grid;
    place-items: center;
    width: 100%;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: .55rem;
    background: #22262d;
}

.tablet-helmets button:hover { border-color: #9ca6b3; }
.tablet-helmets button:focus-visible { outline-offset: 0; }
.tablet-helmets button[aria-pressed="true"] {
    background: var(--helmet-accent);
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.tablet-helmets img {
    display: block;
    width: min(100%, 4.5rem);
    height: auto;
}

.tablet-panel {
    padding: clamp(.65rem, 2.6vw, 1.5rem);
    border: 1px solid #5a626d;
    border-radius: 1rem;
    background: linear-gradient(145deg, #404753, #292f38 75%);
    box-shadow: 0 1rem 2rem #0c0e124f;
}

.tablet-panel h2 {
    margin: 0 0 .65rem;
    font-size: clamp(1.35rem, 4vw, 2.2rem);
    font-style: italic;
    line-height: 1.1;
}

.tablet-values, .tablet-effects {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(.35rem, 1.5vw, .75rem);
}

.tablet-value {
    display: grid;
    grid-template-rows: 1fr auto;
    place-items: center;
    gap: .3rem;
    padding: .45rem .2rem;
    border-radius: .55rem;
    background: #191d23;
    font-size: clamp(.75rem, 2.5vw, 1rem);
    font-weight: 750;
    text-align: center;
}

.tablet-value .helmet {
    width: min(100%, 8rem);
    border-radius: .45rem;
    background: var(--helmet-accent);
}

.tablet-value .speed { font-size: clamp(1.55rem, 6vw, 3rem); }
.tablet-value .diamond-badge { width: min(75%, 5.5rem); margin: 0; }
.tablet-value .diamond-badge span { font-size: clamp(1.4rem, 5.5vw, 2.6rem); }

.tablet-effects:not(:empty) { margin-top: clamp(.35rem, 1.5vw, .75rem); }
.tablet-effect:only-child { grid-column: 1 / -1; }

.tablet-effect {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: .3rem;
    padding: .45rem;
    border-radius: .55rem;
    background: #fff;
    color: #272b33;
    text-align: center;
    font-size: clamp(.75rem, 2.5vw, .95rem);
    font-weight: 750;
}

.tablet-effect-marker {
    justify-self: start;
    min-width: 1.3rem;
    padding-inline: .2rem;
    border-radius: .25rem;
    background: #242830;
    color: #fff;
}

.tablet-effect-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .25rem;
}

.tablet-effect-icon, .tablet-fallback {
    min-width: 0;
    max-width: 100%;
    height: clamp(2rem, 9vw, 4.5rem);
    object-fit: contain;
}

.tablet-fallback { width: auto; height: clamp(1.2rem, 5vw, 2.2rem); }

.race-actions {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .5rem;
    margin-top: 1rem;
}

#previous {
    justify-self: start;
    min-width: 2.9rem;
    font-size: 1.2rem;
}

#next { justify-self: end; }
#reset-race {
    display: flex;
    width: fit-content;
    margin: .75rem auto 0;
    font-size: .88rem;
}

.race-details {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: .4rem;
    margin-top: .35rem;
    color: var(--muted);
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
}

#change-level {
    min-height: 2.75rem;
    padding: .25rem;
    border: 0;
    border-radius: .2rem;
    background: transparent;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: .15em;
}

#change-level:hover { color: var(--text); }

#draw-status {
    color: var(--muted);
    font-size: .88rem;
    font-variant-numeric: tabular-nums;
    font-weight: 750;
    margin: 0;
    white-space: nowrap;
}

@media (max-width: 35rem) {
    #next { padding-inline: .6rem; font-size: .88rem; }
}

@media (max-width: 28rem) {
    .shell { width: calc(100% - 1.25rem); }
    .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
    .level-face { min-height: 4.75rem; }
    .helmet-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .race-controls .button { padding-inline: .45rem; font-size: .85rem; }
}
