/* ========== COMIC VIEWER v2 ========== */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --black: #0d0d0d; --dark: #1a1a2e; --panel: #16213e; --accent: #e94560; --accent-hover: #ff6b81;
    --cyan: #00d4ff; --yellow: #f5c518; --green: #2ecc71; --white: #f8f8f8; --gray: #a0a0b0;
    --font-display: "Bricolage Grotesque", "Arial Black", sans-serif; --font-body: "Rubik", "Segoe UI", sans-serif;
}
body { font-family: var(--font-body); background: var(--black); color: var(--white); min-height: 100vh; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }

/* Loading / Error */
.viewer-loading { text-align: center; padding: 6rem 2rem; }
.viewer-loading .spinner, .processing-spinner .spinner {
    width: 48px; height: 48px; border: 3px solid rgba(233,69,96,.2); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 1.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viewer-error { text-align: center; padding: 5rem 2rem; color: var(--gray); }

/* Processing */
.processing-screen { display: flex; align-items: center; justify-content: center; min-height: 80vh; padding: 2rem; }
.processing-card { background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 20px; padding: 3rem 2.5rem; max-width: 480px; width: 100%; text-align: center; }
.processing-title { font-family: var(--font-display); font-size: 1.5rem; letter-spacing: 1px; margin-bottom: .75rem; }
.processing-msg { color: var(--gray); font-size: .95rem; line-height: 1.6; margin-bottom: .5rem; }
.processing-sub { color: rgba(255,255,255,.3); font-size: .8rem; margin-bottom: 2rem; }
.processing-actions { display: flex; flex-direction: column; gap: .6rem; }
.processing-btn { display: block; padding: .75rem 1.5rem; border-radius: 50px; background: var(--accent); color: var(--white); font-weight: 600; font-size: .9rem; text-align: center; transition: all .2s; }
.processing-btn:hover { background: var(--accent-hover); }
.processing-btn.secondary { background: rgba(255,255,255,.08); }

/* ========== TOOLBAR ========== */
.v-toolbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .75rem;
    background: rgba(13,13,13,.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.v-toolbar-back {
    flex: 1; display: flex; align-items: center; gap: .5rem;
    color: var(--gray); transition: color .2s; min-width: 0;
}
.v-toolbar-back:hover { color: var(--white); }
.v-toolbar-arrow { font-size: 1.1rem; flex-shrink: 0; }
.v-toolbar-title {
    font-family: var(--font-display); font-size: .95rem;
    letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v-toolbar-actions { display: flex; gap: .4rem; }
.v-tool-btn {
    background: none; border: 1px solid rgba(255,255,255,.1); border-radius: 6px;
    color: var(--gray); font-size: .9rem; padding: .3rem .4rem; cursor: pointer;
    transition: all .2s; line-height: 1;
}
.v-tool-btn:hover { color: var(--cyan); border-color: var(--cyan); background: rgba(0,212,255,.08); }
.v-tool-btn.danger:hover { color: var(--accent); border-color: var(--accent); background: rgba(233,69,96,.08); }
.v-tool-btn:disabled { opacity: .3; cursor: not-allowed; }
.v-tool-btn.admin-btn {
    font-size: .7rem; font-weight: 500; letter-spacing: .3px;
    border-color: rgba(0,212,255,.3); color: var(--cyan); background: rgba(0,212,255,.06);
}
.v-tool-btn.admin-btn:hover { background: rgba(0,212,255,.15); border-color: var(--cyan); }
.v-edit-label { display: block; font-size: .8rem; color: var(--gray); margin-bottom: .3rem; }

/* Public/Private toggle */
.v-pub-toggle {
    display: inline-flex; align-items: center; gap: .35rem;
    background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
    border-radius: 20px; padding: .25rem .65rem .25rem .45rem;
    color: var(--gray); font-family: var(--font-body); font-size: .75rem; font-weight: 500;
    cursor: pointer; transition: all .25s; line-height: 1;
}
.v-pub-toggle .v-pub-icon { font-size: .85rem; line-height: 1; transition: transform .25s; }
.v-pub-toggle .v-pub-label { white-space: nowrap; }
.v-pub-toggle:hover { border-color: rgba(255,255,255,.25); color: var(--white); }
.v-pub-toggle.is-public {
    background: rgba(46,204,113,.12); border-color: rgba(46,204,113,.35); color: var(--green);
}
.v-pub-toggle.is-public:hover { background: rgba(46,204,113,.18); border-color: var(--green); }
.v-pub-toggle.loading { pointer-events: none; }
.v-pub-toggle.loading .v-pub-icon { display: none; }
.v-pub-toggle.loading .v-pub-label::before {
    content: ''; display: inline-block; width: 10px; height: 10px;
    border: 1.5px solid rgba(255,255,255,.2); border-top-color: currentColor;
    border-radius: 50%; animation: spin .6s linear infinite;
    margin-right: .35rem; vertical-align: middle;
}

/* Viewer toast */
.v-toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(10px);
    background: var(--panel); border: 1px solid rgba(255,255,255,.12);
    color: var(--white); padding: .6rem 1.2rem; border-radius: 10px;
    font-size: .8rem; font-weight: 500; z-index: 300;
    opacity: 0; transition: all .3s; pointer-events: none;
    box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 90vw; text-align: center;
}
.v-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.v-toast.error { border-color: rgba(233,69,96,.4); color: var(--accent); }

/* ========== VIEWPORT ========== */
.v-viewport {
    padding-top: 48px; /* toolbar height */
    padding-bottom: 72px; /* nav height */
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.v-slide {
    width: 100%;
    transition: opacity .25s ease, transform .25s ease;
}

/* ========== COVER ========== */
.v-cover {
    position: relative;
    max-width: 450px;
    margin: 0 auto;
    padding: 1rem;
}
.v-cover img {
    width: 100%;
    border-radius: 6px;
    box-shadow: 0 12px 48px rgba(0,0,0,.5);
    display: block;
}
.open-comic-btn {
    position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: .6rem;
    background: rgba(255,255,255,.12); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    color: var(--white); padding: .85rem 2rem; border-radius: 50px; border: 1.5px solid rgba(255,255,255,.25);
    font-family: var(--font-body); font-weight: 600; font-size: 1rem; letter-spacing: .5px;
    cursor: pointer; box-shadow: 0 8px 32px rgba(0,0,0,.4); transition: all .3s; white-space: nowrap;
}
.open-comic-btn:hover {
    background: rgba(255,255,255,.22); border-color: rgba(255,255,255,.5);
    transform: translateX(-50%) translateY(-2px); letter-spacing: 1.5px;
}
.open-comic-btn::after {
    content: ''; display: inline-block; width: 7px; height: 7px;
    border-right: 2px solid currentColor; border-top: 2px solid currentColor;
    transform: rotate(45deg); margin-left: .2rem; transition: transform .3s;
}

/* ========== COMIC PAGE ========== */
.v-page { padding: 0; }
.v-page img {
    width: 100%;
    display: block;
    background: #fff;
}
.v-page-empty {
    text-align: center; padding: 4rem; color: var(--gray);
}

/* Desktop: constrain single page width (fallback) */
@media (min-width: 901px) {
    .v-page { max-width: 600px; margin: 0 auto; padding: 0 1rem; }
    .v-page img { border-radius: 4px; box-shadow: 0 8px 32px rgba(0,0,0,.4); }
}

/* ========== DESKTOP TWO-PAGE SPREAD ========== */
.v-spread {
    display: inline-flex;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.08);
    position: relative;
    margin: 0 auto;
}
.v-spread-page {
    display: block;
    background: #fff;
    overflow: hidden;
    line-height: 0;
    position: relative;
}
.v-spread-page img {
    height: calc(100vh - 180px);
    width: auto;
    display: block;
}
.v-spread-empty {
    display: flex; align-items: center; justify-content: center;
    width: 300px; height: calc(100vh - 180px);
    color: rgba(0,0,0,.15); font-size: .85rem;
}
/* Regen button on spread pages */
.spread-edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,.15);
    color: rgba(255,255,255,.6);
    font-size: .9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all .2s;
    z-index: 3;
}
.v-spread-page:hover .spread-edit-btn { opacity: 1; }
.spread-edit-btn:hover {
    background: rgba(233,69,96,.8);
    color: var(--white);
    border-color: var(--accent);
}

.v-spread-spine {
    position: absolute;
    top: 0; bottom: 0;
    left: 50%;
    width: 50px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0,0,0,.18) 0%, rgba(0,0,0,.06) 40%, transparent 75%);
    pointer-events: none;
    z-index: 2;
}

/* Center the spread in the viewport */
@media (min-width: 901px) {
    .v-viewport { text-align: center; }
}

/* ========== ENDING PAGE ========== */
.v-ending {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - 120px); padding: 2rem 1.5rem;
}
.v-ending-inner {
    max-width: 380px; width: 100%; text-align: center;
}

.v-ending-flourish {
    font-family: var(--font-display); font-size: 1rem; letter-spacing: 6px;
    text-transform: uppercase; color: var(--accent); margin-bottom: 1.5rem;
    position: relative;
}
.v-ending-flourish::before, .v-ending-flourish::after {
    content: ''; position: absolute; top: 50%; height: 1px; width: 40px;
    background: linear-gradient(to right, transparent, var(--accent));
}
.v-ending-flourish::before { right: calc(50% + 50px); }
.v-ending-flourish::after { left: calc(50% + 50px); background: linear-gradient(to left, transparent, var(--accent)); }

.v-ending-title {
    font-family: var(--font-display); font-size: 1.8rem; letter-spacing: 2px; margin-bottom: .4rem;
}
.v-ending-meta { color: var(--gray); font-size: .8rem; margin-bottom: 2rem; }

.v-ending-share { margin-bottom: 2rem; }
.v-ending-share-btn {
    display: inline-flex; align-items: center; gap: .6rem;
    background: none; border: 1.5px solid rgba(255,255,255,.15);
    color: var(--white); padding: .7rem 1.8rem; border-radius: 50px;
    font-family: var(--font-body); font-weight: 600; font-size: .9rem;
    cursor: pointer; transition: all .25s;
}
.v-ending-share-btn:hover {
    border-color: var(--cyan); color: var(--cyan);
    box-shadow: 0 0 20px rgba(0,212,255,.15);
}
.v-share-icon { font-size: 1rem; }

.v-ending-brand {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem;
}
.v-ending-line { flex: 1; height: 1px; background: rgba(255,255,255,.08); }
.v-ending-brand span {
    font-family: var(--font-display); font-size: .85rem; letter-spacing: 1px;
    color: var(--gray); white-space: nowrap;
}

.v-ending-cta { margin-bottom: 1.5rem; }
.v-ending-cta-text {
    color: var(--gray); font-size: .85rem; margin-bottom: .75rem;
}
.v-ending-cta-btn {
    display: inline-block; background: var(--accent); color: var(--white);
    padding: .75rem 2rem; border-radius: 50px; font-weight: 600; font-size: .9rem;
    transition: all .2s; box-shadow: 0 4px 16px rgba(233,69,96,.3);
}
.v-ending-cta-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }

.v-ending-owner { margin-bottom: 1.5rem; }
.v-ending-owner-btn {
    background: none; border: 1px solid rgba(255,255,255,.1);
    color: var(--gray); padding: .55rem 1.4rem; border-radius: 50px;
    font-family: var(--font-body); font-size: .8rem; font-weight: 500;
    cursor: pointer; transition: all .2s;
}
.v-ending-owner-btn:hover { border-color: var(--cyan); color: var(--cyan); }

.v-ending-browse {
    display: inline-block; color: var(--gray); font-size: .8rem;
    transition: color .2s;
}
.v-ending-browse:hover { color: var(--white); }

/* ========== NAVIGATION ========== */
.v-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    display: flex; align-items: center; gap: .5rem;
    padding: .6rem 1rem;
    background: rgba(13,13,13,.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255,255,255,.06);
}
.v-nav-arrow {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
    color: var(--white); font-size: 1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s; flex-shrink: 0;
}
.v-nav-arrow:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.v-nav-arrow:disabled { opacity: .2; cursor: not-allowed; }
.v-nav-center { flex: 1; text-align: center; }
.v-page-label { font-size: .8rem; color: var(--gray); display: block; margin-bottom: .3rem; }
.v-dots { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.v-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: rgba(255,255,255,.15); cursor: pointer; transition: all .2s;
}
.v-dot:hover { background: rgba(255,255,255,.3); }
.v-dot.active { background: var(--accent); transform: scale(1.3); }

/* ========== EDIT MODAL ========== */
.v-edit-modal {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.7); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem; opacity: 0; transition: opacity .25s;
}
.v-edit-modal.visible { opacity: 1; }
.v-edit-card {
    background: var(--panel); border: 1px solid rgba(255,255,255,.1);
    border-radius: 18px; padding: 1.5rem; max-width: 420px; width: 100%;
    transform: scale(.95); transition: transform .25s;
}
.v-edit-modal.visible .v-edit-card { transform: scale(1); }
.v-edit-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem;
}
.v-edit-header h3 {
    font-family: var(--font-display); font-size: 1.2rem; letter-spacing: 1px;
}
.v-edit-close {
    background: none; border: none; color: var(--gray); font-size: 1.1rem;
    cursor: pointer; padding: .2rem; transition: color .2s;
}
.v-edit-close:hover { color: var(--white); }
.v-edit-toggle {
    display: flex; background: rgba(255,255,255,.04); border-radius: 8px;
    padding: 3px; margin-bottom: 1rem;
}
.v-toggle-btn {
    flex: 1; padding: .5rem; border: none; border-radius: 6px;
    background: transparent; color: var(--gray); font-family: var(--font-body);
    font-size: .85rem; font-weight: 500; cursor: pointer; transition: all .2s;
}
.v-toggle-btn.active { background: var(--accent); color: var(--white); }
.v-edit-hint {
    font-size: .8rem; color: var(--gray); margin-bottom: .75rem; line-height: 1.4;
}
.v-edit-input {
    width: 100%; padding: .7rem .85rem; background: rgba(255,255,255,.04);
    border: 1.5px solid rgba(255,255,255,.1); border-radius: 10px;
    color: var(--white); font-family: var(--font-body); font-size: .9rem;
    resize: none; outline: none; transition: border-color .2s; margin-bottom: 1rem;
}
.v-edit-input:focus { border-color: var(--accent); }
.v-edit-input::placeholder { color: rgba(255,255,255,.25); }
.v-edit-footer {
    display: flex; justify-content: space-between; align-items: center;
}
.v-edit-cost { font-size: .75rem; color: var(--gray); }
.v-edit-submit {
    padding: .6rem 1.5rem; border-radius: 50px; border: none;
    background: var(--accent); color: var(--white); font-family: var(--font-body);
    font-weight: 600; font-size: .9rem; cursor: pointer; transition: all .2s;
}
.v-edit-submit:hover { background: var(--accent-hover); }

/* ========== REGENERATE OVERLAY ========== */
.v-regen-overlay {
    position: absolute; inset: 0; z-index: 10;
    background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem;
    color: var(--white); font-size: .85rem; font-weight: 500;
}
.v-regen-spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(233,69,96,.2); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite;
}

/* ========== COMPARE MODAL ========== */
.v-compare-modal {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.75); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem; opacity: 0; transition: opacity .3s;
}
.v-compare-modal.visible { opacity: 1; }

.v-compare-card {
    background: var(--panel); border: 1px solid rgba(255,255,255,.1);
    border-radius: 20px; padding: 1.5rem; max-width: 700px; width: 100%;
    text-align: center; transform: scale(.95); transition: transform .3s;
}
.v-compare-modal.visible .v-compare-card { transform: scale(1); }

.v-compare-title {
    font-family: var(--font-display); font-size: 1.3rem; letter-spacing: 1px; margin-bottom: .3rem;
}
.v-compare-sub { color: var(--gray); font-size: .85rem; margin-bottom: 1.25rem; }

.v-compare-images {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
.v-compare-option {
    display: flex; flex-direction: column; gap: .6rem;
}
.v-compare-option img {
    width: 100%; border-radius: 8px; border: 2px solid rgba(255,255,255,.1);
}
.v-compare-btn {
    padding: .6rem 1rem; border-radius: 50px;
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
    color: var(--white); font-family: var(--font-body); font-weight: 600; font-size: .8rem;
    cursor: pointer; transition: all .2s;
}
.v-compare-btn:hover { background: rgba(255,255,255,.15); }
.v-compare-btn.primary { background: var(--accent); border-color: var(--accent); }
.v-compare-btn.primary:hover { background: var(--accent-hover); }

@media (max-width: 500px) {
    .v-compare-images { grid-template-columns: 1fr 1fr; gap: .5rem; }
    .v-compare-card { padding: 1rem; }
    .v-compare-btn { font-size: .75rem; padding: .5rem .75rem; }
}

/* ========== DESKTOP OVERRIDES ========== */
@media (min-width: 901px) {
    .v-nav {
        position: static; background: none; backdrop-filter: none; border: none;
        max-width: 700px; margin: 1rem auto 2rem; padding: .5rem 0;
    }
    .v-toolbar {
        position: static; background: var(--dark); backdrop-filter: none;
        max-width: 900px; margin: 0 auto; border-bottom: none;
        border-radius: 0 0 12px 12px; padding: .75rem 1.25rem;
    }
    .v-viewport { padding-top: 0; padding-bottom: 0; min-height: auto; padding: 1rem 0; }
    .v-cover { max-width: 380px; }
}

/* ===== Preview paywall ===== */
.v-paywall {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 1rem;
}
.v-paywall-card {
    max-width: 480px;
    width: 100%;
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid rgba(233, 69, 96, .35);
    border-radius: 18px;
    padding: 2.2rem 2rem;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.v-paywall-icon {
    font-size: 2.4rem;
    margin-bottom: .8rem;
}
.v-paywall-title {
    font-size: 1.45rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: .7rem;
}
.v-paywall-sub {
    font-size: .92rem;
    color: rgba(255, 255, 255, .75);
    line-height: 1.55;
    margin-bottom: 1.2rem;
}
.v-paywall-perks {
    display: flex;
    flex-direction: column;
    gap: .55rem;
    text-align: left;
    margin: 0 auto 1.4rem;
    max-width: 320px;
}
.v-paywall-perk {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .85rem;
    color: rgba(255, 255, 255, .85);
}
.v-paywall-cta {
    display: inline-block;
    width: 100%;
    background: linear-gradient(135deg, #e94560, #ff6b81);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: .95rem 1.4rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.v-paywall-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(233, 69, 96, .45);
}
.v-paywall-later {
    display: inline-block;
    margin-top: .7rem;
    background: none;
    border: none;
    color: rgba(255, 255, 255, .5);
    font-size: .82rem;
    cursor: pointer;
    text-decoration: underline;
}
.v-paywall-later:hover { color: rgba(255, 255, 255, .8); }
