:root {
    --frame-line: #bbb0ea;
    --frame-echo: #a68ae04a;
    --frame-glow: #9774d820;
    --frame-radius: 1.3rem;
    --rail-stops: transparent, #bba8f0 22%, #7860bb 50%, #bba8f0 78%, transparent;
    --rail-thickness: 2px;
    --corner-border: 2px solid #beaef2;
    --corner-rounding: 36% 0 0 0;
    --corner-mark: radial-gradient(circle, #f8f2ff 22%, #bc9af4 24% 40%, transparent 45%);
}

:root[data-theme="new-year"] {
    --frame-line: #81c7a2;
    --frame-echo: #b7ffe149;
    --frame-glow: #4aa77a30;
    --frame-radius: 1.15rem;
    --rail-period: 1.1rem;
    --rail-pattern: radial-gradient(circle, #ffeef6 0 12%, #dd537a 15% 23%, transparent 30%);
    --rail-repeat: repeat;
    --corner-border: 2px solid #a9dec4;
    --corner-rounding: 36% 0 0 0;
    --corner-fill: repeating-conic-gradient(from 6deg at 0% 0%, #82c6a44a 0 4deg, transparent 4deg 15deg);
    --corner-mark: repeating-conic-gradient(from 15deg, #f1fff8 0 6deg, transparent 7deg 30deg), #78a8c1;
    --corner-shape: polygon(47% 3%, 53% 3%, 55% 39%, 80% 16%, 84% 20%, 61% 45%, 97% 47%, 97% 53%, 61% 55%, 84% 80%, 80% 84%, 55% 61%, 53% 97%, 47% 97%, 45% 61%, 20% 84%, 16% 80%, 39% 55%, 3% 53%, 3% 47%, 39% 45%, 16% 20%, 20% 16%, 45% 39%);
}

:root[data-theme="ceremony"] {
    --frame-line: #cec6ad;
    --frame-echo: #e7dfc679;
    --frame-glow: #e2ccb01a;
    --frame-radius: .6rem;
    --rail-stops: #d7cdac, #8b8b92 22%, #f2e7ca 50%, #8b8b92 78%, #d7cdac;
    --rail-thickness: 3px;
    --corner-border: 3px double #eee4c9;
    --corner-rounding: 14% 0 0 0;
    --corner-fill: repeating-radial-gradient(circle at 4% 4%, transparent 0 12%, #e8dfc68c 13% 14%, transparent 15% 22%);
    --corner-mark: linear-gradient(135deg, #fff5d8, #968a69);
    --corner-shape: polygon(50% 12%, 68% 32%, 88% 50%, 68% 68%, 50% 88%, 32% 68%, 12% 50%, 32% 32%);
}

:root[data-theme="business"] {
    --frame-line: #71acb2;
    --frame-echo: #459a9e65;
    --frame-glow: #3b9d951b;
    --frame-radius: .2rem;
    --rail-stops: #74b9bc 0 7px, transparent 7px 10px, #74b9bc70 10px 12px, transparent 12px 19px;
    --rail-thickness: 3px;
    --corner-border: 3px solid #8cc9c9;
    --corner-rounding: 0;
    --corner-fill: repeating-linear-gradient(90deg, transparent 0 7px, #89c3c920 7px 8px),
        repeating-linear-gradient(0deg, transparent 0 7px, #89c3c920 7px 8px);
    --corner-mark: linear-gradient(135deg, #d5faff, #4a9daf);
    --corner-shape: polygon(8% 8%, 73% 8%, 73% 23%, 28% 23%, 28% 73%, 73% 73%, 73% 88%, 8% 88%);
}

:root[data-theme="conference"] {
    --frame-line: #709feb;
    --frame-echo: #61d5fb78;
    --frame-glow: #4997fc35;
    --frame-radius: .9rem;
    --rail-stops: #9eeaff 0%, #396ec1 18%, #589bec 50%, #396ec1 82%, #9eeaff 100%;
    --rail-thickness: 5px;
    --corner-border: 1px solid #99e9ff;
    --corner-rounding: 27% 0 0 0;
    --corner-fill: conic-gradient(from 105deg at 7% 7%, transparent, #60bbff14 7deg, #9bffffa6 27deg, #388eff10 45deg, transparent 62deg);
    --corner-mark: radial-gradient(circle at 35% 35%, #e6ffff, #48b6ff 20%, transparent 42%);
}

:root[data-theme="birthday"] {
    --frame-line: #e58ba8;
    --frame-echo: #ffabb85e;
    --frame-glow: #e0547f26;
    --frame-radius: 1.75rem;
    --rail-stops: #ff8fac 0 9px, transparent 9px 13px, #ffcaab 13px 20px,
        transparent 20px 25px, #d9b2fc 25px 31px, transparent 31px 38px, #9bd6cc 38px 44px, transparent 44px 53px;
    --rail-thickness: 5px;
    --corner-border: 1px dashed #ffd3e2;
    --corner-rounding: 50% 0 0 0;
    --corner-fill: radial-gradient(ellipse at 42% 34%, #ff9bac 0 13%, #df5277 14% 23%, transparent 25%),
        radial-gradient(ellipse at 72% 54%, #ffceb3 0 12%, #df876e 13% 20%, transparent 22%);
    --corner-mark: radial-gradient(ellipse at 30% 25%, #fbcffa 8%, #a67bd1 47%, transparent 50%);
}

:root[data-theme="school"] {
    --frame-line: #b69cdf;
    --frame-echo: #bcbdf176;
    --frame-glow: #947ad324;
    --frame-radius: .7rem;
    --rail-stops: #ba9de6 0 2px, transparent 2px 6px, #b8e4ed 6px 8px,
        transparent 8px 13px, #f4aac5 13px 15px, transparent 15px 20px;
    --rail-thickness: 6px;
    --corner-border: 2px dashed #cdb3f3;
    --corner-rounding: 12% 0 0 0;
    --corner-fill: repeating-linear-gradient(0deg, #b4a1f425 0 1px, transparent 1px 6px),
        repeating-linear-gradient(90deg, #b4a1f425 0 1px, transparent 1px 6px);
    --corner-mark: linear-gradient(145deg, #ffd8a1 0 24%, #ee9fc2 25% 44%, #a2dcf1 45% 65%, #d5b9ff 66% 100%);
    --corner-shape: polygon(50% 0, 62% 36%, 100% 38%, 69% 61%, 80% 99%, 50% 76%, 20% 99%, 31% 61%, 0 38%, 38% 36%);
}

:root[data-theme="gala"] {
    --frame-line: #cca6c9;
    --frame-echo: #f0cdeb78;
    --frame-glow: #e2a4d826;
    --frame-radius: .35rem;
    --rail-stops: #e2bfde 0 18px, #776389 18px 20px, #efcee8 20px 22px, #776389 22px 24px;
    --rail-thickness: 3px;
    --corner-border: 3px double #f1cee9;
    --corner-rounding: 0;
    --corner-fill: repeating-conic-gradient(from 4deg at 1% 1%, transparent 0 7deg, #d8afd59c 7deg 9deg, transparent 9deg 15deg);
    --corner-mark: linear-gradient(145deg, #f6def2, #c49cbb 56%, #f6def2 80%);
    --corner-shape: polygon(0 5%, 10% 5%, 10% 88%, 94% 88%, 94% 98%, 0 98%, 0 5%, 22% 5%, 28% 5%, 28% 70%, 94% 70%, 94% 76%, 22% 76%);
}

:root[data-theme="summer"] {
    --frame-line: #8cddbb;
    --frame-echo: #ffd1aa77;
    --frame-glow: #73d5ad27;
    --frame-radius: 1.8rem;
    --rail-stops: #9aebd0 0 11px, #a9e1eb 11px 20px, #ffc7a6 20px 28px, transparent 28px 33px;
    --rail-thickness: 5px;
    --corner-border: 2px dashed #bcebd4;
    --corner-rounding: 62% 0 0 0;
    --corner-fill: repeating-radial-gradient(ellipse at 0 0, transparent 0 9%, #9ce8d190 10% 11%, transparent 12% 19%);
    --corner-mark: radial-gradient(circle, #ffcf95 0 34%, transparent 35%),
        repeating-conic-gradient(#ffbd8e 0 8deg, transparent 8deg 26deg);
    --corner-shape: circle(48%);
}

:root[data-theme="sports"] {
    --frame-line: #b7d88e;
    --frame-echo: #b9e39072;
    --frame-glow: #96ce6530;
    --frame-radius: .15rem;
    --rail-stops: #d9f3c1 0 5px, #34532e 5px 10px, #b7dd89 10px 15px, #263c26 15px 20px;
    --rail-thickness: 6px;
    --corner-border: 2px solid #d5f4b4;
    --corner-rounding: 0;
    --corner-fill: repeating-linear-gradient(135deg, transparent 0 7px, #cae99e66 7px 9px, transparent 9px 13px);
    --corner-mark: conic-gradient(#ddefd1 0 25%, #3b5237 0 50%, #ddefd1 0 75%, #3b5237 0);
    --corner-shape: polygon(18% 0, 100% 0, 82% 100%, 0 100%);
}

:root[data-theme="chukotka"] {
    --frame-line: #79a7a9;
    --frame-echo: #bbe7df4d;
    --frame-glow: #7be4cc24;
    --frame-radius: .65rem;
    --rail-period: 1rem;
    --rail-pattern: conic-gradient(from 45deg, transparent 0 25%, #83d0c0 25% 50%, transparent 50% 75%, #e8ca90 75%);
    --rail-repeat: repeat;
    --rail-thickness: 4px;
    --corner-border: 3px double #73c9bd;
    --corner-rounding: 0;
    --corner-mark: linear-gradient(145deg, #f9ddaa, #67b4af);
    --corner-shape: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

body:is([data-mode="vote"], [data-mode="screen"]) {
    --frame-space: .56rem;
    --frame-inset: 3px;
    --frame-corner-size: clamp(1.05rem, 3.2vw, 2.45rem);
    --rail-scale: .65;
    padding: var(--frame-space);
}
body[data-mode="screen"] {
    --frame-space: clamp(.85rem, 1.68vw, 1.9rem);
    --frame-inset: clamp(5px, .7vw, 12px);
    --frame-corner-size: clamp(2rem, 4.65vw, 5rem);
    --rail-scale: 1;
}
[data-mode="screen"] main { margin-block: clamp(.85rem, 1.6vw, 1.5rem) .6rem; }

.event-frame {
    position: fixed;
    z-index: 20;
    inset: var(--frame-inset);
    overflow: hidden;
    pointer-events: none;
    border: 1px solid var(--frame-line);
    border-radius: var(--frame-radius);
    box-shadow: 0 0 0 1px var(--frame-echo), 0 0 22px var(--frame-glow) inset;
}
.event-frame::before {
    position: absolute;
    inset: calc(3px * var(--rail-scale));
    border: 1px solid var(--frame-echo);
    border-radius: inherit;
    content: "";
}
[data-mode="host"] .event-frame { display: none; }
.frame-rail {
    position: absolute;
    --rail-direction: 90deg;
    background-image: var(--rail-pattern, repeating-linear-gradient(var(--rail-direction), var(--rail-stops)));
    background-position: center;
    background-size: var(--rail-period, 100%) 100%;
    background-repeat: var(--rail-repeat, no-repeat);
}
.frame-top, .frame-bottom {
    inset-inline: max(1.1rem, var(--frame-corner-size));
    height: calc(var(--rail-thickness) * var(--rail-scale));
}
.frame-top { top: 4px; }
.frame-bottom { bottom: 4px; }
.frame-left, .frame-right {
    --rail-direction: 0deg;
    inset-block: max(1.1rem, var(--frame-corner-size));
    width: calc(var(--rail-thickness) * var(--rail-scale));
    background-size: 100% var(--rail-period, 100%);
}
.frame-left { left: 4px; }
.frame-right { right: 4px; }
.frame-corner {
    position: absolute;
    width: var(--frame-corner-size);
    aspect-ratio: 1;
    color: var(--frame-line);
}
.frame-top-left { top: 0; left: 0; }
.frame-top-right { top: 0; right: 0; transform: rotate(90deg); }
.frame-bottom-right { bottom: 0; right: 0; transform: rotate(180deg); }
.frame-bottom-left { bottom: 0; left: 0; transform: rotate(270deg); }
.frame-corner::before, .frame-corner::after { position: absolute; content: ""; }
.frame-corner::before {
    inset: 9% 0 0 9%;
    border: var(--corner-border);
    border-right: 0;
    border-bottom: 0;
    border-radius: var(--corner-rounding);
    background: var(--corner-fill, none);
    mask-image: radial-gradient(ellipse at top left, #000 0 42%, transparent 76%);
}
.frame-corner::after {
    inset: 19% 34% 34% 19%;
    background: var(--corner-mark);
    clip-path: var(--corner-shape, none);
}

:root[data-theme="new-year"] .frame-rail {
    height: calc(10px * var(--rail-scale));
}
:root[data-theme="new-year"] :is(.frame-left, .frame-right) {
    height: auto;
    width: calc(10px * var(--rail-scale));
}
:root[data-theme="new-year"] .frame-rail:nth-child(even) {
    --rail-pattern: radial-gradient(circle, #f4fff9 0 12%, #83e4b7 15% 23%, transparent 30%);
}
:root[data-theme="conference"] .frame-corner::before { mask-image: none; }
:root[data-theme="birthday"] .frame-corner::before { mask-image: radial-gradient(ellipse at top left, #000 0 68%, transparent 90%); }

@media (max-width: 35rem) {
    body[data-mode="screen"] { --frame-space: .65rem; --frame-corner-size: 1.65rem; }
    .frame-corner::before { border-width: 1px; }
}
