/* The element reset: Tailwind CSS v4.3.3's Preflight (MIT License, https://tailwindcss.com) with its theme
   variables resolved to their defaults, plus the dark colour scheme, the default text colour and the page
   background. It is in a cascade layer, so every unlayered rule in the app's stylesheets overrides it regardless
   of specificity. */
@layer reset {
    *, ::after, ::before, ::backdrop, ::file-selector-button {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        border: 0 solid;
    }

    html, :host {
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        tab-size: 4;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Noto Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
        font-feature-settings: normal;
        font-variation-settings: normal;
        -webkit-tap-highlight-color: transparent;
        color-scheme: dark;
        color: var(--text-primary, #f2efe6);
        /* An opaque background, so text drawn directly on the page keeps subpixel antialiasing on desktop. */
        background-color: var(--bg-primary, #061711);
    }

    hr {
        height: 0;
        color: inherit;
        border-top-width: 1px;
    }

    abbr:where([title]) {
        -webkit-text-decoration: underline dotted;
        text-decoration: underline dotted;
    }

    h1, h2, h3, h4, h5, h6 {
        font-size: inherit;
        font-weight: inherit;
    }

    a {
        color: inherit;
        -webkit-text-decoration: inherit;
        text-decoration: inherit;
    }

    b, strong {
        font-weight: bolder;
    }

    code, kbd, samp, pre {
        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
        font-feature-settings: normal;
        font-variation-settings: normal;
        font-size: 1em;
    }

    small {
        font-size: 80%;
    }

    sub, sup {
        font-size: 75%;
        line-height: 0;
        position: relative;
        vertical-align: baseline;
    }

    sub {
        bottom: -0.25em;
    }

    sup {
        top: -0.5em;
    }

    table {
        text-indent: 0;
        border-color: inherit;
        border-collapse: collapse;
    }

    :-moz-focusring:where(:not(iframe)) {
        outline: auto;
    }

    progress {
        vertical-align: baseline;
    }

    summary {
        display: list-item;
    }

    ol, ul, menu {
        list-style: none;
    }

    img, svg, video, canvas, audio, iframe, embed, object {
        display: block;
        vertical-align: middle;
    }

    img, video {
        max-width: 100%;
        height: auto;
    }

    button, input, select, optgroup, textarea, ::file-selector-button {
        font: inherit;
        font-feature-settings: inherit;
        font-variation-settings: inherit;
        letter-spacing: inherit;
        color: inherit;
        border-radius: 0;
        background-color: transparent;
        opacity: 1;
    }

    :where(select:is([multiple], [size])) optgroup {
        font-weight: bolder;
    }

    :where(select:is([multiple], [size])) optgroup option {
        padding-inline-start: 20px;
    }

    ::file-selector-button {
        margin-inline-end: 4px;
    }

    ::placeholder {
        opacity: 1;
    }

    @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
        ::placeholder {
            color: currentcolor;

            @supports (color: color-mix(in lab, red, red)) {
                color: color-mix(in oklab, currentcolor 50%, transparent);
            }
        }
    }

    textarea {
        resize: vertical;
    }

    ::-webkit-search-decoration {
        -webkit-appearance: none;
    }

    ::-webkit-date-and-time-value {
        min-height: 1lh;
        text-align: inherit;
    }

    ::-webkit-datetime-edit {
        display: inline-flex;
    }

    ::-webkit-datetime-edit-fields-wrapper {
        padding: 0;
    }

    ::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
        padding-block: 0;
    }

    ::-webkit-calendar-picker-indicator {
        line-height: 1;
    }

    :-moz-ui-invalid {
        box-shadow: none;
    }

    button, input:where([type='button'], [type='reset'], [type='submit']), ::file-selector-button {
        appearance: button;
    }

    ::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
        height: auto;
    }

    [hidden]:where(:not([hidden='until-found'])) {
        display: none !important;
    }
}

button {
    transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1),
                filter 0.12s ease,
                box-shadow 0.15s ease,
                background 0.15s ease,
                opacity 0.15s ease;
}

button:active:not(:disabled) {
    transform: scale(0.96);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

::selection {
    background: rgba(59, 130, 246, 0.3);
}

/* Blazor error UI */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--accent-red, #fb7185);
    color: white;
    z-index: 1000;
    font-size: 0.875rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: 0.5rem;
}

/* ===========================================================================
   Animations: entrance animations, applied through the .animate-*
   utility classes. --ease-spring overshoots slightly before settling.
   =========================================================================== */
:root {
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* The app's z-index order. The layers are styled in different stylesheets, so the order is declared here.
       Without it, the order between a game dialog and the connection shell would depend on which component
       rendered last.

       The connection shell layers are above every game layer, so a game screen can never cover the
       "Connection lost" state. */
    --layer-chrome:       50;   /* the shell's top bar, HUD and navigation */
    --layer-dialog:       65;   /* a modal dialog, above the screen that opened it */
    --layer-toast:        70;
    --layer-reward:       72;
    --layer-fx:           74;
    --layer-conn-pill:    75;
    --layer-conn-scrim:   80;
}

/* The display font (--font-display, Cinzel) for headings and labels. Body text uses Inter, set in App.razor. */
.font-display {
    font-family: var(--font-display);
}

@keyframes mp-pop-in {
    0%   { opacity: 0; transform: scale(0.85); }
    60%  { opacity: 1; transform: scale(1.03); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes mp-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.animate-pop-in    { animation: mp-pop-in 0.30s var(--ease-spring) both; }
.animate-fade-in   { animation: mp-fade-in 0.20s ease both; }

/* A button with a top highlight and a solid bottom edge, which moves down when pressed. Use it together with
   a class that sets the background colour. */
.btn-glossy {
    position: relative;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35),
                0 8px 18px -6px rgba(0, 0, 0, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.30);
}
.btn-glossy:active:not(:disabled) {
    transform: translateY(3px) scale(0.99);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35),
                0 3px 10px -6px rgba(0, 0, 0, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* Reduced motion: entrance animations finish at once and keep their final state through their fill mode. */
@media (prefers-reduced-motion: reduce) {
    .animate-pop-in,
    .animate-fade-in {
        animation-duration: 0.001s;
    }
}

/* ===========================================================================
   Connection shell (ConnectionOverlay.razor): shown when the server connection is
   not working. A small pill for a short interruption around a tab switch, and a
   modal that covers the whole app, including the top bar, so that the player
   cannot tap a screen that is no longer live.

   The rules read the app's design tokens (docs/meta-shell.md, "Styles and design
   tokens"), with the token values as fallbacks for when the tokens are not
   declared yet.
   =========================================================================== */
.mp-conn-pill {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 3.25rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--layer-conn-pill, 75);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    max-width: calc(100% - 2rem);
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    background: rgba(2, 8, 6, 0.55);
    backdrop-filter: blur(6px);
    color: var(--text-secondary, #b9c2b6);
    font-size: 0.75rem;
    white-space: nowrap;
    pointer-events: none;
}

.mp-conn-pill__dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 999px;
    background: var(--gold, #f5c542);
    animation: mp-conn-blink 1.4s ease-in-out infinite;
}

@keyframes mp-conn-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.25; }
}

.mp-conn-scrim {
    position: fixed;
    inset: 0;
    z-index: var(--layer-conn-scrim, 80);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(2, 8, 6, 0.78);
    backdrop-filter: blur(2px);
}

.mp-conn-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: min(22rem, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    background: var(--bg-card, #0e1b16);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    text-align: center;
}

.mp-conn-card__title {
    font-size: 1.25rem;
    color: var(--text-primary, #f2efe6);
}

.mp-conn-card__body {
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-secondary, #b9c2b6);
}

.mp-conn-card__button {
    margin-top: 0.4rem;
    padding: 0.55rem 1.25rem;
    border-radius: 0.6rem;
    background: var(--gold, #f5c542);
    color: var(--on-gold, #2a1f08);
    font-size: 0.875rem;
    font-weight: 600;
}

.mp-conn-spinner {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    border: 2px solid var(--hairline-strong, rgba(255, 255, 255, 0.16));
    border-top-color: var(--gold, #f5c542);
    animation: mp-conn-spin 0.9s linear infinite;
}

@keyframes mp-conn-spin {
    to { transform: rotate(360deg); }
}

/* Reduced motion stops the spinner and the pill's dot but keeps them visible, because they show that the
   client is still trying to reconnect. */
@media (prefers-reduced-motion: reduce) {
    .mp-conn-spinner,
    .mp-conn-pill__dot {
        animation: none;
    }
}

/* ===========================================================================
   Fallback pages: the debug layout (Layout/MainLayout.razor) used by a page
   without its own layout, the not-found page (App.razor) and /Error
   (Pages/Error.razor).
   =========================================================================== */
.mp-column {
    width: 100%;
    max-width: 42rem;
    margin-inline: auto;
    padding-inline: 1rem;
}

.mp-debugbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--layer-chrome, 50);
}

.mp-debugbar__row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 3rem;
}

.mp-debugbar__cluster {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 11px;
}

.mp-debugbar__chip {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.mp-debugbar__dot {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 999px;
    background: var(--text-muted, #8a948a);
}

.mp-debugbar__dot--connected {
    background: var(--claim, #2ee6c5);
}

.mp-debugbar__dot--connecting {
    background: var(--gold, #f5c542);
    animation: mp-conn-blink 1.4s ease-in-out infinite;
}

.mp-debugbar__dot--error {
    background: var(--danger, #fb7185);
}

.mp-debugbar__button {
    padding: 0.25rem 0.625rem;
    border-radius: 0.25rem;
    font-weight: 500;
}

.mp-page {
    padding-top: 1.25rem;
}

.mp-fallback {
    padding: 1.5rem;
    text-align: center;
}

.mp-fallback-title {
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 600;
}

.mp-error {
    padding: 1.5rem;
    border-radius: 0.5rem;
}

.mp-error__lead {
    margin-bottom: 1rem;
}

.mp-error__dev {
    margin-top: 1.5rem;
    padding-top: 1rem;
}

.mp-error__heading {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
}

.mp-error__note {
    font-size: 0.875rem;
    line-height: 1.25rem;
}

.mp-error__note + .mp-error__note {
    margin-top: 0.5rem;
}

.mp-error__code {
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

@media (prefers-reduced-motion: reduce) {
    .mp-debugbar__dot--connecting {
        animation: none;
    }
}
