:root {
    --coop-red: #e30613;
    --coop-red-dark: #b9000a;
    --ink: #242424;
    --muted: #686868;
    --surface: #ffffff;
    --canvas: #eceff2;
    --line: #d8dde2;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background:
        radial-gradient(circle at 50% -20%, #ffffff 0, #eef1f4 40%, #e3e7eb 100%);
    -webkit-tap-highlight-color: transparent;
}

button,
a {
    font: inherit;
}

button {
    border: 0;
}

.app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100dvh;
    min-height: 480px;
}

.topbar {
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
    padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
    color: #fff;
    background: var(--coop-red);
    box-shadow: 0 3px 14px rgba(92, 0, 4, 0.22);
}

.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 11px;
}

.coop-logo {
    flex: none;
    color: #fff;
    font-family: "Arial Rounded MT Bold", Arial, sans-serif;
    font-size: clamp(28px, 8vw, 38px);
    font-weight: 900;
    line-height: 0.8;
    letter-spacing: -4px;
}

.store-name {
    overflow: hidden;
    font-size: clamp(11px, 3.2vw, 15px);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0.035em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-actions {
    display: flex;
    flex: none;
    gap: 4px;
}

.icon-button {
    display: grid;
    width: 42px;
    height: 42px;
    padding: 9px;
    place-items: center;
    color: #fff;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    text-decoration: none;
}

.icon-button:active,
.icon-button:hover {
    background: rgba(255, 255, 255, 0.18);
}

.icon-button svg,
.nav-button svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.viewer {
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.page-stage {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 14px 12px 52px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    touch-action: pan-x pan-y;
}

.page-stage img {
    display: block;
    flex: none;
    max-width: none;
    height: auto;
    background: #fff;
    border-radius: 7px;
    box-shadow: var(--shadow);
    opacity: 1;
    transition: opacity 140ms ease, filter 140ms ease;
    user-select: none;
    -webkit-user-drag: none;
}

.page-stage img.is-changing {
    opacity: 0.25;
    filter: blur(2px);
}

.loading {
    position: absolute;
    z-index: 5;
    top: 50%;
    left: 50%;
    display: none;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    color: #fff;
    background: rgba(25, 25, 25, 0.78);
    border-radius: 999px;
    font-size: 13px;
    transform: translate(-50%, -50%);
}

.loading.visible {
    display: flex;
}

.spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.swipe-hint {
    position: absolute;
    z-index: 6;
    bottom: 10px;
    left: 50%;
    padding: 7px 12px;
    color: #fff;
    background: rgba(18, 18, 18, 0.72);
    border-radius: 999px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    transform: translateX(-50%);
    transition: opacity 300ms ease;
}

.swipe-hint.hidden {
    opacity: 0;
}

.controlbar {
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: stretch;
    min-height: 68px;
    padding: 7px max(10px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.07);
}

.nav-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    padding: 8px;
    color: var(--coop-red);
    background: transparent;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
}

.nav-button svg {
    width: 22px;
    height: 22px;
}

.nav-button:disabled {
    color: #b8bdc2;
    cursor: default;
}

.page-counter {
    display: grid;
    grid-template-columns: auto auto;
    align-content: center;
    align-items: baseline;
    justify-content: center;
    column-gap: 4px;
    min-width: 98px;
    padding: 5px 13px;
    color: #fff;
    background: var(--coop-red);
    border-radius: 13px;
    box-shadow: 0 4px 12px rgba(227, 6, 19, 0.23);
    cursor: pointer;
}

.page-counter strong {
    font-size: 20px;
}

.page-counter span {
    font-size: 12px;
}

.page-counter small {
    grid-column: 1 / -1;
    font-size: 9px;
    opacity: 0.85;
}

.zoom-controls {
    position: absolute;
    z-index: 15;
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(82px + env(safe-area-inset-bottom));
    display: flex;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}

.zoom-controls button {
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    color: var(--ink);
    background: transparent;
    font-weight: 800;
    cursor: pointer;
}

.zoom-controls button + button {
    border-left: 1px solid var(--line);
}

#zoomReset {
    min-width: 62px;
    color: var(--muted);
    font-size: 11px;
}

.pages-dialog {
    width: min(94vw, 880px);
    height: min(88dvh, 820px);
    padding: 0;
    overflow: hidden;
    background: var(--surface);
    border: 0;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.pages-dialog::backdrop {
    background: rgba(16, 18, 20, 0.72);
    backdrop-filter: blur(3px);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 16px;
    color: #fff;
    background: var(--coop-red);
}

.dialog-header strong,
.dialog-header span {
    display: block;
}

.dialog-header strong {
    font-size: 17px;
}

.dialog-header span {
    margin-top: 2px;
    font-size: 11px;
    opacity: 0.86;
}

.close-button {
    width: 42px;
    height: 42px;
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    height: calc(100% - 72px);
    padding: 14px;
    overflow-y: auto;
    background: #eef1f4;
}

.thumbnail {
    position: relative;
    padding: 0;
    overflow: hidden;
    background: #fff;
    border: 3px solid transparent;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    cursor: pointer;
}

.thumbnail.active {
    border-color: var(--coop-red);
}

.thumbnail img {
    display: block;
    width: 100%;
    height: auto;
}

.thumbnail span {
    position: absolute;
    right: 5px;
    bottom: 5px;
    display: grid;
    width: 27px;
    height: 27px;
    place-items: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.72);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
}

.noscript {
    position: fixed;
    z-index: 99;
    inset: 0;
    margin: 0;
    padding: 30px;
    color: #fff;
    background: var(--coop-red-dark);
}

@media (min-width: 700px) {
    .topbar {
        padding-right: 24px;
        padding-left: 24px;
    }

    .page-stage {
        padding: 22px 22px 58px;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .controlbar {
        width: min(620px, calc(100% - 32px));
        margin: 0 auto 12px;
        padding: 7px;
        border: 1px solid var(--line);
        border-radius: 17px;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.13);
    }

    .app-shell {
        grid-template-rows: auto minmax(0, 1fr) auto;
    }

    .zoom-controls {
        bottom: 98px;
    }
}

@media (max-width: 380px) {
    .store-name {
        max-width: 145px;
    }

    .nav-button span {
        display: none;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
