:root {
    color-scheme: dark;
    --circus-ink: #281c2a;
    --circus-panel: #53313c;
    --circus-edge: #241923;
    --circus-cream: #fff0c7;
    --circus-gold: #f5c273;
    --circus-orange: #be5144;
    --circus-safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px), var(--circus-runtime-safe-top, 0px));
    --circus-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px), var(--circus-runtime-safe-bottom, 0px));
    --circus-safe-left: max(env(safe-area-inset-left, 0px), var(--circus-runtime-safe-left, 0px));
    --circus-safe-right: max(env(safe-area-inset-right, 0px), var(--circus-runtime-safe-right, 0px));
}

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

html {
    min-width: 0;
    background: var(--circus-ink);
}

body {
    min-width: 0;
    min-height: 100dvh;
    margin: 0;
    overflow-x: hidden;
    background: var(--circus-ink);
    color: var(--circus-cream);
    font-family: ui-monospace, "Cascadia Mono", "Courier New", monospace;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    font: inherit;
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid var(--circus-cream);
    outline-offset: 3px;
}

[hidden] {
    display: none !important;
}

.circus-shell {
    display: flex;
    min-height: 100dvh;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    gap: 0.65rem;
    padding:
        calc(0.75rem + var(--circus-safe-top))
        max(0.75rem, var(--circus-safe-right))
        calc(0.75rem + var(--circus-safe-bottom))
        max(0.75rem, var(--circus-safe-left));
}

.circus-header {
    display: flex;
    width: min(100%, 27rem);
    min-height: 2.75rem;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.circus-back {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    color: var(--circus-cream);
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
}

.circus-header__label,
.circus-hint {
    color: var(--circus-gold);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.circus-machine {
    width: min(100%, 27rem, max(12rem, calc((100svh - 12.75rem - var(--circus-safe-top) - var(--circus-safe-bottom)) * 0.75)));
    border: 4px solid var(--circus-edge);
    background: var(--circus-panel);
    box-shadow: 0 0 0 2px #a44a44, 6px 7px 0 #1b1420;
}

.circus-marquee {
    display: flex;
    height: 2.6rem;
    align-items: center;
    justify-content: center;
    border-bottom: 3px solid var(--circus-edge);
    background: #73333d;
}

.circus-marquee img {
    display: block;
    width: auto;
    max-width: 90%;
    height: 2rem;
    image-rendering: pixelated;
}

.circus-hud {
    display: flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-bottom: 3px solid var(--circus-edge);
    background: #4b3039;
}

.circus-hud__scores {
    display: flex;
    min-width: 0;
    flex-wrap: wrap;
    column-gap: 0.75rem;
    color: var(--circus-cream);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.4;
}

.circus-hud__scores strong {
    color: var(--circus-gold);
    font-size: 1.05em;
}

.circus-hud__controls {
    display: flex;
    flex-shrink: 0;
    gap: 0.3rem;
}

.circus-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background: #30232f;
}

.circus-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    touch-action: none;
}

.circus-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    gap: clamp(0.35rem, 1.6vh, 0.7rem);
    padding: 0.55rem;
    background: rgb(36 23 35 / 0.81);
    text-align: center;
}

.circus-screen__eyebrow {
    color: var(--circus-gold);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.circus-screen h1,
.circus-screen h2 {
    margin: 0;
    color: var(--circus-cream);
    font-size: clamp(1.75rem, 8vw, 3rem);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 0.95;
    text-shadow: 3px 3px 0 #95502e;
}

.circus-screen__logo img {
    display: block;
    width: min(100%, 12.75rem);
    height: auto;
    margin-inline: auto;
    image-rendering: pixelated;
}

.circus-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.circus-screen p {
    max-width: 16rem;
    margin: 0;
    font-size: clamp(0.65rem, 2.4vw, 0.85rem);
    line-height: 1.5;
}

.circus-screen__result {
    line-height: 1.8 !important;
}

.circus-screen__result strong {
    color: var(--circus-gold);
}

.circus-button {
    min-width: min(100%, 10rem);
    min-height: 2.75rem;
    padding: 0.55rem 0.9rem;
    border: 2px solid #673029;
    border-radius: 0;
    background: var(--circus-orange);
    box-shadow: 3px 3px 0 #261b25;
    color: #fff4d5;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 900;
    text-transform: uppercase;
}

.circus-button:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #261b25;
}

a.circus-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.circus-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.circus-button--icon {
    display: inline-flex;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.circus-button--icon svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.circus-button--secondary {
    border-color: #3d2931;
    background: #78524e;
}

.circus-hint,
.circus-status {
    width: min(100%, 27rem);
    margin: 0;
    text-align: center;
}

.circus-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.circus-save-status {
    color: var(--circus-gold);
    font-size: 0.65rem !important;
}

[data-circus-best-label] {
    text-transform: uppercase;
}

@media (max-height: 36rem) {
    .circus-shell {
        gap: 0.3rem;
        padding-block: calc(0.3rem + var(--circus-safe-top)) calc(0.3rem + var(--circus-safe-bottom));
    }

    .circus-hint {
        display: none;
    }
}
