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

:root {
    --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --sky-top: #4ea5f2;
    --sky-bottom: #cfe8ff;
    --sun-core: #fff6c2;
    --sun-edge: #ffb300;
    --glow-color: rgba(255, 140, 90, .85);
    --sun-x: .5;
    --sun-y: .3;
    --moon-x: .5;
    --moon-y: .3;
    --moon-o: 0;
    --moon-turn: 0deg;
    --glow-x: .5;
    --glow-o: 0;
    --stars-o: 0;
}

/* Палитры времени суток для облаков, моря и природы */
body[data-period="morning"] {
    --ink: #40281f;
    --glass: rgba(255, 255, 255, .45);
    --cloud: #fff4ea;
    --sea1: #5d9cc4;
    --sea2: #4686b1;
    --sea3: #33709b;
    --hill-far: #9cc68a;
    --hill-near: #6aa35a;
    --tree: #3e7a3c;
    --trunk: #6b4a2e;
}

body[data-period="day"] {
    --ink: #0f2f4d;
    --glass: rgba(255, 255, 255, .45);
    --cloud: #ffffff;
    --sea1: #3a9bd5;
    --sea2: #2a84c0;
    --sea3: #1c6ca5;
    --hill-far: #a3d16b;
    --hill-near: #6caf4b;
    --tree: #2f7d32;
    --trunk: #6b4a2e;
}

body[data-period="evening"] {
    --ink: #fff7f0;
    --glass: rgba(30, 20, 50, .35);
    --cloud: #f5c1b0;
    --sea1: #6a5a9c;
    --sea2: #54467f;
    --sea3: #3e3466;
    --hill-far: #6e6a8c;
    --hill-near: #4f4b6c;
    --tree: #36334f;
    --trunk: #2b2840;
}

body[data-period="night"] {
    --ink: #e7f0ff;
    --glass: rgba(0, 0, 0, .35);
    --cloud: #34466b;
    --sea1: #142b4d;
    --sea2: #0e2242;
    --sea3: #091a33;
    --hill-far: #1e3838;
    --hill-near: #142c28;
    --tree: #0d211d;
    --trunk: #0b1a17;
}

/* Утром и вечером небо бывает и тёмным, и светлым — тон текста следует за высотой солнца */
body[data-period="morning"][data-ink="light"]:not([data-theme="cartoon"]) {
    --ink: #fff7f0;
    --glass: rgba(30, 20, 50, .35);
}

body[data-period="evening"][data-ink="dark"]:not([data-theme="cartoon"]) {
    --ink: #0f2f4d;
    --glass: rgba(255, 255, 255, .45);
}

/* Мульт живёт в своих ярких красках, ночью — в фиолетовых */
body[data-theme="cartoon"] {
    --ink: #ffffff;
    --outline: #2b2d42;
    --glass: rgba(255, 255, 255, .6);
    --control-ink: #2b2d42;
    --glow-color: rgba(255, 159, 176, .9);
}

body[data-theme="cartoon"][data-ink="light"] {
    --outline: #1a1238;
    --glass: rgba(255, 255, 255, .25);
    --control-ink: #ffffff;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    overflow: hidden;
    font-family: var(--font);
    color: var(--ink);
    background: var(--sky-bottom);
    transition: color 1.5s ease;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Сцена ---------- */

.scene {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.sky {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
    transition: background 1.5s ease;
}

.stars {
    position: absolute;
    inset: 0 0 35% 0;
    opacity: var(--stars-o);
    transition: opacity 2s ease;
}

.stars span {
    position: absolute;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: #fff;
    animation: twinkle 3s ease-in-out infinite;
}

.glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 45% 28% at calc(var(--glow-x) * 100%) calc(var(--horizon) * 100%), var(--glow-color), transparent 70%);
    opacity: var(--glow-o);
    transition: opacity 1.5s ease;
}

.heavens {
    position: absolute;
    inset: 0;
    bottom: calc((1 - var(--horizon)) * 100%);
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 96%, transparent);
    mask-image: linear-gradient(to bottom, #000 96%, transparent);
}

.luminary {
    position: absolute;
    left: calc(var(--x) * 100%);
    top: calc(var(--y) / var(--horizon) * 100%);
    width: clamp(56px, 9vw, 120px);
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    transition: left 1s linear, top 1s linear;
}

.sun {
    --x: var(--sun-x);
    --y: var(--sun-y);
    border-radius: 50%;
    background: radial-gradient(circle, var(--sun-core) 0 35%, var(--sun-edge) 100%);
    box-shadow: 0 0 60px 20px rgba(255, 210, 80, .55);
}

.moon {
    --x: var(--moon-x);
    --y: var(--moon-y);
    overflow: visible;
    opacity: var(--moon-o);
    transform: translate(-50%, -50%) rotate(var(--moon-turn));
    filter: drop-shadow(0 0 18px rgba(244, 241, 222, .45));
    transition: opacity 2s ease, left 1s linear, top 1s linear;
}

.moon-dark {
    fill: rgba(255, 255, 255, .07);
}

.moon-lit {
    fill: #f4f1de;
}

.layer {
    display: none;
    position: absolute;
    inset: 0;
}

body[data-theme="clouds"] .layer--clouds,
body[data-theme="sea"] .layer--sea,
body[data-theme="nature"] .layer--nature,
body[data-theme="cartoon"] .layer--cartoon {
    display: block;
}

/* ---------- Облака ---------- */

.cloud {
    position: absolute;
    left: 0;
    width: var(--w);
    height: calc(var(--w) * .32);
    background: var(--cloud);
    border-radius: 999px;
    opacity: .92;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .08));
    animation: drift var(--t) linear infinite;
    animation-delay: var(--d);
    transition: background 1.5s ease;
}

.cloud::before, .cloud::after {
    content: "";
    position: absolute;
    background: inherit;
    border-radius: 50%;
}

.cloud::before {
    width: 50%;
    aspect-ratio: 1;
    left: 14%;
    bottom: 30%;
}

.cloud::after {
    width: 36%;
    aspect-ratio: 1;
    left: 48%;
    bottom: 22%;
}

.c1 {
    --w: 260px;
    --t: 90s;
    --d: -10s;
    top: 12%;
}

.c2 {
    --w: 180px;
    --t: 70s;
    --d: -45s;
    top: 30%;
    opacity: .8;
}

.c3 {
    --w: 340px;
    --t: 120s;
    --d: -80s;
    top: 62%;
}

.c4 {
    --w: 140px;
    --t: 60s;
    --d: -25s;
    top: 78%;
    opacity: .75;
}

.c5 {
    --w: 220px;
    --t: 100s;
    --d: -60s;
    top: 46%;
    opacity: .85;
}

/* ---------- Море ---------- */

.layer--sea {
    top: auto;
    height: 30vh;
}

.wave {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 200%;
    animation: roll var(--t) linear infinite;
}

.wave path {
    transition: fill 1.5s ease;
}

.w1 {
    height: 100%;
    --t: 22s;
}

.w1 path {
    fill: var(--sea1);
}

.w2 {
    height: 74%;
    --t: 15s;
    animation-direction: reverse;
}

.w2 path {
    fill: var(--sea2);
}

.w3 {
    height: 48%;
    --t: 10s;
}

.w3 path {
    fill: var(--sea3);
}

.sail {
    position: absolute;
    bottom: 62%;
    left: 0;
    width: 0;
    height: 0;
    border-left: 18px solid transparent;
    border-right: 18px solid transparent;
    border-bottom: 44px solid #fdfdfd;
    animation: sail 140s linear infinite, bob 4s ease-in-out infinite;
}

.sail::after {
    content: "";
    position: absolute;
    top: 44px;
    left: -26px;
    width: 52px;
    height: 12px;
    background: #8b5a3c;
    border-radius: 0 0 26px 26px;
}

/* ---------- Природа ---------- */

.hills {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
}

.hills path {
    transition: fill 1.5s ease;
}

.hills.far {
    height: 42vh;
}

.hills.far path {
    fill: var(--hill-far);
}

.hills.near {
    height: 30vh;
}

.hills.near path {
    fill: var(--hill-near);
}

.tree {
    position: absolute;
    width: var(--s);
    height: calc(var(--s) * 1.6);
    transform-origin: 50% 100%;
    animation: sway 6s ease-in-out infinite;
    animation-delay: var(--d);
}

.tree::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 75%;
    background: var(--tree);
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
    transition: background 1.5s ease;
}

.tree::after {
    content: "";
    position: absolute;
    left: 42%;
    bottom: 0;
    width: 16%;
    height: 28%;
    background: var(--trunk);
    border-radius: 2px;
}

.t1 {
    --s: 70px;
    --d: 0s;
    left: 6%;
    bottom: 17vh;
}

.t2 {
    --s: 46px;
    --d: -1.5s;
    left: 13%;
    bottom: 19vh;
}

.t3 {
    --s: 90px;
    --d: -3s;
    left: 72%;
    bottom: 14vh;
}

.t4 {
    --s: 58px;
    --d: -4.5s;
    left: 81%;
    bottom: 17vh;
}

.t5 {
    --s: 40px;
    --d: -2s;
    left: 88%;
    bottom: 20vh;
}

/* ---------- Мульт ---------- */

.blob {
    position: absolute;
    border-radius: 50%;
    width: var(--s);
    aspect-ratio: 1;
    background: var(--c);
    border: 5px solid var(--outline);
    animation: float var(--t) ease-in-out infinite;
}

.b1 {
    --s: 180px;
    --c: #ff6b6b;
    --t: 9s;
    left: -40px;
    bottom: 8%;
}

.b2 {
    --s: 120px;
    --c: #6bcb77;
    --t: 7s;
    right: 6%;
    top: 10%;
}

.b3 {
    --s: 90px;
    --c: #ffd93d;
    --t: 11s;
    right: 18%;
    bottom: 14%;
}

.spark {
    position: absolute;
    font-size: var(--s);
    color: #fff;
    -webkit-text-stroke: 2px var(--outline);
    animation: spin 8s linear infinite, twinkle 2.4s ease-in-out infinite;
}

.s1 {
    --s: 44px;
    left: 12%;
    top: 16%;
}

.s2 {
    --s: 30px;
    left: 30%;
    top: 70%;
    animation-delay: -1s;
}

.s3 {
    --s: 36px;
    left: 82%;
    top: 52%;
    animation-delay: -2s;
}

.s4 {
    --s: 26px;
    left: 58%;
    top: 12%;
    animation-delay: -3s;
}

body[data-theme="cartoon"] .sun {
    background: #ffd93d;
    border: 5px solid var(--outline);
    box-shadow: 0 0 0 10px rgba(255, 217, 61, .35);
}

body[data-theme="cartoon"] .moon {
    filter: none;
}

body[data-theme="cartoon"] .moon-dark {
    fill: rgba(255, 255, 255, .15);
    stroke: var(--outline);
    stroke-width: 4;
}

body[data-theme="cartoon"] .moon-lit {
    fill: #fff6d6;
    stroke: var(--outline);
    stroke-width: 4;
    stroke-linejoin: round;
}

/* ---------- Часы ---------- */

.clock {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 0 16px;
    margin-bottom: 8vh;
}

.time {
    display: inline-flex;
    align-items: baseline;
    font-size: clamp(4.5rem, 19vw, 15rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 24px rgba(0, 0, 0, .18);
}

.sec {
    font-size: .32em;
    margin-left: .25em;
    opacity: .8;
    min-width: 2ch;
    text-align: left;
}

.date {
    margin: .4em 0 0;
    font-size: clamp(1.1rem, 3.4vw, 2rem);
    font-weight: 600;
}

.date::first-letter {
    text-transform: uppercase;
}

.zone {
    display: inline-block;
    margin: .3em 0 0;
}

.zone select {
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    font-size: clamp(.85rem, 2.2vw, 1.1rem);
    color: inherit;
    max-width: calc(100vw - 32px);
    padding: 4px 26px 4px 10px;
    border: 0;
    border-radius: 999px;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center / 10px;
    opacity: .8;
    cursor: pointer;
    text-align: center;
}

.zone select:hover, .zone select:focus-visible {
    background-color: var(--glass);
    opacity: 1;
    outline: none;
}

.zone option {
    color: #10243a;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Круглые часы ---------- */

.dial {
    display: none;
    width: min(68vmin, 460px);
    height: auto;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, .18));
}

body[data-face="analog"] .dial {
    display: block;
    margin: 0 auto;
}

body[data-face="analog"] .time {
    display: none;
}

.dial-face {
    fill: var(--dial-face, rgba(255, 255, 255, .55));
    stroke: var(--ink);
    stroke-width: 3;
    transition: fill 1.5s ease;
}

.dial-ticks line {
    stroke: var(--ink);
    stroke-linecap: round;
}

.dial-ticks .major {
    stroke-width: 3.2;
}

.dial-ticks .minor {
    stroke-width: 1.2;
    opacity: .6;
}

.dial-numbers text {
    fill: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: central;
}

.hand {
    stroke: var(--ink);
    stroke-linecap: round;
}

.hand-hour {
    stroke-width: 7;
}

.hand-minute {
    stroke-width: 4.5;
}

.hand-second {
    stroke: #e63946;
    stroke-width: 1.8;
}

.dial-pin {
    fill: #e63946;
    stroke: var(--ink);
    stroke-width: 1.5;
}

body[data-ink="light"] {
    --dial-face: rgba(10, 15, 35, .35);
}

body[data-theme="cartoon"] {
    --dial-face: #ffffff;
}

body[data-theme="cartoon"] .dial-face {
    stroke: var(--outline);
    stroke-width: 6;
}

body[data-theme="cartoon"] .dial-ticks line,
body[data-theme="cartoon"] .dial-numbers text {
    stroke: none;
    fill: var(--outline);
}

body[data-theme="cartoon"] .dial-ticks line {
    stroke: var(--outline);
}

body[data-theme="cartoon"] .dial-numbers text {
    font-weight: 900;
    font-size: 17px;
}

body[data-theme="cartoon"] .hand-hour {
    stroke: #ff6b6b;
}

body[data-theme="cartoon"] .hand-minute {
    stroke: #4d96ff;
}

body[data-theme="cartoon"] .hand-second {
    stroke: var(--outline);
}

body[data-theme="cartoon"] .hand {
    filter: drop-shadow(1.5px 1.5px 0 var(--outline));
}

body[data-theme="cartoon"] .dial-pin {
    fill: #ffd93d;
    stroke: var(--outline);
    stroke-width: 3;
}

body[data-theme="cartoon"] .time {
    font-weight: 900;
    -webkit-text-stroke: .035em var(--outline);
    paint-order: stroke fill;
    text-shadow: .06em .06em 0 var(--outline);
}

body[data-theme="cartoon"] .sec {
    display: inline-block;
    opacity: 1;
}

body[data-theme="cartoon"] .sec.tick {
    animation: pop .35s ease-out;
}

body[data-theme="cartoon"] .date {
    -webkit-text-stroke: 1px var(--outline);
    paint-order: stroke fill;
    text-shadow: 2px 2px 0 var(--outline);
}

body[data-theme="cartoon"] .zone select {
    color: var(--outline);
    font-weight: 700;
}

body[data-theme="cartoon"][data-ink="light"] .zone select {
    color: #fff;
}

/* ---------- Переключатели ---------- */

.controls {
    position: fixed;
    z-index: 2;
    left: 0;
    right: 0;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: fit-content;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px;
    max-width: calc(100vw - 32px);
    border-radius: 999px;
    color: var(--control-ink, var(--ink));
    background: var(--glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    transition: opacity .6s ease, background 1.5s ease;
}

.themes, .faces {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.faces {
    padding-left: 8px;
    border-left: 1px solid rgba(127, 127, 127, .35);
}

.icon {
    width: 1.2em;
    height: 1.2em;
    display: block;
}

.controls button {
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    transition: background .2s ease;
}

.controls button:hover {
    background: rgba(255, 255, 255, .25);
}

.controls button[aria-checked="true"] {
    background: rgba(255, 255, 255, .6);
    color: #10243a;
}

.controls button:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

.fullscreen {
    font-size: 1.2rem !important;
    padding: 8px 12px !important;
}

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .2);
}

[data-set-theme="clouds"] .swatch {
    background: linear-gradient(#4ea5f2, #fff);
}

[data-set-theme="sea"] .swatch {
    background: linear-gradient(#cfe8ff 45%, #1c6ca5 55%);
}

[data-set-theme="nature"] .swatch {
    background: linear-gradient(#cfe8ff 45%, #6caf4b 55%);
}

[data-set-theme="cartoon"] .swatch {
    background: conic-gradient(#ff6b6b, #ffd93d, #6bcb77, #7bdff2, #ff6b6b);
}

/* Без движения мыши часы становятся «чистыми», как на экране ТВ */
body.idle {
    cursor: none;
}

body.idle .controls {
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 560px) {
    .controls {
        border-radius: 24px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .faces {
        border-left: 0;
        padding-left: 0;
    }

    .controls button {
        padding: 7px 10px;
        font-size: .88rem;
    }

    .c1 {
        --w: 180px;
    }

    .c3 {
        --w: 220px;
    }

    .b1 {
        --s: 120px;
    }

    .b2 {
        --s: 80px;
    }
}

/* ---------- Анимации ---------- */

@keyframes drift {
    from {
        transform: translateX(-40vw);
    }
    to {
        transform: translateX(120vw);
    }
}

@keyframes roll {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-50%);
    }
}

@keyframes sail {
    from {
        left: -60px;
    }
    to {
        left: calc(100% + 60px);
    }
}

@keyframes bob {
    0%, 100% {
        transform: translateY(0) rotate(-3deg);
    }
    50% {
        transform: translateY(6px) rotate(3deg);
    }
}

@keyframes sway {
    0%, 100% {
        transform: rotate(-1.5deg);
    }
    50% {
        transform: rotate(1.5deg);
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-24px) scale(1.04);
    }
}

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

@keyframes twinkle {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: .35;
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    40% {
        transform: scale(1.25) rotate(-6deg);
    }
    100% {
        transform: scale(1);
    }
}

/* Первая отрисовка без плавных переходов, иначе страница секунду показывает дневные цвета */
body.booting, body.booting *, body.booting *::before, body.booting *::after {
    transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
