html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none; /* no rubber-band bounce around the app */
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation; /* no double-tap zoom */
    background-color: #F2F6F8; /* Knorvic background */
}

/* Compose draws everything; let it handle every gesture (no browser pinch / double-tap zoom). */
#composeTarget, #composeTarget canvas {
    touch-action: none;
}

/* iOS Safari zooms the page when focusing a field smaller than 16px; Compose's hidden text
   inputs (used for the keyboard) must never trigger that. */
input, textarea {
    font-size: 16px !important;
}

body {
    display: flex;
    flex-direction: column;
    font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#composeTarget {
    flex: 1;
    min-height: 0;
}

/* Loading screen (see index.html). */
#splash {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background-color: #F2F6F8;
    color: #1C2B33;
    transition: opacity 350ms ease;
}

#splash.hidden {
    opacity: 0;
    pointer-events: none;
}

.splash-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.splash-bar {
    width: 140px;
    height: 4px;
    border-radius: 999px;
    background-color: #E2E9EE;
    overflow: hidden;
}

.splash-bar span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: 999px;
    background-color: #F8CE47; /* Knorvic yellow */
    animation: splash-progress 1.1s ease-in-out infinite;
}

@keyframes splash-progress {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

/* When the app cannot start, the loading screen explains why instead of leaving a blank page. */
.splash-message {
    display: none;
    max-width: 340px;
    padding: 0 24px;
    text-align: center;
    font-family: var(--knorvic-text-font);
    font-size: 15px;
    line-height: 1.45;
    color: #51636D;
}

.splash-message strong {
    display: block;
    margin-bottom: 6px;
    font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
    font-size: 17px;
    color: #1C2B33;
}

.splash-message code {
    display: block;
    margin-top: 12px;
    font-size: 12px;
    opacity: 0.7;
    word-break: break-word;
}

.splash-retry {
    display: none;
    margin-top: 4px;
    padding: 12px 26px;
    border: 0;
    border-radius: 999px;
    background-color: #1C2B33;
    color: #FFFFFF;
    font: 600 15px "Space Grotesk", system-ui, -apple-system, sans-serif;
    cursor: pointer;
}

#splash.failed .splash-bar { display: none; }
#splash.failed .splash-message,
#splash.failed .splash-retry { display: block; }

/* Another tab holds the database: this one waits (see sqlite.worker.js) and says so. */
#db-locked {
    position: fixed;
    inset: 0;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-color: rgba(16, 32, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
}

#db-locked.visible {
    opacity: 1;
    pointer-events: auto;
}

#db-locked > div {
    max-width: 340px;
    padding: 24px 26px;
    border-radius: 28px;
    background-color: #FFFFFF;
    color: #51636D;
    font: 500 15px/1.45 var(--knorvic-text-font);
    box-shadow: 0 12px 40px rgba(16, 32, 42, 0.25);
}

#db-locked strong {
    display: block;
    margin-bottom: 6px;
    font: 700 18px "Space Grotesk", system-ui, -apple-system, sans-serif;
    color: #1C2B33;
}

/* Dark: the system's choice unless Settings forces light (data-theme on <html>, see index.html). */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]),
    :root:not([data-theme="light"]) body,
    :root:not([data-theme="light"]) #splash {
        background-color: #10202A;
        color: #E4ECF1;
    }

    :root:not([data-theme="light"]) .splash-bar {
        background-color: #2C3D48;
    }

    :root:not([data-theme="light"]) .splash-message,
    :root:not([data-theme="light"]) #db-locked > div { color: #A9B8C1; }
    :root:not([data-theme="light"]) .splash-message strong,
    :root:not([data-theme="light"]) #db-locked strong { color: #E4ECF1; }
    :root:not([data-theme="light"]) .splash-retry { background-color: #F8CE47; color: #1C2B33; }
    :root:not([data-theme="light"]) #db-locked > div { background-color: #1A2C37; }
}

:root[data-theme="dark"],
:root[data-theme="dark"] body,
:root[data-theme="dark"] #splash {
    background-color: #10202A;
    color: #E4ECF1;
}

:root[data-theme="dark"] .splash-bar {
    background-color: #2C3D48;
}

:root[data-theme="dark"] .splash-message,
:root[data-theme="dark"] #db-locked > div { color: #A9B8C1; }
:root[data-theme="dark"] .splash-message strong,
:root[data-theme="dark"] #db-locked strong { color: #E4ECF1; }
:root[data-theme="dark"] .splash-retry { background-color: #F8CE47; color: #1C2B33; }
:root[data-theme="dark"] #db-locked > div { background-color: #1A2C37; }

/* Text font for the HTML inputs of the login form (the rest is drawn by Compose). */
@font-face {
    font-family: "Manrope";
    font-weight: 500;
    font-display: swap;
    src: url("composeResources/com.knorvic.cashup.resources/font/manrope_medium.ttf") format("truetype");
}

:root {
    --knorvic-text-font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
