* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-image: url("images/Tisch.jpg");
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    transition: background-image 0.3s ease;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
}

.container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: calc(env(safe-area-inset-top) + 20px) 20px
        calc(env(safe-area-inset-bottom) + 20px) 20px;
}

/* ---- Dice ---- */
.dice-row {
    display: flex;
    gap: 24px;
    justify-content: center;
    width: 100%;
}

.die {
    width: 40vw;
    max-width: 170px;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    object-position: center;
    transition: transform 0.2s;
}

.rolling {
    animation: shake 0.5s;
}

@keyframes shake {
    0%,
    100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-25deg) scale(1.08);
    }
    75% {
        transform: rotate(25deg) scale(1.08);
    }
}

/* ---- Controls ---- */
.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    width: 100%;
    max-width: 340px;
}

#rollBtn {
    width: 100%;
    padding: 20px;
    font-size: 1.5rem;
    font-weight: 600;
    border: none;
    border-radius: 18px;
    background: #34c759;
    color: white;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

#rollBtn:active {
    transform: scale(0.97);
}

#manualBtn {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 500;
    border: none;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.9);
    color: #007aff;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

#manualBtn:active {
    transform: scale(0.97);
}

/* ---- iOS-style toggle switch ---- */
.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}

.toggle-label {
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 34px;
    transition: background 0.3s;
}

.slider::before {
    content: "";
    position: absolute;
    height: 28px;
    width: 28px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.switch input:checked + .slider {
    background: #34c759;
}

.switch input:checked + .slider::before {
    transform: translateX(26px);
}

/* ---- Manual overlay ---- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom) 12px;
}

.hidden {
    display: none;
}

.manual-box {
    position: relative;
    width: 100%;
    max-width: 700px;
    max-height: 100%;
    background: #fff;
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* CSS-based fullscreen — reliable on iPhone & iPad */
.manual-box.fs-active {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    justify-content: center;
    padding: calc(env(safe-area-inset-top) + 10px) env(safe-area-inset-right)
        calc(env(safe-area-inset-bottom) + 10px) env(safe-area-inset-left);
    z-index: 200;
}

/* Wrapper clips the zoomed image so it can't overflow */
.manual-img-wrap {
    overflow: hidden;
    width: 100%;
    flex: 1;
    min-height: 0;
    max-height: 72vh;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none; /* we handle gestures in JS */
}

.manual-box.fs-active .manual-img-wrap {
    max-height: 85vh;
    max-height: 85dvh;
}

#manualImg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.05s;
    will-change: transform;
    cursor: grab;
}

/* ---- Manual nav (enlarged for finger taps) ---- */
.manual-nav {
    display: flex;
    align-items: center;
    gap: 30px;
    margin-top: 16px;
    font-size: 1.3rem;
}

.manual-box.fs-active .manual-nav {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom) + 20px);
}

.manual-nav button {
    min-width: 72px;
    height: 60px;
    padding: 0 22px;
    border: none;
    border-radius: 16px;
    background: #34c759;
    color: white;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.manual-nav button:active {
    transform: scale(0.95);
}

.manual-nav button:disabled {
    background: #c7c7cc;
    cursor: default;
    transform: none;
}

#pageInfo {
    font-size: 1.2rem;
    font-weight: 600;
    min-width: 70px;
    text-align: center;
}

/* ---- Close & fullscreen buttons ---- */
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: #ff3b30;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 210;
}

.fs-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: #007aff;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 210;
}

/* In fullscreen, push top buttons BELOW the status bar / Dynamic Island */
.manual-box.fs-active .close-btn {
    top: calc(env(safe-area-inset-top) + 12px);
    right: calc(env(safe-area-inset-right) + 12px);
}

.manual-box.fs-active .fs-btn {
    top: calc(env(safe-area-inset-top) + 12px);
    left: calc(env(safe-area-inset-left) + 12px);
}
