/* MargoStory chrome around original Sandspiel canvases */

.sandspiel-body {
    overflow-x: hidden;
    overflow-y: hidden;
    height: 100vh;
    max-height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #F7F2EA;
    max-width: 100%;
}

.sandspiel-body.header,
.sandspiel-body .header {
    position: relative;
    z-index: 20;
    flex: 0 0 auto;
}

.sandspiel-page {
    position: relative;
    z-index: 2;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    max-width: 1900px;
    width: 100%;
    margin: 0 auto;
    padding: 4px 16px 8px;
    min-height: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.back-home {
    display: inline-block;
    align-self: flex-start;
    margin-bottom: 8px;
    padding: 10px 20px;
    background: #FFF8F1;
    border-radius: 18px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
    color: #7A644E;
    font-weight: 600;
    transition: 0.35s;
}

.back-home:hover {
    transform: translateY(-3px);
    color: #B48B43;
}

.sandspiel-stage {
    position: relative;
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
    max-height: calc(100dvh - 160px);
    min-height: 0;
    height: auto;
    margin: 0 auto;
    align-self: center;
    background: #F7F2EA;
    border-radius: 28px;
    overflow: hidden;
    box-shadow:
        0 14px 40px rgba(0, 0, 0, 0.10),
        0 5px 15px rgba(0, 0, 0, 0.05);
}

.sandspiel-body,
.sandspiel-body #background {
    position: relative;
    top: auto;
    left: auto;
    width: auto;
    height: auto;
}

.sandspiel-stage #background {
    position: relative;
    width: 100%;
    height: 100%;
    background: #F7F2EA;
}

.sandspiel-credit {
    margin: 4px 0 0;
    font-size: 12px;
    line-height: 1.2;
    color: #A08A72;
    flex: 0 0 auto;
}

.language a.active {
    color: #B48B43;
    font-weight: 600;
}

html[dir="rtl"] .sandspiel-page {
    text-align: right;
}

html[dir="rtl"] .back-home {
    align-self: flex-end;
}

.sandspiel-boot-error {
    position: absolute;
    z-index: 30;
    left: 24px;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    padding: 16px 18px;
    background: #FFF8F1;
    color: #7A644E;
    border-radius: 18px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.sandspiel-stage #ui {
    float: none;
    z-index: 6;
}

.sandspiel-stage #sand-canvas,
.sandspiel-stage #fluid-canvas {
    right: auto;
    max-width: none !important;
    max-height: none !important;
}

@media (max-width: 1023px) {
    .sandspiel-page {
        padding: 4px 12px 8px;
    }

    .sandspiel-stage {
        max-height: calc(100dvh - 180px);
        border-radius: 22px;
    }
}

@media (max-width: 700px) {
    .sandspiel-body .header {
        padding: 8px 12px;
        gap: 6px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
    }

    .sandspiel-body .logo img {
        width: 44px;
        height: 44px;
        border-width: 3px;
        box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
    }

    .sandspiel-body .title {
        flex: 1 1 140px;
        min-width: 0;
    }

    .sandspiel-body .title h1 {
        font-size: 18px;
        letter-spacing: 0.4px;
    }

    .sandspiel-body .gold-line {
        width: 64px;
        height: 2px;
        margin: 4px auto;
    }

    .sandspiel-body .title p {
        font-size: 11px;
        line-height: 1.3;
        margin: 0;
    }

    .sandspiel-body .language {
        font-size: 13px;
    }

    .sandspiel-page {
        padding: 4px 8px 6px;
    }

    .sandspiel-stage {
        width: 100% !important;
        max-width: 100%;
        max-height: calc(100dvh - 130px);
        border-radius: 16px;
        align-self: stretch;
    }

    .sandspiel-stage.is-stacked #ui {
        display: flex !important;
        flex-wrap: wrap !important;
        align-content: flex-start !important;
        align-items: stretch !important;
        gap: 3px !important;
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .sandspiel-stage.is-stacked #ui > * {
        box-sizing: border-box !important;
        max-width: 100% !important;
    }

    /* Promo pull-tab sits fixed off-canvas on desktop; hide on phone */
    .sandspiel-stage.is-stacked #PullTab,
    .sandspiel-stage.is-stacked #PullTabContent {
        display: none !important;
    }

    .sandspiel-stage.is-stacked #ui #controls,
    .sandspiel-stage.is-stacked #ui .controls {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 3px !important;
    }

    /* Anchors that wrap Browse/Info must be flex items too */
    .sandspiel-stage.is-stacked #ui > a {
        flex: 1 1 calc(33.33% - 4px) !important;
        min-width: 0 !important;
        max-width: calc(50% - 3px) !important;
        display: flex !important;
    }

    .sandspiel-stage.is-stacked #ui button,
    .sandspiel-stage.is-stacked #ui .promo {
        flex: 1 1 calc(33.33% - 4px) !important;
        min-width: 0 !important;
        max-width: calc(50% - 3px) !important;
        width: auto !important;
        height: auto !important;
        min-height: 32px !important;
        padding: 5px 4px !important;
        font-size: 11px !important;
        line-height: 1.15 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .sandspiel-stage.is-stacked #ui > a > button {
        flex: 1 1 auto !important;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
    }

    /* Brush-size cluster: one full-width row */
    .sandspiel-stage.is-stacked #ui .sizes {
        flex: 1 1 100% !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        align-items: stretch !important;
        gap: 2px !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .sandspiel-stage.is-stacked #ui .sizes button {
        flex: 1 1 0 !important;
        max-width: none !important;
        min-width: 28px !important;
        width: auto !important;
    }

    .sandspiel-stage.is-stacked #ui button.selected {
        text-shadow: none !important;
    }

    .sandspiel-stage.is-stacked #fps {
        position: absolute !important;
        right: 4px !important;
        bottom: 2px !important;
        font-size: 10px !important;
        pointer-events: none !important;
        z-index: 7 !important;
    }

    .sandspiel-stage.is-stacked {
        overflow: hidden !important;
    }

    .back-home {
        margin-bottom: 6px;
        padding: 8px 14px;
        font-size: 13px;
    }

    .sandspiel-credit {
        font-size: 11px;
    }
}

@media (max-width: 700px) and (orientation: landscape) {
    .sandspiel-body .title p,
    .sandspiel-body .gold-line {
        display: none;
    }

    .sandspiel-body .logo img {
        width: 32px;
        height: 32px;
    }
}
