* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    background-color: var(--night);
    color: var(--chalk);

    height: 100dvh;
    overflow: hidden;
    position: relative;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

:root {
    --safe-top: env(safe-area-inset-top);
    --safe-right: env(safe-area-inset-right);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);

    --frame-gap: 15px;
    --frame-border: 5px;

    --night: #000000;
    --chalk: #FFFFFF;
    --frame-ink: #0000FF;
    --frame-ink-lit: #0040FF;
    --tick: #FF0000;
}

body,
.blue-frame,
.line,
.center-dot,
.error-text,
.error-description,
.date,
.week-number {
    transition:
        background-color 0.6s ease,
        border-color 0.6s ease,
        color 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
    body,
    .blue-frame,
    .line,
    .center-dot,
    .error-text,
    .error-description,
    .date,
    .week-number { transition: none; }
}

body[data-page="404"] {
    --reply-align: left;
}

body[data-page="404"] .switch-reply { color: var(--chalk); }

#bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
}

.bg-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.bg-layer.is-on { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
    .bg-layer { transition: none; }
}

.blue-frame {
    position: absolute;
    top: calc(15px + var(--safe-top));
    left: calc(15px + var(--safe-left));
    right: calc(15px + var(--safe-right));
    bottom: calc(15px + var(--safe-bottom));
    border: 5px solid var(--frame-ink);
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 30px;
}

.clock-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clock {
    position: relative;
    width: min(90vw, 90vh);
    height: min(90vw, 90vh);
    max-width: 800px;
    max-height: 800px;
}

.clock-face {
    position: relative;
    width: 100%;
    height: 100%;
    background: transparent;
}

.line {
    position: fixed;
    background-color: var(--chalk);
    z-index: 100;
}

.line-12 {
    top: calc(15px + var(--safe-top));
    left: 50%;
    width: 2px;
    height: 30px;
    transform: translateX(-50%);
}

.line-3 {
    top: 50%;
    right: calc(15px + var(--safe-right));
    width: 30px;
    height: 2px;
    transform: translateY(-50%);
}

.line-6 {
    bottom: calc(15px + var(--safe-bottom));
    left: 50%;
    width: 2px;
    height: 30px;
    transform: translateX(-50%);
}

.line-9 {
    top: 50%;
    left: calc(15px + var(--safe-left));
    width: 30px;
    height: 2px;
    transform: translateY(-50%);
}

.error-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(24px, 4vw, 48px);
    font-weight: 900;
    color: var(--frame-ink);
    letter-spacing: 0.1em;
    margin-bottom: 10px;
}

.error-description {
    font-family: 'Inter', sans-serif;
    font-size: clamp(12px, 1.5vw, 18px);
    font-weight: 400;
    color: var(--chalk);
    line-height: 1.4;
    opacity: 0.8;
    max-width: 300px;
    margin-bottom: 5px;
}

.date-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.4;
    margin-bottom: 5px;
}

.week-number {
    font-family: 'Inter', sans-serif;
    font-size: clamp(12px, 1.5vw, 18px);
    font-weight: 400;
    color: var(--chalk);
    line-height: 1.4;
    opacity: 0.8;
    margin-top: 0;
}

.center-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    background: var(--chalk);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
}

.hand {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform-origin: 50% 100%;
    background: var(--chalk);
    border-radius: 2px;
}

.hour-hand {
    width: 4px;
    height: 25%;
    margin-left: -2px;
    z-index: 15;
}

.minute-hand {
    width: 3px;
    height: 35%;
    margin-left: -1.5px;
    z-index: 16;
}

.second-hand {
    width: 1px;
    height: 40%;
    background: var(--tick);
    margin-left: -0.5px;
    z-index: 17;
    transition: background-color 0.6s ease;
}

body[data-page="404"][data-bg="polar"] .hand,
body[data-page="404"][data-bg="polar"] .center-dot { opacity: 0; }

.center-dot { transition: opacity 0.6s ease; }

@media (prefers-reduced-motion: reduce) {
    .center-dot { transition: none; }
}

.bottom-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    color: var(--chalk);
    z-index: var(--layer-note, 900);
    position: absolute;
    bottom: calc(15px + var(--safe-bottom));
    left: calc(20px + var(--safe-left));
    right: calc(20px + var(--safe-right));
    padding-bottom: 5px;
}

.bottom-info[data-header-follow] {
    --header-shift: 10px;
    transform: translateY(0);
    transition:
        opacity var(--header-fade) cubic-bezier(0.22, 0.61, 0.36, 1),
        transform var(--header-fade) cubic-bezier(0.22, 0.61, 0.36, 1),
        visibility 0s;
}

.bottom-info[data-header-follow].header-hidden {
    transform: translateY(var(--header-shift));
    transition:
        opacity var(--header-fade) cubic-bezier(0.4, 0, 0.6, 1),
        transform var(--header-fade) cubic-bezier(0.4, 0, 0.6, 1),
        visibility 0s linear var(--header-fade);
}

@media (prefers-reduced-motion: reduce) {
    .bottom-info[data-header-follow],
    .bottom-info[data-header-follow].header-hidden {
        transform: none;
        transition: opacity 1ms linear, visibility 0s;
    }
}

.bottom-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    margin-bottom: -5px;
}

.bottom-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    justify-content: flex-end;
    margin-bottom: -5px;
}

.date {
    font-family: 'Inter', sans-serif;
    font-size: clamp(12px, 1.5vw, 18px);
    font-weight: 400;
    color: var(--chalk);
    line-height: 1.4;
    opacity: 0.8;
    margin-bottom: 0;
}

.uptime-value {
    font-weight: 600;
    font-family: 'Space Grotesk', monospace;
}

@media (max-width: 768px) {
    :root { --frame-gap: 12px; --frame-border: 4px; }

    .blue-frame {
        top: calc(12px + var(--safe-top));
        left: calc(12px + var(--safe-left));
        right: calc(12px + var(--safe-right));
        bottom: calc(12px + var(--safe-bottom));
        border-width: 4px;
        padding: 25px;
    }

.clock {
        width: min(85vw, 85vh);
        height: min(85vw, 85vh);
        max-width: 600px;
        max-height: 600px;
    }
    
    .bottom-info {
        font-size: 11px;
        bottom: calc(12px + var(--safe-bottom));
        left: calc(25px + var(--safe-left));
        right: calc(25px + var(--safe-right));
    }
    
    .error-text {
        font-size: clamp(18px, 3vw, 32px);
    }
    
    .error-description {
        font-size: clamp(11px, 1.4vw, 16px);
        max-width: 280px;
    }
    
    .date {
        font-size: clamp(11px, 1.4vw, 16px);
    }
    
    .week-number {
        font-size: clamp(11px, 1.4vw, 16px);
    }
}

@media (max-width: 480px) {
    :root { --frame-gap: 10px; --frame-border: 3px; }

    .blue-frame {
        top: calc(10px + var(--safe-top));
        left: calc(10px + var(--safe-left));
        right: calc(10px + var(--safe-right));
        bottom: calc(10px + var(--safe-bottom));
        border-width: 3px;
        padding: 20px;
    }

.clock {
        width: min(80vw, 80vh);
        height: min(80vw, 80vh);
        max-width: 400px;
        max-height: 400px;
    }
    
    .error-text {
        font-size: clamp(16px, 2.8vw, 28px);
        margin-bottom: 6px;
    }
    
    .error-description {
        font-size: clamp(10px, 1.3vw, 14px);
        max-width: 220px;
        line-height: 1.3;
    }
    
    .date {
        font-size: clamp(10px, 1.3vw, 14px);
    }
    
    .week-number {
        font-size: clamp(10px, 1.3vw, 14px);
    }
    
    .bottom-info {
        font-size: 10px;
        bottom: calc(10px + var(--safe-bottom));
        left: calc(20px + var(--safe-left));
        right: calc(20px + var(--safe-right));
    }
    
    .bottom-left {
        margin-bottom: 0;
    }
    
    .bottom-right {
        margin-bottom: 0;
    }
}

@media (max-width: 414px) {
    :root { --frame-gap: 8px; --frame-border: 3px; }

    .blue-frame {
        top: calc(8px + var(--safe-top));
        left: calc(8px + var(--safe-left));
        right: calc(8px + var(--safe-right));
        bottom: calc(8px + var(--safe-bottom));
        border-width: 3px;
        padding: 18px;
    }

.clock {
        width: min(75vw, 75vh);
        height: min(75vw, 75vh);
        max-width: 350px;
        max-height: 350px;
    }
    
    .error-text {
        font-size: clamp(14px, 2.5vw, 24px);
        margin-bottom: 4px;
    }
    
    .error-description {
        font-size: clamp(9px, 1.2vw, 12px);
        max-width: 200px;
        line-height: 1.2;
    }
    
    .date {
        font-size: clamp(9px, 1.2vw, 12px);
    }
    
    .week-number {
        font-size: clamp(9px, 1.2vw, 12px);
    }
    
    .bottom-info {
        font-size: 9px;
        bottom: calc(8px + var(--safe-bottom));
        left: calc(18px + var(--safe-left));
        right: calc(18px + var(--safe-right));
    }
}

@media (max-width: 375px) {
    :root { --frame-gap: 6px; --frame-border: 2px; }

    .blue-frame {
        top: calc(6px + var(--safe-top));
        left: calc(6px + var(--safe-left));
        right: calc(6px + var(--safe-right));
        bottom: calc(6px + var(--safe-bottom));
        border-width: 2px;
        padding: 15px;
    }

.clock {
        width: min(70vw, 70vh);
        height: min(70vw, 70vh);
        max-width: 300px;
        max-height: 300px;
    }
    
    .error-text {
        font-size: clamp(12px, 2.2vw, 20px);
        margin-bottom: 3px;
    }
    
    .error-description {
        font-size: clamp(8px, 1.1vw, 10px);
        max-width: 180px;
        line-height: 1.1;
    }
    
    .date {
        font-size: clamp(8px, 1.1vw, 10px);
    }
    
    .week-number {
        font-size: clamp(8px, 1.1vw, 10px);
    }
    
    .bottom-info {
        font-size: 8px;
        bottom: calc(6px + var(--safe-bottom));
        left: calc(15px + var(--safe-left));
        right: calc(15px + var(--safe-right));
    }
}

@keyframes tick {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(6deg); }
}

.second-hand {
    animation: none;
}

.clock-container {
    opacity: 1;
    transform: scale(1);
}

.blue-frame::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--frame-ink), var(--frame-ink-lit), var(--frame-ink));
    z-index: -1;
    border-radius: 2px;
    opacity: var(--frame-wash, 0.3);
}

.theme-half {
    transition: opacity 0.4s ease;
}

.theme-drop {
    fill: var(--tick);
    opacity: 0;
    transform: scale(0);
    transform-origin: 12px 12px;
    transition:
        transform 0.4s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 0.4s ease,
        fill 0.6s ease;
}

.theme-switch.is-paint .theme-half { opacity: 0; }

.theme-switch.is-paint .theme-drop {
    opacity: 1;
    transform: scale(1);
}

@media (prefers-reduced-motion: reduce) {
    .theme-half,
    .theme-drop { transition: none; }
}

svg.logo-svg {
    color: var(--frame-ink);
    filter: none;
    transition: opacity 0.3s ease, color 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
    svg.logo-svg { transition: opacity 0.3s ease; }
}
