/*
 * Femkamp: Material 3 in hand-written CSS, like the dflag.se front page and Hästskospelet (Nunito, tinted surfaces
 * instead of outlines, rounded shapes, light and dark after the device), mobile first: it is used on a phone, outdoors,
 * so the targets are large. The tones: syren (default, the lilac), apelsin and mynta, the two last with ?ton=apelsin
 * or ?ton=mynta. Every text colour pair is at least 4.5:1 (tools/test_site.py checks it).
 */

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

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

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

:root {
    color-scheme: light dark;
    --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --max: 960px;
    --gutter: max(16px, env(safe-area-inset-left));
    --gutter-r: max(16px, env(safe-area-inset-right));
    --scrim: rgb(0 0 0 / 0.45);
}

/* tone: syren (light) */
:root,
:root[data-tone="syren"] {
    --primary: #804698;
    --on-primary: #ffffff;
    --container: #f5d9ff;
    --on-container: #310048;
    --bg: #fdf8fe;
    --surface: #f4eff6;
    --surface-high: #e9e4ea;
    --text: #1e1a1f;
    --text-2: #4c444f;
    --outline: #7d7480;
    --accent: #fedadb;
    --on-accent: #40000e;
    --inverse: #332f34;
    --on-inverse: #f4eff6;
}

:root[data-tone="apelsin"] {
    --primary: #934b01;
    --on-primary: #ffffff;
    --container: #ffdcc4;
    --on-container: #2b1700;
    --bg: #fef8f4;
    --surface: #f7efea;
    --surface-high: #ece4df;
    --text: #201a17;
    --text-2: #51443c;
    --outline: #82746b;
    --accent: #e3e7a1;
    --on-accent: #1c1d01;
    --inverse: #352f2b;
    --on-inverse: #f7efea;
}

:root[data-tone="mynta"] {
    --primary: #016b5d;
    --on-primary: #ffffff;
    --container: #89f5e1;
    --on-container: #00201b;
    --bg: #f1fcf9;
    --surface: #e8f3f0;
    --surface-high: #dde8e5;
    --text: #151d1b;
    --text-2: #384a46;
    --outline: #687b77;
    --accent: #bfe9ff;
    --on-accent: #011f2a;
    --inverse: #2a3230;
    --on-inverse: #e8f3f0;
}

@media (prefers-color-scheme: dark) {
    :root {
        --scrim: rgb(0 0 0 / 0.6);
    }

    :root,
    :root[data-tone="syren"] {
        --primary: #eab2ff;
        --on-primary: #4c1564;
        --container: #652e7d;
        --on-container: #f5d9ff;
        --bg: #161217;
        --surface: #221e23;
        --surface-high: #2d292e;
        --text: #e6e1e7;
        --text-2: #cdc3d0;
        --outline: #978e9a;
        --accent: #792d37;
        --on-accent: #fedadb;
        --inverse: #e6e1e7;
        --on-inverse: #332f34;
    }

    :root[data-tone="apelsin"] {
        --primary: #ffb780;
        --on-primary: #4d2600;
        --container: #703800;
        --on-container: #ffdcc4;
        --bg: #18120d;
        --surface: #241e1b;
        --surface-high: #2f2925;
        --text: #e9e1dc;
        --text-2: #d3c4b9;
        --outline: #9c8e84;
        --accent: #434b0c;
        --on-accent: #e3e7a1;
        --inverse: #e9e1dc;
        --on-inverse: #352f2b;
    }

    :root[data-tone="mynta"] {
        --primary: #6cd9c5;
        --on-primary: #003730;
        --container: #025046;
        --on-container: #89f5e1;
        --bg: #0b1513;
        --surface: #19211f;
        --surface-high: #232c2a;
        --text: #dae5e2;
        --text-2: #b6cbc6;
        --outline: #819590;
        --accent: #054d64;
        --on-accent: #bfe9ff;
        --inverse: #dae5e2;
        --on-inverse: #2a3230;
    }
}

/* ------------------------------------------------------------------------------------------------------------- */

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

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 400 16px/1.5 var(--font);
    -webkit-tap-highlight-color: transparent;
}

h1,
h2 {
    margin: 0;
    line-height: 1.2;
    font-weight: 800;
}

p {
    margin: 0;
}

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

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

/* a dialog's heading takes the focus when it opens (so no button looks pressed): no ring on it */
[tabindex="-1"]:focus {
    outline: none;
}

.icon {
    width: 24px;
    height: 24px;
    flex: none;
    fill: currentColor;
}

/* the top bar ------------------------------------------------------------------------------------------------ */

.app-bar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 64px;
    padding: env(safe-area-inset-top) var(--gutter-r) 0 var(--gutter);
    background: var(--bg);
    border-bottom: 1px solid color-mix(in srgb, var(--outline) 22%, transparent);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding-left: 4px;
    font-size: 20px;
    font-weight: 800;
}

.brand__mark {
    width: 28px;
    height: 28px;
    fill: var(--primary);
}

.grow {
    flex: 1;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.icon-btn:hover {
    background: color-mix(in srgb, var(--text) 8%, transparent);
}

.icon-btn:active {
    background: color-mix(in srgb, var(--text) 12%, transparent);
}

/* buttons ------------------------------------------------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 24px;
    border: 0;
    border-radius: 24px;
    font-weight: 700;
    font-size: 16px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, box-shadow 0.15s;
}

.btn .icon {
    width: 20px;
    height: 20px;
    margin-left: -6px;
}

.btn.filled {
    background: var(--primary);
    color: var(--on-primary);
}

.btn.filled:hover {
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
    background: color-mix(in srgb, var(--primary) 92%, var(--on-primary));
}

.btn.tonal {
    background: var(--container);
    color: var(--on-container);
}

.btn.text {
    background: transparent;
    color: var(--primary);
    padding: 0 14px;
}

.btn.text:hover {
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.btn.text.inline {
    min-height: 40px;
    margin: -8px 0 -8px -6px;
    padding: 0 10px;
}

.btn.big {
    min-height: 64px;
    border-radius: 20px;
    padding: 0 28px;
    font-size: 18px;
}

.btn:disabled {
    cursor: default;
    box-shadow: none;
    background: color-mix(in srgb, var(--text) 12%, transparent);
    color: color-mix(in srgb, var(--text) 50%, transparent);
}

.btn.text:disabled {
    background: transparent;
}

/* layout --------------------------------------------------------------------------------------------------------- */

main {
    max-width: var(--max);
    margin: 0 auto;
    padding: 16px var(--gutter-r) calc(32px + env(safe-area-inset-bottom)) var(--gutter);
}

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

.view__title {
    font-size: 28px;
    overflow-wrap: anywhere;
}

.overline {
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.02em;
}

.hint {
    color: var(--text-2);
    font-size: 15px;
}

.caption {
    color: var(--text-2);
    font-size: 14px;
}

.card {
    background: var(--surface);
    border-radius: 24px;
    padding: 20px;
}

.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: -6px -8px 8px 0;
}

.card h2 {
    font-size: 20px;
}

/* start ------------------------------------------------------------------------------------------------------------ */

.hero {
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 32px 20px 28px;
    border-radius: 28px;
    background: var(--container);
    color: var(--on-container);
    text-align: center;
}

.hero__mark {
    width: 104px;
    height: 104px;
    fill: var(--primary);
}

.hero h1 {
    font-size: 34px;
}

.hero__text {
    max-width: 30ch;
    font-size: 17px;
}

.hero__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 8px;
}

.resume {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--accent);
    color: var(--on-accent);
}

.resume__text {
    display: grid;
    min-width: 0;
    overflow-wrap: anywhere;
}

.resume__text strong {
    font-size: 18px;
}

.rules__list {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rules__list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
}

.rules__list span {
    color: var(--text-2);
    font-weight: 700;
}

/* events and players ------------------------------------------------------------------------------------------- */

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    max-width: 100%;
    padding: 0 20px;
    border: 1px solid var(--outline);
    border-radius: 14px;
    background: transparent;
    font-weight: 700;
    font-size: 17px;
    text-align: left;
    cursor: pointer;
}

.chip span {
    overflow-wrap: anywhere;
}

.chip .icon {
    display: none;
    width: 20px;
    height: 20px;
    margin-left: -6px;
}

.chip[aria-pressed="true"] {
    border-color: transparent;
    background: var(--container);
    color: var(--on-container);
}

.chip[aria-pressed="true"] .icon,
.chip--add .icon {
    display: block;
}

.chip--add {
    border-style: dashed;
    color: var(--primary);
}

/* the order an event is played in */
.chip__order {
    display: inline-grid;
    place-items: center;
    flex: none;
    min-width: 28px;
    height: 28px;
    margin-left: -8px;
    padding: 0 6px;
    border-radius: 14px;
    background: var(--primary);
    color: var(--on-primary);
    font-size: 15px;
    font-weight: 800;
}

.bottom-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px calc(-1 * var(--gutter-r)) calc(-32px - env(safe-area-inset-bottom)) calc(-1 * var(--gutter));
    padding: 12px var(--gutter-r) calc(12px + env(safe-area-inset-bottom)) var(--gutter);
    background: var(--surface);
    border-top: 1px solid color-mix(in srgb, var(--outline) 22%, transparent);
}

.picked {
    color: var(--text-2);
    font-weight: 700;
}

/* the board ------------------------------------------------------------------------------------------------------- */

.board-head {
    display: grid;
    gap: 4px;
}

.board-head__desc {
    color: var(--text-2);
}

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

.board-actions .btn.big {
    flex: 1 1 260px;
    max-width: 100%;
}

.board-actions .btn.big span {
    overflow-wrap: anywhere;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 16px;
    background: var(--surface);
    -webkit-overflow-scrolling: touch;
}

table {
    min-width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th,
td {
    padding: 10px 14px;
    white-space: nowrap;
    text-align: left;
}

thead th {
    background: var(--surface-high);
    color: var(--text-2);
    font-size: 14px;
}

thead th.now {
    color: var(--primary);
}

.num {
    text-align: right;
}

tbody tr + tr > * {
    border-top: 1px solid color-mix(in srgb, var(--outline) 22%, transparent);
}

th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
}

thead th:first-child {
    background: var(--surface-high);
}

/* a team's row stands out; its players follow, indented */
.row--team > * {
    background: var(--container);
    color: var(--on-container);
    font-weight: 800;
}

.row--team > th:first-child {
    background: var(--container);
}

.row--player > th {
    padding-left: 26px;
    font-weight: 700;
}

.row--player > td {
    color: var(--text-2);
}

/* one player per team: no team rows, so nothing to indent under */
.solo .row--player > th {
    padding-left: 14px;
}

td.total {
    font-weight: 800;
}

/* dialogs ---------------------------------------------------------------------------------------------------------- */

dialog.dlg {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    padding: 0;
    border: 0;
    border-radius: 28px;
    background: var(--surface-high);
    color: var(--text);
}

dialog.dlg[open] {
    display: flex;
    flex-direction: column;
}

dialog.dlg::backdrop {
    background: var(--scrim);
}

.dlg__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px 8px 12px;
}

.dlg__head h2 {
    font-size: 22px;
    overflow-wrap: anywhere;
}

.dlg__body {
    display: grid;
    align-content: start;
    gap: 14px;
    padding: 20px 24px 12px;
    overflow-y: auto;
}

.dlg__head + .dlg__body {
    padding-top: 4px;
}

.dlg__body > h2 {
    font-size: 24px;
}

.dlg__foot {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
}

@media (max-width: 599px) {
    dialog.dlg--full {
        width: 100vw;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border-radius: 0;
        background: var(--bg);
    }

    dialog.dlg--full .dlg__head {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    dialog.dlg--full .dlg__body {
        flex: 1;
    }

    dialog.dlg--full .dlg__foot {
        border-top: 1px solid color-mix(in srgb, var(--outline) 22%, transparent);
    }
}

@media (min-width: 600px) {
    dialog.dlg--full {
        min-height: min(640px, calc(100dvh - 48px));
    }

    dialog.dlg--full .dlg__body {
        flex: 1;
    }
}

.prompt {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* one player's points: a large field, as on the old page */
.points-input {
    width: 100%;
    min-height: 88px;
    padding: 8px 20px;
    border: 2px solid var(--outline);
    border-radius: 20px;
    background: var(--bg);
    color: var(--primary);
    font-size: 56px;
    font-weight: 800;
    line-height: 1;
    text-align: right;
    font-variant-numeric: tabular-nums;
    appearance: textfield;
    -moz-appearance: textfield;
}

.points-input::-webkit-inner-spin-button,
.points-input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.points-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: inset 0 0 0 2px var(--primary);
}

/* the points entered so far, team by team; tap a player to go back to them */
.entries {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.entries__team {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px 0 4px;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 800;
}

.entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 52px;
    padding: 8px 16px;
    border: 0;
    border-radius: 16px;
    background: var(--surface);
    text-align: left;
    cursor: pointer;
}

.dlg--full .entry {
    background: var(--surface);
}

.entry--now {
    background: var(--container);
    color: var(--on-container);
}

.dlg--full .entry--now {
    background: var(--container);
}

.entry__name {
    font-size: 17px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.entries__points {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

/* fields and settings */
.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: var(--text-2);
    font-size: 14px;
    font-weight: 700;
}

.field input,
.setting select {
    width: 100%;
    min-height: 52px;
    padding: 12px 16px;
    border: 1px solid var(--outline);
    border-radius: 12px;
    background: var(--bg);
    font-size: 17px;
}

.field input:focus,
.setting select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.settings {
    display: grid;
}

.setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 60px;
}

.setting span {
    font-weight: 700;
}

.setting select {
    width: auto;
    min-width: 88px;
}

.error {
    color: #ba1a1a;
    font-weight: 700;
}

.error:empty {
    display: none;
}

@media (prefers-color-scheme: dark) {
    .error {
        color: #ffb4ab;
    }
}

/* the snackbar */
.snackbar {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    z-index: 20;
    width: max-content;
    max-width: min(560px, calc(100vw - 32px));
    padding: 14px 20px;
    border-radius: 8px;
    background: var(--inverse);
    color: var(--on-inverse);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.25);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 16px);
    transition: opacity 0.2s, transform 0.2s;
}

.snackbar.on {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (min-width: 720px) {
    main {
        padding-top: 32px;
    }

    .hero {
        padding: 48px 32px 40px;
    }

    .hero__mark {
        width: 128px;
        height: 128px;
    }

    .hero h1 {
        font-size: 44px;
    }

    .view__title {
        font-size: 34px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
    }
}
