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

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background: #121212;
    color: #e0e0e0;
    overflow: hidden;
    position: fixed;
    /* Fix body to prevent elastic scrolling on iOS */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    --page-zoom: 1;
}

#container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    z-index: 1;
    background: #121212;
}

body.zoomed #container {
    overflow-x: auto;
    scroll-snap-type: none;
}

.page {
    height: calc(100% * var(--page-zoom));
    /* Use % instead of vh for better mobile bar handling */
    width: calc(100% * var(--page-zoom));
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

body.zoomed .page {
    scroll-snap-align: none;
    scroll-snap-stop: normal;
    justify-content: flex-start;
    align-items: flex-start;
}

.page img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    /* Prevent ghost drag */
}

/* UI Layer */
#header,
#controls {
    position: fixed;
    left: 0;
    right: 0;
    background: rgba(30, 30, 30, 0.95);
    /* Darker theme for better contrast */
    backdrop-filter: blur(10px);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#header {
    top: 0;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#controls {
    bottom: 0;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 12px;
}

/* Immersive State */
.ui-hidden #header {
    transform: translateY(-100%);
}

.ui-hidden #controls {
    transform: translateY(100%);
}

h1 {
    font-size: 16px;
    font-weight: 500;
    color: #90caf9;
    margin: 0;
}


#btnClose {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 44px;
    /* Touch target */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* Align icon to right */
}

/* Page Info - Bottom Left */
.controls-left,
.controls-center,
.controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.controls-left {
    justify-self: start;
}

.controls-center {
    justify-self: center;
}

.controls-right {
    justify-self: end;
    gap: 8px;
}

.page-status {
    font-size: 12px;
    color: #aaa;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

/* Copyright - Bottom Right */
.copyright-tag {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

/* Unified Control Styles */
.control-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s;
}

.control-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.2);
}

#btnGo {
    width: auto;
    border-radius: 22px;
    /* Half of 44px height */
    padding: 0 20px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 14px;
    background: #1976d2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#btnGo:active {
    background: #1565c0;
}

.desktop-only {
    display: none;
}

@media (hover: hover) and (pointer: fine) {
    .desktop-only {
        display: inline-flex;
    }
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.control-btn:disabled:active {
    transform: none;
    background: rgba(255, 255, 255, 0.1);
}

input[type="number"] {
    width: 70px;
    height: 44px;
    /* Matches buttons exactly */
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    color: #fff;
    -moz-appearance: textfield;
    appearance: textfield;
    /* Remove spinner */
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input:focus {
    outline: none;
    border-color: #90caf9;
    background: rgba(0, 0, 0, 0.5);
}

#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: #fff;
    z-index: 2000;
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    padding: 24px;
    border-radius: 16px;
    pointer-events: none;
}

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid #fff;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}