/* The demo's own pages. Every colour is a design token, copied from the app's app.css (docs/ARCHITECTURE.md, Design
   tokens): the page around the two frames looks like the app, light and dark. The app's own fonts, served by the
   demo. */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }

:root {
    --bg: #F5F2EC;
    --card: #FFFFFF;
    --ink: #1D1B18;
    --muted: #5C574F;
    --line: #E3DED5;
    --chip: #E8E3DA;
    --accent: #C2410C;
    --on-ink: #FFFFFF;
    --backdrop: rgba(29, 27, 24, 0.5);
    --font-sans: "IBM Plex Sans", system-ui, sans-serif;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16140F;
        --card: #221F1A;
        --ink: #F2EEE7;
        --muted: #B3AA9E;
        --line: #332E27;
        --chip: #2E2A24;
        --accent: #F06A2C;
        --on-ink: #16140F;
        --backdrop: rgba(0, 0, 0, 0.6);
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.4;
}

h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

p {
    margin: 0;
}

.muted {
    color: var(--muted);
}

button {
    min-height: 44px;
    padding: 0 20px;
    border: 0;
    border-radius: 12px;
    background: var(--ink);
    color: var(--on-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* The page: a header, then the two frames. On a phone and a tablet (below 1024 px) one frame at a time, by the tabs:
   radio buttons and their labels, so it works without JavaScript. */
body.demo {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.demo-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
}

.demo-intro p {
    font-size: 14px;
}

.tab-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.demo-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    background: var(--chip);
}

.demo-tabs label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 10px;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#tab-app:checked ~ .demo-header label[for="tab-app"],
#tab-simulator:checked ~ .demo-header label[for="tab-simulator"] {
    background: var(--card);
    color: var(--ink);
}

#tab-app:focus-visible ~ .demo-header label[for="tab-app"],
#tab-simulator:focus-visible ~ .demo-header label[for="tab-simulator"] {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.demo-frames {
    position: relative;
    flex: 1;
    display: flex;
    min-height: 0;
}

.demo-frames iframe {
    flex: 1;
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--bg);
}

#tab-app:checked ~ .demo-frames .frame-simulator,
#tab-simulator:checked ~ .demo-frames .frame-app,
#tab-simulator:checked ~ .demo-frames .template-offer {
    display: none;
}

/* "Skip setup": over the app's frame only, the app dimmed behind; the simulator stays usable. The card is centred by
   its margins, so on a short screen it scrolls from its top rather than being cut off. */
.template-offer {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    padding: 16px;
    overflow-y: auto;
    background: var(--backdrop);
}

.template-offer .card {
    margin: auto;
}

/* "Getting your demo ready": over both frames (on a phone, whichever tab shows) until they have loaded. */
.waiting {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    padding: 16px;
    overflow-y: auto;
    background: var(--bg);
}

.waiting[hidden] {
    display: none;
}

.waiting .card {
    align-items: center;
    margin: auto;
    text-align: center;
}

/* "Taking long? Reload": hidden for 20 seconds, then shown by the stylesheet alone, so a page whose script didn't load
   isn't stuck. Shown again from the start each time the waiting screen is. */
.waiting-slow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    visibility: hidden;
    animation: waiting-slow 0s 20s forwards;
}

@keyframes waiting-slow {
    to {
        visibility: visible;
    }
}

a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 20px;
    border-radius: 12px;
    background: var(--chip);
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
}

a.button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.spinner {
    flex: none;
    width: 40px;
    height: 40px;
    border: 4px solid var(--chip);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

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

.template-offer form {
    margin: 0;
}

.template-offer button {
    width: 100%;
}

.template-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 16px 20px;
    text-align: left;
}

.template-name {
    font-size: 18px;
}

.template-text {
    font-size: 14px;
    font-weight: 400;
}

button.secondary {
    background: var(--chip);
    color: var(--ink);
}

button:disabled {
    cursor: progress;
    opacity: 0.6;
}

/* Desktop: the simulator on the left third, the app on the right two thirds, no tabs. */
@media (min-width: 1024px) {
    .demo-header {
        flex-direction: row;
        align-items: center;
    }

    .demo-intro {
        display: flex;
        align-items: baseline;
        gap: 16px;
    }

    .demo-tabs {
        display: none;
    }

    #tab-app:checked ~ .demo-frames .frame-simulator,
    #tab-simulator:checked ~ .demo-frames .frame-app {
        display: block;
    }

    #tab-simulator:checked ~ .demo-frames .template-offer {
        display: flex;
    }

    /* The app's two thirds. */
    .template-offer {
        left: calc(100% / 3);
    }

    .demo-frames .frame-simulator {
        flex: 1;
        border-right: 1px solid var(--line);
    }

    .demo-frames .frame-app {
        flex: 2;
    }
}

/* Busy, stopped: one card in the middle. */
body.message {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 480px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
}

.card h1,
.card h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

/* "Are you still there?" and "Your demo has ended": over the whole page, the page dimmed behind. */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--backdrop);
}

.overlay[hidden] {
    display: none;
}

/* Nothing is left behind it: the page's own background. */
#demo-ended {
    background: var(--bg);
}
