#screen {
    height: 100vh;
    height: 100dvh;
    min-width: 320px;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#screen.theme-crossfade-snapshot {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 10000;
    opacity: 1;
    pointer-events: none;
    background-color: var(--bg);
    color: var(--fg);
    font-family: var(--font-ui);
    transition: opacity var(--crossfade-duration, 2s) linear;
}

#background {
    position: absolute;
    inset: 0;
    background-position: center;
    background-size: cover;
    opacity: var(--background-image-opacity);
    z-index: 0;
}

header,
.center,
footer {
    position: relative;
    z-index: 1;
}

header {
    padding: 14px 26px 8px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: start;
    column-gap: clamp(6px, 1vw, 14px);
}

.header-left {
    min-width: 0;
    grid-column: 1;
}

header .brand {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    justify-self: center;
}

.header-right {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    min-width: 0;
}

.header-left,
.header-right {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.header-right {
    align-items: flex-end;
}

.brand {
    color: var(--sub);
    font-size: inherit;
    letter-spacing: 0.04em;
}

header a {
    color: var(--fg);
    text-decoration: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.5vw, 18px);
}

.header-actions .sign-in-link {
    border: 1px solid var(--ui-border);
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 13px;
}

.header-actions .settings-link {
    white-space: nowrap;
}

.profile-link {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--ui-border);
    border-radius: 50%;
}

.profile-link[hidden] {
    display: none;
}

.profile-link svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
}

.center {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

/* Overall clock size belongs to layout; face details live in faces/classic.css. */
.analog {
    width: min(78vh, 75vw, 850px, max(0px, calc(100dvh - 300px)));
}

.digital {
    font-family: var(--font-clock);
    font-size: clamp(70px, 15.5vw, 190px);
    font-weight: var(--digital-weight);
    letter-spacing: -0.06em;
    font-variant-numeric: tabular-nums;
    padding: 0.12em 0.22em;
    border: 1px solid color-mix(in srgb, var(--fg) 30%, transparent);
    border-radius: 0.2em;
}

.digital .day-period {
    display: inline-block;
    font-size: 0.28em;
    letter-spacing: 0.08em;
    vertical-align: baseline;
    margin-left: 0.1em;
}

.digital .digital-seconds {
    font-size: 0.66em;
}

#conditions {
    width: min(88vw, 620px, max(260px, calc(100dvh - 400px)));
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: clamp(8px, 1.2vw, 14px);
}

.condition-card {
    min-width: 0;
    padding: 10px 12px 8px;
    border: 1px solid var(--face-border);
    border-color: color-mix(in srgb, var(--face-border) 48%, transparent);
    border-radius: 12px;
    background: var(--face-bg);
    background: color-mix(in srgb, var(--face-bg) 82%, var(--bg));
    box-shadow: 0 5px 18px #00000012;
    text-align: left;
}

.condition-title {
    margin: 0 0 4px;
    color: var(--sub);
    font-family: var(--font-ui);
    font-size: 9px;
    font-weight: 650;
    letter-spacing: 0.14em;
    line-height: 1.2;
    text-transform: uppercase;
}

.condition-primary {
    font-family: var(--font-ui);
    font-size: clamp(14px, 1.35vw, 18px);
    font-weight: 400;
    line-height: 1.2;
    color: var(--fg);
    min-width: 0;
    overflow-wrap: anywhere;
}

.condition-metrics {
    display: flex;
    justify-content: space-between;
    gap: 5px 10px;
    margin-top: 7px;
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: clamp(9px, 0.9vw, 11px);
    font-weight: 400;
    line-height: 1.25;
}

.condition-metrics span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.condition-source {
    display: block;
    margin-top: 6px;
    font-size: 9px;
    line-height: 1.2;
    color: var(--sub);
}

#city {
    font-size: clamp(15px, 2vw, 21px);
    color: var(--sub);
}

#full {
    position: absolute;
    z-index: 2;
    left: 26px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--fg);
    border: 0;
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
}

#full:hover,
#full:focus-visible {
    background: color-mix(in srgb, var(--fg) 10%, transparent);
}

#full:focus-visible {
    outline: 2px solid var(--fg);
    outline-offset: 2px;
}

#full svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#full .fullscreen-exit-icon {
    display: none;
}

#full[aria-label="Exit fullscreen"] .fullscreen-enter-icon {
    display: none;
}

#full[aria-label="Exit fullscreen"] .fullscreen-exit-icon {
    display: block;
}

@media (max-width: 650px) {
    .analog {
        width: min(85vw, max(0px, calc(100dvh - 295px)));
    }

    header {
        padding: 10px 14px 6px;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    }

    header .brand {
        grid-column: 2;
        grid-row: 1;
    }

    .header-right {
        grid-column: 3;
        grid-row: 1;
    }

    .header-actions {
        gap: 4px;
    }

    #date {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 10px;
    }

    .brand {
        font-size: 10px;
    }

    #conditions {
        width: min(80vw, max(250px, calc(100dvh - 390px)));
        gap: 7px;
    }

    .condition-card {
        padding: 8px 9px 7px;
        border-radius: 10px;
    }

    .header-actions .sign-in-link {
        padding: 5px 6px;
        font-size: 10px;
        white-space: nowrap;
    }

    .header-actions .settings-link {
        font-size: 11px;
    }

    .profile-link {
        width: 28px;
        height: 28px;
    }

    #full {
        left: max(0px, env(safe-area-inset-left));
        width: 24px;
        height: 24px;
        padding: 3px;
    }

    #full svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-height: 600px) {
    header {
        padding-block: 7px 4px;
    }

    .header-left,
    .header-right {
        gap: 4px;
    }

    .brand {
        font-size: 10px;
    }

    #full {
        left: max(2px, env(safe-area-inset-left));
    }

    .center {
        gap: 8px;
    }

    .digital {
        font-size: min(15.5vw, 18vh, 105px);
    }

    .analog {
        width: min(75vw, max(0px, calc(100dvh - 275px)));
    }

    #conditions {
        width: min(68vw, max(0px, calc(100dvh - 350px)));
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    #screen {
        min-height: 600px;
    }

    .analog {
        width: min(75vw, 325px);
    }

    .digital {
        font-size: min(15.5vw, 105px);
    }

    #conditions {
        width: min(88vw, 620px);
    }
}

@media (max-width: 360px) {
    .condition-metrics {
        flex-direction: column;
        gap: 3px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #screen.theme-crossfade-snapshot {
        transition: none !important;
    }
}
