body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(255, 153, 0, 0.2), transparent 30%),
        radial-gradient(circle at 80% 20%, rgba(0, 212, 170, 0.16), transparent 28%),
        linear-gradient(160deg, #121212 0%, #1d1d1d 48%, #111111 100%);
    color: #f4efe7;
    font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
    touch-action: none;
}

body {
    display: flex;
    flex-direction: column;
    position: relative;
}

body::before,
body::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    pointer-events: none;
}

body::before {
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0, rgba(255, 255, 255, 0.025) 1px, transparent 1px, transparent 72px),
        linear-gradient(rgba(255, 255, 255, 0.018) 0, rgba(255, 255, 255, 0.018) 1px, transparent 1px, transparent 72px);
    opacity: 0.35;
}

body::after {
    background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.32) 100%);
}

.controlApp {
    min-height: 100%;
}

.appShell {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    padding: 18px;
    gap: 16px;
}

#header {
    background:
        linear-gradient(135deg, rgba(30, 30, 30, 0.94), rgba(18, 18, 18, 0.9)),
        linear-gradient(90deg, rgba(255, 153, 0, 0.12), rgba(0, 212, 170, 0.12));
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 18px 20px;
    box-sizing: border-box;
    gap: 18px;
    flex-wrap: wrap;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px);
}

.headerMain {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.appIconBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 88px;
    height: 88px;
    flex: 0 0 88px;
    border-radius: 50%;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.appIcon {
    width: 88%;
    height: 88%;
    object-fit: contain;
}

.headerCopy {
    max-width: 520px;
    min-width: 0;
}

.eyebrow {
    font-size: 10px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: #ffb347;
    margin-bottom: 7px;
}

.headerCopy h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1;
    letter-spacing: 0.02em;
}

.headerCopy p {
    margin: 8px 0 0;
    max-width: 38ch;
    color: rgba(244, 239, 231, 0.76);
    font-size: 14px;
    line-height: 1.4;
}

.headerActions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto;
    align-content: center;
}

.backToAppsButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.84);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-decoration: none;
    box-sizing: border-box;
}

.backToAppsButton:focus {
    outline: 3px solid rgba(255, 179, 71, 0.75);
    outline-offset: 3px;
}

.controlBar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.controlBarActions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

#colorPicker {
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    cursor: pointer;
    background: transparent;
}

#clearButton {
    background: linear-gradient(135deg, #f25f4c, #d9482f);
    color: white;
    border: none;
    padding: 9px 13px;
    border-radius: 999px;
    font-weight: bold;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(242, 95, 76, 0.24);
}

.secondaryButton {
    background: linear-gradient(135deg, #00b894, #008f79);
    color: white;
    border: none;
    padding: 9px 13px;
    border-radius: 999px;
    font-weight: bold;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0, 184, 148, 0.2);
}

.colorDock,
.sprayDock,
#clearButton,
.secondaryButton,
#commsInfoDiv {
    min-height: 40px;
}

.colorDock,
.sprayDock,
#clearButton,
.secondaryButton {
    transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease, background 140ms ease;
}

.colorDock:active,
.sprayDock:active,
#clearButton:active,
.secondaryButton:active {
    transform: translateY(1px) scale(0.99);
}

.secondaryButton:disabled {
    opacity: 0.48;
    cursor: default;
    box-shadow: none;
}

.hiddenControl {
    display: none;
}

.colorDock {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 5px 8px 5px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f8f3eb;
    font-size: 11px;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.sprayDock {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 158px;
    padding: 5px 10px 5px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f8f3eb;
    font-size: 11px;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    box-sizing: border-box;
}

#sprayWidth {
    width: 74px;
    height: 26px;
    margin: 0;
}

#sprayWidthValue {
    min-width: 35px;
    color: rgba(248, 243, 235, 0.72);
    font-size: 10px;
    letter-spacing: 0.04em;
    text-align: right;
}

#commsInfoDiv {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 10px;
    font-size: 10px;
    margin-left: 2px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.84);
    min-height: 30px;
}

#commsInfo {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    letter-spacing: 0.04em;
}

.statusDot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffb347;
    box-shadow: 0 0 16px rgba(255, 179, 71, 0.8);
}

.statusDot.statusDotConnected {
    background: #20d66b;
    box-shadow: 0 0 16px rgba(32, 214, 107, 0.8);
}

.statusDot.statusDotDisconnected {
    background: #ff4f4f;
    box-shadow: 0 0 16px rgba(255, 79, 79, 0.8);
}

#drawContainer {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.stageFrame {
    position: relative;
    width: 100%;
    max-width: 920px;
    height: 100%;
    max-height: 920px;
    width: min(100%, 920px);
    height: min(100%, 920px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    border-radius: 32px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01)),
        rgba(14, 14, 14, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        0 35px 70px rgba(0, 0, 0, 0.38),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    box-sizing: border-box;
}

#drawSurface {
    background:
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.06), transparent 30%),
        radial-gradient(circle at 80% 80%, rgba(255, 179, 71, 0.08), transparent 28%),
        linear-gradient(160deg, #4e4a46, #36322f 46%, #262220 100%);
    position: relative;
    user-select: none;
    touch-action: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    border-radius: 26px;
    overflow: hidden;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        inset 0 -24px 45px rgba(0, 0, 0, 0.22);
}

#drawSurface::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    background:
        linear-gradient(120deg, rgba(255, 255, 255, 0.02), transparent 24%, transparent 75%, rgba(255, 255, 255, 0.025)),
        radial-gradient(circle at center, transparent 0, transparent 42%, rgba(0, 0, 0, 0.18) 100%);
    pointer-events: none;
}

#drawSurface.motionMode {
    border-color: rgba(0, 212, 170, 0.52);
    background:
        radial-gradient(circle at center, rgba(0, 212, 170, 0.17), rgba(0, 212, 170, 0.05) 40%, transparent 75%),
        radial-gradient(circle at 80% 20%, rgba(255, 179, 71, 0.14), transparent 28%),
        linear-gradient(160deg, #28403c, #1f3330 46%, #162a27 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        inset 0 -24px 45px rgba(0, 0, 0, 0.22),
        0 0 0 1px rgba(0, 212, 170, 0.24),
        0 0 40px rgba(0, 212, 170, 0.18);
}

.surfaceLabel {
    z-index: 1;
    pointer-events: none;
}

.surfaceLabel {
    position: absolute;
    left: 22px;
    top: 18px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(15, 15, 15, 0.44);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(255, 245, 232, 0.8);
}

.surfaceCaption {
    width: 92vw;
    max-width: 680px;
    max-width: min(680px, 92vw);
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(15, 15, 15, 0.38);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(244, 239, 231, 0.68);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
    box-sizing: border-box;
}

body.motionEnabled .statusDot {
    background: #00d4aa;
    box-shadow: 0 0 16px rgba(0, 212, 170, 0.85);
}

body.motionEnabled .secondaryButton:not(:disabled) {
    background: linear-gradient(135deg, #ff9f1c, #ff7b00);
    box-shadow: 0 10px 25px rgba(255, 123, 0, 0.24);
}

body.viewerPortrait #drawContainer {
    align-items: stretch;
}

body.viewerPortrait .stageFrame {
    max-width: 560px;
    max-height: none;
}

body.viewerPortrait .surfaceLabel {
    left: 12px;
    top: 12px;
    padding: 6px 8px;
    font-size: 9px;
    letter-spacing: 0.12em;
}

@media (hover: hover) {

    .colorDock:hover,
    .sprayDock:hover,
    #clearButton:hover,
    .secondaryButton:hover:not(:disabled) {
        transform: translateY(-1px);
        filter: brightness(1.04);
    }
}

@media (max-width: 760px) {
    .appShell {
        padding: 12px;
        gap: 12px;
    }

    #header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        border-radius: 20px;
    }

    .headerMain {
        align-items: flex-start;
        gap: 12px;
        width: 100%;
    }

    .appIconBadge {
        width: 72px;
        height: 72px;
        flex-basis: 72px;
    }

    .headerActions {
        align-self: flex-end;
        justify-content: flex-end;
        margin-left: 0;
    }

    .stageFrame {
        padding: 12px;
        border-radius: 24px;
    }

    #drawSurface {
        border-radius: 20px;
    }

    .surfaceCaption {
        width: 92vw;
        max-width: 420px;
        max-width: min(92vw, 420px);
    }

}

@media (max-width: 760px) and (orientation: portrait) {
    body.viewerPortrait .appShell {
        padding: 10px;
        gap: 8px;
    }

    body.viewerPortrait #header {
        padding: 12px;
        gap: 10px;
    }

    body.viewerPortrait .headerMain {
        align-items: center;
        gap: 10px;
    }

    body.viewerPortrait .appIconBadge {
        width: 58px;
        height: 58px;
        flex-basis: 58px;
    }

    body.viewerPortrait .eyebrow {
        margin-bottom: 4px;
        font-size: 9px;
    }

    body.viewerPortrait .headerCopy h1 {
        font-size: 30px;
    }

    body.viewerPortrait .headerCopy p {
        margin-top: 5px;
        font-size: 12px;
        line-height: 1.3;
    }

    body.viewerPortrait .headerActions {
        width: 100%;
    }

    body.viewerPortrait .controlBarActions {
        gap: 6px;
    }

    body.viewerPortrait .colorDock,
    body.viewerPortrait .sprayDock,
    body.viewerPortrait #clearButton,
    body.viewerPortrait .secondaryButton {
        min-height: 36px;
    }

    body.viewerPortrait .colorDock,
    body.viewerPortrait .sprayDock {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    body.viewerPortrait .sprayDock {
        min-width: 148px;
    }

    body.viewerPortrait #sprayWidth {
        width: 62px;
    }

    body.viewerPortrait #clearButton,
    body.viewerPortrait .secondaryButton {
        padding: 8px 12px;
        font-size: 12px;
    }

    body.viewerPortrait .stageFrame {
        padding: 10px;
        border-radius: 22px;
    }

    body.viewerPortrait .surfaceCaption {
        display: none;
    }
}

@media (max-width: 760px) and (max-height: 720px) and (orientation: portrait) {
    body.viewerPortrait .appShell {
        gap: 7px;
    }

    body.viewerPortrait #header {
        padding: 10px 12px;
    }

    body.viewerPortrait .appIconBadge {
        width: 48px;
        height: 48px;
        flex-basis: 48px;
    }

    body.viewerPortrait .headerCopy p {
        display: none;
    }

    body.viewerPortrait .headerCopy h1 {
        font-size: 28px;
    }

    body.viewerPortrait .headerActions {
        justify-content: space-between;
    }

    body.viewerPortrait #commsInfoDiv,
    body.viewerPortrait .backToAppsButton {
        min-height: 28px;
    }
}