/* Skirun - the slope page. The kit has no board here: a canvas stage with a heads-up display,
   cards for the menu / pause / result over it, and the leaderboard + help beside it.
   Sizes only from the kit scale (12 / 14 / 16 / 20 / 28 px). The snow stays light in dark mode. */

.ski { max-width: 1180px; margin: 0 auto; padding: 16px var(--gutter) 24px; display: grid; gap: 16px; }
.ski__stage {
    position: relative;
    height: clamp(420px, calc(100svh - var(--header-h) - 40px), 760px);
    overflow: hidden;
    border-radius: 18px;
    background: #f5f8fc;
    box-shadow: inset 0 0 0 1px var(--line), var(--shadow-1);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
.ski__stage[aria-busy="true"] { background: linear-gradient(110deg, #e9eef5 35%, #f5f8fc 50%, #e9eef5 65%) 0 0 / 300% 100%; animation: skeleton 1.4s ease-in-out infinite; }
.ski__canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.ski[data-phase="play"] .ski__stage { cursor: crosshair; }

/* heads-up display */
.ski__hud { position: absolute; left: 10px; top: 10px; right: 64px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.hud-chip { display: inline-flex; flex-direction: column; min-width: 64px; padding: 4px 10px; border-radius: 10px; background: rgb(255 255 255 / .86); color: #1f1a15; box-shadow: 0 1px 2px rgb(30 44 66 / .14); line-height: 1.25; }
.hud-chip__label { font-size: var(--fs-xs); color: #5b5046; white-space: nowrap; }
.hud-chip strong { font-size: var(--fs-m); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-chip--alert strong { color: #9b3226; }
.hud-chip[data-hud="chase"] { justify-content: center; border: 1px solid #9b3226; animation: pulse 1s ease-in-out infinite; }
.ski:not([data-mode="slalom"]) [data-for="slalom"] { display: none; }
.ski[data-mode="slalom"] [data-for="style endless"] { display: none; }
.ski__pause { position: absolute; right: 10px; top: 10px; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgb(255 255 255 / .9); color: #1f1a15; box-shadow: 0 1px 3px rgb(30 44 66 / .2); cursor: pointer; }
.ski__pause:hover { background: #fff; }

/* cards over the slope */
.ski__panel { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 16px; overflow-y: auto; overscroll-behavior: contain; background: rgb(236 242 249 / .6); touch-action: pan-y; }
/* a frame that cannot save scores: the note with its "open in a new tab" button (menu and result) */
.framed-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid var(--gold); border-radius: 10px; background: var(--surface-2); font-size: var(--fs-xs); color: var(--ink-2); }
.framed-note span { flex: 1 1 160px; }
/* a short note in the HUD during the run (instead of a toast over the slope) */
.hud-chip--note { flex-basis: 100%; max-width: 320px; justify-content: center; }
.hud-chip--note strong { font-size: var(--fs-s); white-space: normal; line-height: 1.3; }
.panel-card { width: min(460px, 100%); max-height: 100%; overflow-y: auto; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); }
.panel-card--small { width: min(340px, 100%); text-align: center; }
.panel-card__title { margin-bottom: 14px; font-size: var(--fs-l); }
.panel-card__wait { margin: 0; color: var(--ink-2); }
.panel-card__wait::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border-radius: 50%; background: var(--gold); vertical-align: middle; animation: pulse 1s ease-in-out infinite; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.panel-card--small .panel-actions { flex-direction: column; }
.panel-actions .btn { flex: 1 1 auto; }
.btn--wide { width: 100%; margin-top: 4px; }

.modes { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; border: 0; }
.mode-card { position: relative; display: block; cursor: pointer; }
.mode-card input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.mode-card__body { display: grid; gap: 2px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); transition: border-color .15s, box-shadow .15s; }
.mode-card input:checked + .mode-card__body { border-color: var(--gold); background: var(--surface); box-shadow: 0 0 0 1px var(--gold), var(--shadow-1); }
.mode-card input:focus-visible + .mode-card__body { outline: 2px solid var(--gold); outline-offset: 2px; }
.mode-card__name { font-weight: 600; }
.mode-card__desc { font-size: var(--fs-s); color: var(--ink-2); line-height: 1.45; }
.mode-card__best { font-size: var(--fs-xs); color: var(--gold-ink); }
.mode-card__best:empty { display: none; }
.controls-hint { margin: 12px 0 0; font-size: var(--fs-xs); color: var(--ink-2); line-height: 1.5; }
.controls-hint--touch { display: none; }
@media (pointer: coarse) {
    .controls-hint--keys { display: none; }
    .controls-hint--touch { display: block; }
}

/* the result */
.end-badge { display: inline-block; margin: 0 0 6px; padding: 2px 12px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-s); font-weight: 600; }
.end-badge[data-reason="finish"] { background: rgb(201 165 90 / .22); color: var(--gold-ink); }
.end-badge[data-reason="caught"] { background: rgb(155 50 38 / .12); color: var(--accent); }
.end-score { margin: 0; font-family: var(--font-head); font-size: var(--fs-xl); font-weight: 600; line-height: 1.25; font-variant-numeric: tabular-nums; }
.end-best { display: inline-block; margin: 6px 0 0; padding: 2px 10px; border-radius: 999px; background: var(--primary-bg); color: var(--primary-ink); font-size: var(--fs-xs); font-weight: 600; }
.end-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 14px 0; }
.end-stats div { padding: 6px 10px; border-radius: 10px; background: var(--surface-2); }
.end-stats dt { font-size: var(--fs-xs); color: var(--ink-2); }
.end-stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.end-rank { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 1.6em; }
.end-rank p { margin: 0; font-weight: 600; }
.claim { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.claim__title { margin: 0 0 10px; font-weight: 600; }
.claim__fields { display: grid; gap: 0 10px; }
@media (min-width: 480px) { .claim__fields { grid-template-columns: 1fr 1fr; } }
.claim .input { margin-bottom: 8px; }
.claim .field__help { margin: 0 0 10px; }
.claim__error { margin: 0 0 10px; color: var(--accent); font-size: var(--fs-s); }
.claim .btn { width: 100%; }

/* leaderboards (end card, side card) */
.board-list { margin: 12px 0 0; padding: 0; list-style: none; }
.board-list[aria-busy="true"] { min-height: 140px; border-radius: 10px; background: linear-gradient(110deg, var(--surface-2) 35%, var(--surface) 50%, var(--surface-2) 65%) 0 0 / 300% 100%; animation: skeleton 1.4s ease-in-out infinite; }
.board-list__row { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 40px; padding: 4px 8px; border-bottom: 1px solid var(--line); font-size: var(--fs-s); }
.board-list__row:last-child { border-bottom: 0; }
.board-list__row.is-you { border-radius: 10px; background: rgb(201 165 90 / .2); }
.board-list__row--gap { position: relative; margin-top: 14px; }
.board-list__row--gap::before { content: "⋯"; position: absolute; left: 0; right: 0; top: -15px; color: var(--ink-3); text-align: center; line-height: 1; }
.board-list__rank { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }
.board-list__who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.board-list__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board-list__score { font-variant-numeric: tabular-nums; white-space: nowrap; }
.board-list__empty { padding: 12px 8px; color: var(--ink-2); font-size: var(--fs-s); }
.flag { flex: none; display: inline-block; min-width: 1.6em; font-size: var(--fs-xs); line-height: 1.4; text-align: center; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink-2); }
.flag--emoji { min-width: 0; border: 0; font-size: var(--fs-m); line-height: 1; }

/* beside the slope */
.ski__side { display: grid; gap: 16px; align-content: start; }
.side-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-1); }
.side-card__title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: var(--fs-l); }
.side-card__more { display: inline-flex; align-items: center; min-height: 44px; margin-top: 4px; font-size: var(--fs-s); }
.board-tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.board-tabs__tab { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 4px 6px; border: 0; border-radius: 9px; background: none; color: var(--ink-2); font-size: var(--fs-s); font-weight: 600; cursor: pointer; }
.board-tabs__tab[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--gold), var(--shadow-1); }
.help-list { margin: 0 0 8px; padding-left: 1.2em; font-size: var(--fs-s); color: var(--ink-2); }
.help-list li { margin-bottom: 6px; }

@media (min-width: 1024px) {
    .ski { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; padding-top: 24px; }
    .ski__side { position: sticky; top: calc(var(--header-h) + 24px); }
}

/* phones: the slope fills the screen under the header; leaderboard and help follow below */
@media (max-width: 639px) {
    .ski { padding: 0 0 16px; gap: 12px; }
    .ski__stage { height: calc(100svh - var(--header-h) - 52px); min-height: 420px; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
    .ski__side { padding: 0 var(--gutter); }
    .ski__hud { left: 8px; top: 8px; gap: 4px; }
    .hud-chip { min-width: 0; padding: 3px 8px; }
    .hud-chip--speed { display: none; }
    .ski__panel { padding: 12px; place-items: start center; }
    .panel-card { padding: 18px 16px; }
    /* the result has to fit with its name form: one compact row of figures */
    .end-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 10px 0; }
    .end-stats div { padding: 4px 6px; }
    .end-stats dt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .end-stats dd { font-size: var(--fs-s); }
    .end-best { margin-top: 4px; }
    .end-rank p { font-size: var(--fs-s); }
    .claim { margin-top: 10px; padding: 12px; }
    .claim__title { margin-bottom: 6px; }
    .panel-actions { margin-top: 12px; }
    /* the result card: badge, score, figures, rank and the buttons first; the name form and the
       board follow below them, so "play again" is never pushed out of the card by the form */
    #panel-end .panel-card { display: flex; flex-direction: column; }
    #panel-end .end-badge { order: 1; align-self: flex-start; }
    #panel-end .end-score { order: 2; }
    #panel-end .end-best { order: 3; align-self: flex-start; }
    #panel-end .end-stats { order: 4; }
    #panel-end .end-rank { order: 5; }
    #panel-end .panel-actions { order: 6; margin-top: 10px; }
    #panel-end .framed-note { order: 7; margin: 10px 0 0; }
    #panel-end .claim { order: 8; }
    #panel-end .board-list { order: 9; }
}

/* short screens (iPhone SE, phones in landscape): the slope may be lower than 420 px, and only the
   chosen mode keeps its description, so the start button is on screen without scrolling */
@media (max-height: 600px) {
    .ski__stage { min-height: 0; }
    .mode-card input:not(:checked) + .mode-card__body .mode-card__desc { display: none; }
    .panel-card__title { margin-bottom: 8px; }
    .modes { gap: 6px; margin-bottom: 10px; }
    .controls-hint { margin-top: 8px; }
}

/* phones in landscape: the slope is the whole screen under the header, the cards are compact */
@media (orientation: landscape) and (max-height: 500px) {
    .ski { padding: 0 0 12px; gap: 8px; }
    .ski__stage { height: calc(100svh - var(--header-h)); min-height: 0; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
    .ski__side { padding: 0 var(--gutter); }
    .ski__panel { padding: 8px; place-items: start center; }
    .panel-card { padding: 10px 14px; }
    .panel-card .eyebrow { display: none; }
    .panel-card__title { margin-bottom: 6px; font-size: var(--fs-m); }
    .modes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 8px; }
    .mode-card__body { min-height: 44px; padding: 8px; align-content: center; }
    .mode-card__desc { display: none; }
    .btn--wide { margin-top: 0; }
    .controls-hint { margin-top: 6px; }
    .hud-chip--speed { display: none; }
    .end-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 8px 0; }
}

/* the leaderboard page */
.scores { max-width: 900px; margin: 0 auto; padding: 32px var(--gutter) 24px; }
.scores__tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.scores__tabs a { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; min-width: 96px; min-height: 44px; padding: 4px 10px; border-radius: 9px; color: var(--ink-2); font-size: var(--fs-s); font-weight: 600; text-decoration: none; }
.scores__tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--gold), var(--shadow-1); }
.scores__filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
.scores__filter .input { margin: 0; flex: 1 1 220px; }
.scores__table .is-you td { background: rgb(201 165 90 / .16); }
.scores__table .rank { width: 3em; color: var(--ink-2); text-align: right; }
.scores__who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.scores__note { margin-top: 12px; font-size: var(--fs-xs); color: var(--ink-2); }
.scores__empty { padding: 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; color: var(--ink-2); }
