html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Roboto", sans-serif;
    background: linear-gradient(
        145deg,
        color-mix(in srgb, var(--mud-palette-background) 92%, var(--mud-palette-primary) 8%) 0%,
        var(--mud-palette-background) 100%);
    color: var(--mud-palette-text-primary);
}

.welcome-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

.app-content {
    min-height: 100vh;
    padding-top: 72px;
}

/* Sidebar navigation icons only; top and bottom navigation remain unchanged. */
.mobile-drawer .mud-navmenu .mud-nav-link-icon {
    color: var(--mud-palette-primary) !important;
}

.mobile-drawer .mud-navmenu .mud-nav-link.active:not(.mud-nav-link-disabled) {
    color: var(--mud-palette-primary) !important;
    font-weight: 700 !important;
}

/* On mobile add bottom padding so content is not hidden under bottom nav */
@media (max-width: 959.98px) {
    .app-content {
        padding-top: 64px;
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

/* Landscape phone: keep bottom nav compact */
@media (max-height: 500px) and (orientation: landscape) {
    .app-content {
        padding-bottom: calc(52px + env(safe-area-inset-bottom));
    }
}

.home-container, .auth-container {
    min-height: calc(100vh - 64px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

.page-container {
    padding-top: 3rem;
    padding-bottom: 3rem;
}

.hero-card {
    overflow: hidden;
    padding: clamp(2rem, 6vw, 5rem);
    width: 100%;
}

.hero-title {
    font-weight: 700;
    max-width: 700px;
}

.bowling-mark {
    align-items: center;
    aspect-ratio: 1;
    background: linear-gradient(145deg, #1769bd, #2685e4);
    border-radius: 50%;
    color: white;
    display: inline-flex;
    justify-content: center;
    max-width: 260px;
    width: 80%;
}

.bowling-mark .mud-icon-root {
    font-size: 8rem;
}

.auth-card {
    width: 100%;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.auth-input {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 6px;
    color: var(--mud-palette-text-primary);
    font: inherit;
    margin-bottom: 0.75rem;
    padding: 0.9rem 1rem;
}

.auth-input:focus {
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--mud-palette-primary) 20%, transparent);
    outline: none;
}

.remember-me {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* ── Training page utilities ───────────────────────────── */
.page-section {
    padding: clamp(0.75rem, 3vw, 1.5rem);
    padding-bottom: 1rem;
}

.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, transparent);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ── Touch-friendly roll buttons ───────────────────────── */
.roll-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    font-size: 1rem !important;
    font-weight: 700 !important;
    border-radius: 8px !important;
}

.roll-btn-strike {
    background-color: var(--mud-palette-primary-darken) !important;
    color: var(--mud-palette-primary-text) !important;
}

.roll-btn-spare {
    background-color: var(--mud-palette-primary) !important;
    color: var(--mud-palette-primary-text) !important;
}

/* ── Frame scorecard ────────────────────────────────────── */
.scorecard-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.training-expand-column {
    width: 3rem;
}

.history-card-table .mud-table-root {
    table-layout: fixed;
}

.history-card-table .mud-table-body > .mud-table-row > .history-card-cell {
    padding: 2px 2px 0.75rem;
    border-bottom: none;
}

.app-theme-dark .history-session-card,
.app-theme-dark .session-list-item {
    border: 1px solid color-mix(in srgb, var(--mud-palette-primary) 38%, var(--mud-palette-lines-default));
    box-shadow: 0 2px 5px color-mix(in srgb, var(--mud-palette-primary) 20%, transparent) !important;
}

.app-theme-dark .history-average,
.app-theme-dark .session-average {
    color: var(--mud-palette-text-primary) !important;
}

.training-detail-row > td {
    background: color-mix(in srgb, var(--mud-palette-primary) 5%, transparent);
    padding: 1rem !important;
}

.training-detail-list {
    display: grid;
    gap: 0.75rem;
}

.training-game-card {
    border: 1px solid var(--mud-palette-lines-default);
    min-width: 0;
}

.history-session-card:has(.history-open-button[aria-expanded="true"]),
.session-list-item:has(.session-open-button[aria-expanded="true"]) {
    background-color: color-mix(in srgb, var(--mud-palette-primary) 12%, var(--mud-palette-surface));
}

@media (max-width: 600px) {
    .training-expand-column {
        width: auto;
    }

    .training-detail-row > td {
        display: block !important;
        width: 100% !important;
        padding: 0.75rem !important;
        text-align: left !important;
    }

    .training-detail-row > td::before {
        display: none !important;
        content: none !important;
    }

    .training-detail-list,
    .training-game-card {
        width: 100%;
    }

    /* Keep all ten frames in one row while allowing the three tenth-frame
       roll boxes to shrink into the available phone width. */
    .training-game-card .scorecard {
        min-width: 0;
        width: 100%;
    }

    .training-game-card .scorecard-frame {
        min-width: 0;
    }

    .training-game-card .sc-roll-box {
        min-width: 0;
        padding-inline: 1px;
    }
}

.dashboard-card,
.stat-surface,
.empty-state {
    background: color-mix(in srgb, var(--mud-palette-surface) 92%, transparent);
    backdrop-filter: blur(8px);
}

.record-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.record-line:last-child {
    border-bottom: none;
}

.stats-grid-compact {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.comparison-delta {
    color: var(--mud-palette-text-secondary);
    font-size: 0.75rem;
    margin-top: 0.2rem;
}

.scorecard {
    display: flex;
    min-width: 320px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
    overflow: hidden;
}

.scorecard-frame {
    flex: 1;
    border-right: 1px solid var(--mud-palette-lines-default);
    display: flex;
    flex-direction: column;
}

.scorecard-frame:last-child {
    border-right: none;
    flex: 1.5;
}

.sc-frame-num {
    font-size: 0.55rem;
    text-align: center;
    color: var(--mud-palette-text-secondary);
    padding: 1px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.sc-rolls {
    display: flex;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    min-height: 26px;
}

.sc-roll-box {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    border-right: 1px solid var(--mud-palette-lines-default);
    min-width: 12px;
    padding: 0 2px;
}

.sc-roll-box:last-child {
    border-right: none;
}

.sc-roll-strike {
    color: var(--mud-palette-primary-darken);
}

.sc-roll-spare {
    color: var(--mud-palette-primary);
}

.sc-roll-foul {
    color: var(--mud-palette-error);
}

.sc-roll-split {
    width: 1.25rem;
    height: 1.25rem;
    border: 1.5px solid currentColor;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.sc-score {
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    padding: 3px 0;
    min-height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sc-frame-active {
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, transparent);
}

/* Motion is opt-in through the OS preference. Content stays visible without it. */
@media (prefers-reduced-motion: no-preference) {
    /* Start only once the saved theme is visible, including on touch devices. */
    html:not([data-theme-pending]) .brand-link .bowling-brand-mark {
        animation: app-bowling-mark-spin 12s linear infinite;
    }

    .page-container > *,
    .auth-card {
        animation: app-content-enter 280ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
    }

    .page-container > :nth-child(2) {
        animation-delay: 35ms;
    }

    .page-container > :nth-child(n + 3) {
        animation-delay: 70ms;
    }

    /* Animate individual games on insertion; cap the stagger even for long sessions. */
    .training-detail-list > .training-game-card {
        animation: app-game-enter 260ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
    }

    .training-detail-list > .training-game-card:nth-child(2) {
        animation-delay: 30ms;
    }

    .training-detail-list > .training-game-card:nth-child(3) {
        animation-delay: 60ms;
    }

    .training-detail-list > .training-game-card:nth-child(n + 4) {
        animation-delay: 90ms;
    }

    .history-session-card,
    .session-list-item {
        transition: background-color 180ms ease;
    }

    /* Individual scale preserves existing button transforms and layout offsets. */
    .mud-button:not(:disabled):not([aria-disabled="true"]) {
        transition: background-color 160ms ease, box-shadow 160ms ease,
                    color 160ms ease, scale 120ms ease;
    }

    .mud-button:not(:disabled):not([aria-disabled="true"]):active {
        scale: 0.97;
    }

    .auth-input {
        transition: border-color 160ms ease, box-shadow 160ms ease;
    }

    .scorecard-frame {
        transition: background-color 180ms ease;
    }

    .history-open-button .mud-icon-root,
    .session-open-button .mud-icon-root {
        transition: transform 180ms ease;
    }

    .history-open-button[aria-expanded="true"] .mud-icon-root,
    .session-open-button[aria-expanded="true"] .mud-icon-root {
        transform: rotate(90deg);
    }
}

@keyframes app-content-enter {
    from {
        opacity: 0.35;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes app-game-enter {
    from {
        opacity: 0.25;
        transform: translateX(-12px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes app-bowling-mark-spin {
    from {
        rotate: 0deg;
    }

    to {
        rotate: 360deg;
    }
}

/* Keep the expanded state legible even when motion is disabled. */
@media (prefers-reduced-motion: reduce) {
    .history-open-button[aria-expanded="true"] .mud-icon-root,
    .session-open-button[aria-expanded="true"] .mud-icon-root {
        transform: rotate(90deg);
    }
}
