:root {
    /* Official marketing palette */
    --apug-brick: #A8353A;
    --apug-red-2: #D34147;
    --apug-red-3: #892A36;
    --apug-red-4: #5B262B;
    --apug-gray-1: #BCBDC0;
    --apug-gray-2: #77787B;
    --apug-taupe-1: #EDEBE8;
    --apug-taupe-2: #DCD6C9;
    --apug-taupe-3: #CCC2B7;

    /* Brand roles: Brick primary, Red 3 hover, Red 4 strong, Red 2 mid accent */
    --apug-brand: var(--apug-brick);
    --apug-brand-hover: var(--apug-red-3);
    --apug-brand-strong: var(--apug-red-4);
    --apug-brand-accent: var(--apug-red-2);
    --apug-brand-focus: rgba(168, 53, 58, 0.25);
    --apug-brand-muted: rgba(168, 53, 58, 0.12);
    --apug-brand-highlight: rgba(211, 65, 71, 0.16);

    --pico-primary: var(--apug-brand);
    --pico-primary-hover: var(--apug-brand-hover);
    --pico-primary-focus: var(--apug-brand-focus);
    --pico-primary-inverse: #fff;
    --pico-primary-background: var(--apug-brand-muted);
    --pico-primary-border: var(--apug-brand);
    --pico-primary-underline: rgba(168, 53, 58, 0.5);
    --pico-form-element-focus-color: var(--apug-brand-focus);
    --pico-form-element-selected-background-color: var(--apug-brand-highlight);
    --pico-switch-checked-background-color: var(--apug-brand);

    /* Soft surfaces / borders from taupe + gray (not body text) */
    --apug-surface: var(--apug-taupe-1);
    --apug-surface-muted: var(--apug-taupe-2);
    --apug-border: var(--apug-taupe-3);
    --apug-border-muted: var(--apug-gray-1);

    /* Theme toggle icon color — defined here (on <html>) so it cannot be
       overridden by Pico's button rule which sets --pico-color: #fff */
    --toggle-icon-color: #1b2532;
}

[data-theme="dark"] {
    --toggle-icon-color: var(--pico-primary-inverse);
    /* Official Brick/Red 3/4 fail AA on dark bg — lift from Red 2 for links/UI */
    --apug-brand: #DB555A;
    --apug-brand-hover: #E0666B;
    --apug-brand-strong: var(--apug-red-2);
    --apug-brand-accent: #E0666B;
    --apug-brand-focus: rgba(219, 85, 90, 0.35);
    --apug-brand-muted: rgba(219, 85, 90, 0.18);
    --apug-brand-highlight: rgba(211, 65, 71, 0.22);
    --pico-primary-underline: rgba(219, 85, 90, 0.55);
    --pico-primary-inverse: #fff;
    --pico-form-element-selected-background-color: var(--apug-brand-highlight);
    /* Keep cool Pico neutrals; taupe reads dirty on dark */
    --apug-surface: #1b2532;
    --apug-surface-muted: #202632;
    --apug-border: rgba(188, 189, 192, 0.35);
    --apug-border-muted: rgba(188, 189, 192, 0.22);
}

body {
    font-size: 0.90rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body > header {
    padding-block-end: calc(var(--pico-spacing) * 0.25);
}

body > main {
    flex: 1;
    padding-block-start: calc(var(--pico-spacing) * 0.25);
}

/* Theme Switcher - SVG Animation (Pico CSS theme toggle) */
#theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.25rem;
    border: none;
    background: transparent;
    /* var(--pico-color) cannot be used here — Pico overrides it to
       --pico-primary-inverse (#fff) on every <button> element.
       Use our own token defined above Pico's button scope instead. */
    color: var(--toggle-icon-color);
    cursor: pointer;
    border-radius: 999px;
    /* Sit slightly below brand text optical center so the icon aligns with the glyphs */
    transform: translateY(4px);
}

#theme-toggle:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] #theme-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
}

#theme-toggle:focus,
#theme-toggle:focus-visible {
    --pico-primary-focus: transparent;
    outline: none;
    box-shadow: none;
}


#unable-to-signin-btn:focus,
#unable-to-signin-btn:focus-visible {
    --pico-primary-focus: transparent;
    outline: none;
    box-shadow: none;
}

/* Pico's icon-theme-toggle animation */
svg.icon-theme-toggle {
    --theme-toggle-duration: 0.4s;
    overflow: visible; /* required: clipPath cutout extends outside SVG bounds during animation */
}

svg.icon-theme-toggle :first-child path {
    transition-duration: calc(var(--theme-toggle-duration) * 0.6);
    transition-property: transform, d;
    transition-timing-function: cubic-bezier(0, 0, 0.5, 1);
}

svg.icon-theme-toggle g circle,
svg.icon-theme-toggle g path {
    transform-origin: center;
    transition:
        transform calc(var(--theme-toggle-duration) * 0.65)
                  cubic-bezier(0, 0, 0, 1.25)
                  calc(var(--theme-toggle-duration) * 0.35);
}

svg.icon-theme-toggle.moon g circle {
    transform: scale(1.4);
    transition-delay: 0s;
}

svg.icon-theme-toggle.moon g path {
    transform: scale(0.75);
    transition-delay: 0s;
}

svg.icon-theme-toggle.moon :first-child path {
    d: path("M-9 3h25a1 1 0 0017 13v30H0Z");
    transition-delay: calc(var(--theme-toggle-duration) * 0.4);
    transition-timing-function: cubic-bezier(0, 0, 0, 1.25);
}

/* Fallback for browsers without d:path() support */
@supports not (d: path("")) {
    svg.icon-theme-toggle.moon :first-child path {
        transform: translate3d(-9px, 14px, 0);
    }
}

/* Header & Navigation */
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand img {
    width: 1.5rem;
    height: 1.5rem;
    display: block;
    flex-shrink: 0;
}

.brand strong {
    display: block;
    /* Nudge up — text sat too low in the header band */
    transform: translateY(-6px);
}

.brand small {
    display: block;
    color: var(--pico-muted-color);
    font-size: 0.75rem;
}

/* Main content */
main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 0;
}

.container {
    width: min(100%, 22rem);
}

main .container {
    width: min(100%, 22rem);
}

header .container,
footer .container {
    width: min(100%, 90rem);
    margin: 0 auto;
    padding: 0 1.5rem;

}

article.card {
    padding: 2rem;
}

/* Logo on login screen */
.login-logo {
    display: block;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto 1rem;
}

/* Header styling */
header {
    border-bottom: 1px solid var(--pico-muted-border-color);
    padding: 0.75rem 0;
}

header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* Footer */
footer {
    border-top: 1px solid var(--pico-muted-border-color);
    padding: 0.75rem 0;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
}

footer .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

footer p {
    margin: 0;
    line-height: 1.25;
}

footer .app-version {
    color: var(--pico-muted-color);
    font-weight: 400;
}

/* Login form blocks */
.login-brand {
    text-align: center;
}

.login-block {
    display: grid;
    gap: 1.5rem;
}

.login-block h1 {
    margin: 0.5rem 0 0;
    font-size: 1.5rem;
    text-align: center;
}

.login-block > p {
    margin: 0;
    text-align: center;
    color: var(--pico-muted-color);
}

.or-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--pico-muted-color);
    font-size: 0.875rem;
}

.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--pico-muted-border-color);
}

/* Google Sign-In Button */
.google-signin {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.9rem 1rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 0.5rem;
    background: var(--pico-background);
    color: #000;
    text-decoration: none;
    transition: all 0.2s ease;
}

[data-theme="dark"] .google-signin {
    color: #fff;
}

.google-signin:hover {
    background: color-mix(in srgb, currentColor 10%, var(--pico-background));
    border-color: var(--pico-muted-border-color);
}

.google-signin svg {
    width: 20px;
    height: 20px;
}

/* Support link */
.support-link {
    text-align: center;
}

.link-button {
    background: none;
    border: none;
    color: var(--pico-primary);
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    font-size: 0.95rem;
}

.link-button:hover {
    color: var(--pico-primary-hover);
    text-decoration-color: var(--pico-primary-hover);
    --pico-underline: var(--pico-primary-hover);
}

[data-theme="dark"] .link-button:hover {
    color: var(--pico-primary-inverse);
}

.link-button.link-button-footer {
    font-size: 0.75rem;
}

/* JICS form block */
.jics-block {
    padding: 1rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 0.5rem;
    background: var(--pico-background);
}

.jics-block h2 {
    margin: 0 0 1rem;
    font-size: 1rem;
}

/* Modal (native dialog + Pico article) */
#support-modal {
    border: none;
    padding: 0;
    margin: 0;
    max-width: none;
    max-height: none;
    width: 100%;
    height: 100%;
    background: transparent;
}

#support-modal[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

#support-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] #support-modal::backdrop {
    background: rgba(15, 15, 15, 0.5);
}

#support-modal article {
    width: min(100%, 24rem);
    padding: 2rem;
}

.modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    color: var(--pico-primary);
    margin: 0 auto 1rem;
    font-size: 1.5rem;
}

.modal-icon svg {
    width: 100%;
    height: 100%;
}

#support-modal h2 {
    margin: 0 0 0.5rem;
    text-align: center;
}

#support-modal p {
    text-align: center;
}

.modal-actions {
    display: grid;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.modal-actions a {
    display: block;
    text-align: center;
}

#email-address {
    display: block;
}

#close-modal-btn {
    display: block;
    margin: 0 auto;
}

/* Welcome back state */
.welcome-block {
    display: grid;
    gap: 1rem;
    text-align: center;
}

.welcome-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    color: var(--pico-primary);
    margin: 0 auto;
    font-size: 1.5rem;
}

.welcome-logo {
    width: 2.25rem;
    height: 2.25rem;
    display: block;
}

.welcome-block h1 {
    margin: 0;
    font-size: 1.3rem;
}

.welcome-block p {
    margin: 0;
    color: var(--pico-muted-color);
}

.user-info {
    padding: 1rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: 0.5rem;
    background: var(--pico-background);
    text-align: center;
    font-weight: 500;
}


/* Abstract Background Pattern - Constrained to Main */
.binary-circulating-bg {
    position: relative; /* Constrains absolute pseudo-elements to this container */
    overflow: hidden;   /* Prevents shapes from spilling into header/footer */
    background: linear-gradient(120deg, #F4F6F6 1%, #EDF2F6 99%);
    z-index: 1;         /* Establishes stacking context */
}

/* Ensure the login card sits above the background shapes */
.binary-circulating-bg > .container {
    position: relative;
    z-index: 2;
}

/* Large Rotated Concentric Square - Top Right */
.binary-circulating-bg::after {
    content: '';
    position: absolute;
    top: -15%;
    right: -10%;
    width: 520px;
    height: 520px;
    border-radius: 12px;
    border: 1px solid rgba(203, 213, 225, 0.6);
    
    /* 4 concentric layers */
    box-shadow: 
        inset 0 0 0 18px rgba(203, 213, 225, 0.15),
        inset 0 0 0 12px rgba(203, 213, 225, 0.25),
        inset 0 0 0 6px rgba(203, 213, 225, 0.35),
        inset 0 0 0 3px rgba(203, 213, 225, 0.45);
    
    transform: rotate(45deg);
    animation: floatSquare 12s infinite alternate ease-in-out;
    z-index: -2;          /* Behind dots */
    pointer-events: none; /* Prevents shapes from stealing clicks */
}


/* --- Keyframes for Subtle Animations --- */
@keyframes floatSquare {
    0% { 
        transform: rotate(45deg) translate(0, 0); 
    }
    100% { 
        transform: rotate(45deg) translate(25px, 25px); 
    }
}

/* Dot matrix (login decoration; toggled by login-page.js) */
.js-dot-matrix {
    position: absolute;
    bottom: 12%;
    left: 6%;
    width: 238px;
    height: 51px;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    z-index: -1;
    pointer-events: none;
    --dot-on: #cbd5e1;
}

.js-dot-matrix__dot {
    border-radius: 50%;
    background: transparent;
    opacity: 0;
}

.js-dot-matrix__dot.is-on {
    background: var(--dot-on);
    opacity: 0.6;
}

/* --- Pico.css Dark Mode Compatibility --- */
[data-theme="dark"] .binary-circulating-bg {
    background: linear-gradient(-120deg, #0B090B 1%, #130C0B 99%);
}

[data-theme="dark"] .js-dot-matrix {
    --dot-on: #374151;
}
