@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;900&display=swap');

:root {
    --gold: #E8A03F;
    --gold-dim: rgba(232, 160, 63, 0.15);
    --purple: #4A2E63;
    --purple-glass: rgba(74, 46, 99, 0.72);
    --onyx: #111111;
    --onyx-mid: #1a1a1a;
    --onyx-light: #222222;
    --text: #f2f2f2;
    --muted: rgba(242, 242, 242, 0.55);
    --bar-height: 64px;
    --bar-radius: 40px;
    --bar-margin: 12px;
}

/* ─── Reset ─────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    font-family: 'Cairo', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-drag: none;
}

img, svg, canvas { -webkit-user-drag: none; }

a, button, .subject-btn, .icon-btn, .page-btn,
.grid-page-btn, .close-btn, #pdf-container {
    pointer-events: auto;
}

@media print {
    html, body { display: none !important; visibility: hidden !important; }
}

/* ─── Menu Body ────────────────────────────────────── */
.menu-body {
    background-color: var(--onyx);
    color: var(--text);
    min-height: 100vh;
    padding: 36px 20px 48px;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
}

.menu-container {
    max-width: 580px;
    width: 100%;
    text-align: center;
}

/* ── Logo: rounded, no white box ── */
.main-logo {
    width: 140px;
    height: 140px;
    margin: 0 auto 36px;
    display: block;
    border-radius: 28px;
    overflow: visible;
    background: transparent;
    filter: drop-shadow(0 0 18px rgba(255,255,255,0.90)) drop-shadow(0 0 42px rgba(255,255,255,0.55)) drop-shadow(0 0 70px rgba(232,160,63,0.40));
    pointer-events: none;
    position: relative;
}

.main-logo::before {
    content: '';
    position: absolute;
    inset: -110px;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(255,255,255,0.72) 0%,
        rgba(255,255,255,0.48) 12%,
        rgba(255,240,200,0.28) 28%,
        rgba(232,160,63,0.14) 50%,
        rgba(74,46,99,0.05) 72%,
        transparent 88%);
    pointer-events: none;
    z-index: -1;
}

.main-logo svg,
.loading-logo svg {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

/* Make the white SVG background transparent */
.main-logo svg rect,
.loading-logo svg rect {
    fill: transparent !important;
}

.menu-container h2 {
    color: var(--gold);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin: 28px 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(74,46,99,0.7);
    position: relative;
}

.menu-container h2::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 50%;
    transform: translateX(-50%);
    width: 48px; height: 2px;
    background: var(--gold);
    border-radius: 2px;
}

.subject-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.subject-btn {
    background-color: var(--purple);
    color: var(--text);
    padding: 16px 10px;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.92rem;
    transition: background 0.18s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.06);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.subject-btn::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 60%);
    pointer-events: none;
}

.subject-btn:hover { background-color: #5a3978; }
.subject-btn:active {
    background-color: var(--gold);
    color: var(--onyx);
    transform: scale(0.97);
}

/* ─── Viewer Body ──────────────────────────────────── */
.viewer-body {
    background-color: #1c1c1c;
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ─── Watermark ────────────────────────────────────── */
/*
   Strategy: the overlay is full viewport, rotated -30deg and scaled up
   so the diagonal fills edge-to-edge with no gaps. The rows flex-wrap
   and the overlay uses CSS repeat-style tiling via enough content to
   exceed 100% in both axes before the transform clips it.
*/
#watermark-overlay {
    position: fixed;
    pointer-events: none !important;
    touch-action: none;
    z-index: 200;
    /* Expand well beyond viewport so rotation never reveals a bare edge */
    inset: -60%;
    width: 220%;
    height: 220%;
    transform: rotate(-28deg);
    transform-origin: center center;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.watermark-row {
    display: flex;
    flex-wrap: nowrap;
    flex-shrink: 0;
    align-items: center;
    /* Alternate rows offset by half a unit for brick-pattern density */
}

/* Wrapper that stacks both text layers */
.wm-pair {
    position: relative;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 2.6;
    pointer-events: none !important;
}

/* White layer — front */
.wm-pair .wm-white {
    font-size: 8.5px;
    font-weight: 600;
    padding: 0 22px;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.16);
    display: block;
    text-transform: none;
}

/* Grey shadow — offset behind, no blur */
.wm-pair .wm-shadow {
    font-size: 8.5px;
    font-weight: 600;
    padding: 0 22px;
    letter-spacing: 0.04em;
    color: rgba(110, 110, 110, 0.10);
    display: block;
    text-transform: none;
    position: absolute;
    top: 2px;
    left: 3px;
    width: 100%;
}

/* ─── Glassmorphism Bars ───────────────────────────── */
.hide-able {
    position: fixed;
    left: var(--bar-margin);
    right: var(--bar-margin);
    height: var(--bar-height);
    transition: transform 0.32s cubic-bezier(.4,0,.2,1), opacity 0.32s ease;
    background: rgba(58, 34, 80, 0.6);
    backdrop-filter: blur(3px) saturate(1.05);
    -webkit-backdrop-filter: blur(3px) saturate(1.05);
    border: 1px solid rgba(255,255,255,0.09);
    padding: 0 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    border-radius: var(--bar-radius);
    box-shadow: 0 6px 28px rgba(0,0,0,0.55);
}

.toolbar   { top: var(--bar-margin); }
.bottom-bar { bottom: var(--bar-margin); }

.toolbar.hidden    { transform: translateY(calc(-100% - var(--bar-margin) - 4px)); opacity: 0; pointer-events: none; }
.bottom-bar.hidden { transform: translateY(calc(100%  + var(--bar-margin) + 4px)); opacity: 0; pointer-events: none; }

.branding {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

/* Home button: gold */
#home-btn {
    color: var(--gold);
}
#home-btn:active {
    background: rgba(232,160,63,0.18);
}

/* Zoom buttons: white */
#zoom-in,
#zoom-out {
    color: #ffffff;
}
#zoom-in:active,
#zoom-out:active {
    background: rgba(255,255,255,0.15);
}

.controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

#zoom-level {
    font-weight: 700;
    font-size: 0.82rem;
    width: 46px;
    text-align: center;
    color: var(--gold);
    letter-spacing: 0.02em;
    cursor: pointer;
    border-bottom: 1px dashed rgba(232,160,63,0.4);
    padding-bottom: 1px;
    transition: color 0.15s;
}

#zoom-level:hover { color: #f0c060; }

/* ─── Icon Buttons ─────────────────────────────────── */
.icon-btn {
    background: transparent;
    color: var(--gold);
    border: none;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s, transform 0.12s;
    flex-shrink: 0;
    -webkit-touch-callout: none;
    pointer-events: auto;
}

.icon-btn:active {
    background: rgba(232,160,63,0.18);
    transform: scale(0.92);
}

.icon-btn .material-symbols-outlined {
    font-size: 26px;
    pointer-events: none;
}

/* ─── Bottom Bar ───────────────────────────────────── */
.page-info {
    display: flex;
    align-items: center;
    gap: 2px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.page-btn {
    background: rgba(0,0,0,0.35);
    color: var(--gold);
    padding: 4px 14px;
    margin: 0 6px;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 14px;
    border: 1px solid rgba(232,160,63,0.5);
    cursor: pointer;
    transition: background 0.15s;
    font-family: 'Cairo', sans-serif;
    pointer-events: auto;
}

.page-btn:active { background: rgba(232,160,63,0.2); }

/* ─── PDF Container ────────────────────────────────── */
#pdf-container {
    position: absolute;
    inset: 0;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: #1c1c1c;
    padding: calc(var(--bar-height) + var(--bar-margin) + 12px) 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 1;
    pointer-events: auto;
    touch-action: pan-x pan-y pinch-zoom;
    min-width: 0;
    perspective: 1200px; /* enables 3D paper-flip effect on canvas */
}

/* Wrapper to allow horizontal scroll when canvas exceeds viewport */
#pdf-container > canvas,
#pdf-render {
    box-shadow: 0 8px 40px rgba(0,0,0,0.7);
    border-radius: 2px;
    display: block;
    /* REMOVED max-width:100% so zoomed canvas can exceed phone width */
    max-width: none;
    pointer-events: none !important;
    -webkit-user-drag: none;
    flex-shrink: 0;
}

/* ─── Page Grid Modal ──────────────────────────────── */
#page-grid-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(20px) saturate(1.6);
    -webkit-backdrop-filter: blur(20px) saturate(1.6);
    z-index: 500;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 0;
    pointer-events: auto;
    transition: opacity 0.25s ease;
}

#page-grid-modal.hidden { display: none; }

.modal-content {
    background: linear-gradient(145deg, rgba(30,14,46,0.92) 0%, rgba(26,26,26,0.88) 100%);
    border: 1px solid rgba(232,160,63,0.18);
    border-bottom: none;
    border-radius: 28px 28px 0 0;
    padding: 8px 20px 32px;
    width: 100%;
    max-width: 480px;
    max-height: 72vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -8px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04) inset;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    position: relative;
    overflow: hidden;
}

/* Top drag handle indicator */
.modal-content::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(232,160,63,0.35);
    border-radius: 4px;
    margin: 10px auto 16px;
    flex-shrink: 0;
}

/* Purple glow at top edge */
.modal-content::after {
    content: '';
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(232,160,63,0.5), rgba(86,55,119,0.5), transparent);
    border-radius: 1px;
}

.modal-content h3 {
    color: var(--gold);
    text-align: center;
    margin-bottom: 14px;
    font-size: 1rem;
    letter-spacing: 0.06em;
    font-weight: 700;
    flex-shrink: 0;
}

#page-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 7px;
    overflow-y: auto;
    padding: 6px 2px 4px;
    flex-grow: 1;
    overscroll-behavior: contain;
}

#page-grid-container::-webkit-scrollbar { width: 3px; }
#page-grid-container::-webkit-scrollbar-track { background: transparent; }
#page-grid-container::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--gold), var(--purple));
    border-radius: 4px;
}

.grid-page-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 6px;
    color: rgba(242,242,242,0.75);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    transition: border-color 0.15s, background 0.15s, transform 0.12s, color 0.15s;
    pointer-events: auto;
    min-height: 48px;
    position: relative;
    overflow: hidden;
}

.grid-page-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 60%);
    pointer-events: none;
}

.grid-page-btn:hover  {
    background: rgba(74,46,99,0.45);
    border-color: rgba(86,55,119,0.5);
    color: var(--text);
}
.grid-page-btn:active { transform: scale(0.91); }

.grid-page-btn.active {
    background: linear-gradient(135deg, rgba(232,160,63,0.25) 0%, rgba(86,55,119,0.35) 100%);
    color: var(--gold);
    border-color: rgba(232,160,63,0.55);
    box-shadow: 0 0 0 1px rgba(232,160,63,0.2), 0 4px 16px rgba(232,160,63,0.15);
}

.close-btn {
    margin-top: 12px;
    background: linear-gradient(135deg, rgba(232,160,63,0.15) 0%, rgba(86,55,119,0.25) 100%);
    color: var(--gold);
    border: 1px solid rgba(232,160,63,0.35);
    padding: 12px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: background 0.18s, transform 0.12s;
    font-family: 'Cairo', sans-serif;
    pointer-events: auto;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    flex-shrink: 0;
}

.close-btn:active {
    transform: scale(0.97);
    background: rgba(232,160,63,0.25);
}

/* ─── Loading Screen ───────────────────────────────── */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--onyx);
    z-index: 9000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    transition: opacity 0.4s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Logo on loading screen: rounded, no white bg */
.loading-logo {
    width: 130px;
    height: 130px;
    border-radius: 22px;
    overflow: visible;
    background: transparent;
    filter: drop-shadow(0 0 18px rgba(255,255,255,0.92)) drop-shadow(0 0 44px rgba(255,255,255,0.56)) drop-shadow(0 0 72px rgba(232,160,63,0.40));
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Static radial glow backdrop behind the logo */
.loading-logo::before {
    content: '';
    position: absolute;
    inset: -110px;
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(255,255,255,0.75) 0%,
        rgba(255,255,255,0.50) 12%,
        rgba(255,240,200,0.28) 28%,
        rgba(232,160,63,0.14) 50%,
        rgba(74,46,99,0.05) 72%,
        transparent 88%);
    pointer-events: none;
    z-index: -1;
}

.loading-bar-wrap {
    width: 180px;
    height: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--purple), var(--gold));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.loading-text {
    color: var(--muted);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
}

/* ─── Zoom Picker Modal ────────────────────────────── */
#zoom-picker-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    z-index: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    pointer-events: auto;
}

#zoom-picker-modal.hidden { display: none; }

.zoom-picker-content {
    background: linear-gradient(145deg, rgba(30,14,46,0.95) 0%, rgba(22,22,22,0.92) 100%);
    border: 1px solid rgba(232,160,63,0.22);
    border-radius: 24px;
    padding: 24px 20px 20px;
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04) inset;
    position: relative;
    overflow: hidden;
}

.zoom-picker-content::after {
    content: '';
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(232,160,63,0.55), transparent);
}

.zoom-picker-content h3 {
    color: var(--gold);
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.zoom-option-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 14px;
    color: rgba(242,242,242,0.8);
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    padding: 13px 16px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    pointer-events: auto;
    text-align: center;
}

.zoom-option-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 60%);
    pointer-events: none;
}

.zoom-option-btn:active { transform: scale(0.96); }

.zoom-option-btn.active {
    background: linear-gradient(135deg, rgba(232,160,63,0.2) 0%, rgba(86,55,119,0.3) 100%);
    border-color: rgba(232,160,63,0.5);
    color: var(--gold);
    box-shadow: 0 0 0 1px rgba(232,160,63,0.18);
}

.zoom-option-btn:not(.active):hover {
    background: rgba(74,46,99,0.35);
    border-color: rgba(86,55,119,0.4);
    color: var(--text);
}

/* ─── Toast ────────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: calc(var(--bar-height) + var(--bar-margin) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30,10,10,0.92);
    border: 1px solid rgba(200,50,50,0.5);
    color: #ff8a8a;
    font-size: 0.82rem;
    padding: 10px 20px;
    border-radius: 20px;
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 600;
    white-space: nowrap;
    font-family: 'Cairo', sans-serif;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
