/* ===========================================================================
   Reader — the open book
   ---------------------------------------------------------------------------
   Loaded after refresh.css and profile.css on index.html. The left page is
   the night sky the rest of the site uses (cover, title, stars, player); the
   right page is paper, where the story is read. On narrow screens the two
   stack: night on top, paper below. main.css still owns the modal's open
   animation and the phone bottom-sheet positioning.
   =========================================================================== */

:root {
    --paper: #FFFCF5;
    --paper-edge: #F3EEE2;
    --paper-rule: rgba(120, 96, 60, 0.14);
    --ink: #1F1B2E;
    --ink-soft: #5B5566;                 /* 6.6:1 on the paper */
    --night-text: rgba(236, 240, 255, 0.86);
    --night-line: rgba(255, 255, 255, 0.14);
    --night-glass: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] {
    --paper: #10162F;
    --paper-edge: #0C1127;
    --paper-rule: rgba(163, 171, 255, 0.14);
    --ink: #ECEFFD;
    --ink-soft: #A7AED0;                 /* 7.9:1 on the dark paper */
}

/* ── The book ────────────────────────────────────────────────────────────── */

#read-modal .book-modal-content {
    width: calc(100% - 48px);
    max-width: 1180px;
    height: min(92vh, 900px);
    max-height: none;
    margin: 4vh auto 0;
    padding: 0;
    border: 0;
    border-radius: 32px;
    overflow: hidden;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 40px 120px rgba(8, 10, 32, 0.55);
}

#read-modal .book-layout {
    flex: 1;
    min-height: 0;
    gap: 0;
}

/* Left page: night */
#read-modal .book-left {
    flex: 0 0 min(420px, 40%);
    box-sizing: border-box;
    padding: 26px 28px 32px;
    border-right: 0;
    align-items: stretch;
    overflow-y: auto;
    color: #fff;
    background:
        radial-gradient(1.4px 1.4px at 30px 40px, rgba(255, 255, 255, 0.8) 50%, transparent 52%),
        radial-gradient(1px 1px at 150px 90px, rgba(255, 255, 255, 0.6) 50%, transparent 52%),
        radial-gradient(1.2px 1.2px at 260px 30px, rgba(255, 243, 196, 0.9) 50%, transparent 52%),
        radial-gradient(1px 1px at 340px 140px, rgba(255, 255, 255, 0.5) 50%, transparent 52%),
        radial-gradient(120% 60% at 90% 0%, rgba(109, 74, 255, 0.55) 0%, transparent 60%),
        radial-gradient(90% 50% at 0% 100%, rgba(37, 99, 235, 0.4) 0%, transparent 60%),
        linear-gradient(170deg, #0B1026 0%, #151B52 55%, #231C66 100%);
    background-size: 380px 200px, 380px 200px, 380px 200px, 380px 200px, auto, auto, auto;
    background-repeat: repeat, repeat, repeat, repeat, no-repeat, no-repeat, no-repeat;
    scrollbar-width: none;
}

/* Right page: paper, with the spine's shadow falling on its inner edge */
#read-modal .book-right {
    position: relative;
    flex: 1;
    padding: 24px 52px 44px 56px;
    background: var(--paper);
    box-shadow: inset 30px 0 34px -30px rgba(8, 10, 32, 0.35);
    color: var(--ink);
    scrollbar-width: thin;
    scrollbar-color: var(--paper-rule) transparent;
}

/* A gold bookmark ribbon over the top edge of the page. */
#read-modal .book-right::before {
    content: '';
    position: absolute;
    top: 0;
    left: 30px;
    width: 18px;
    height: 58px;
    background: linear-gradient(180deg, #FFB547, #FFD27A);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
    box-shadow: 0 2px 6px rgba(154, 91, 0, 0.3);
    pointer-events: none;
}

/* ── Close ───────────────────────────────────────────────────────────────── */

#read-modal .bk-close {
    top: 16px;
    right: 16px;
    z-index: 120;
    width: 44px;
    height: 44px;
    border: 1px solid var(--paper-rule);
    background: var(--paper);
    color: var(--ink);
    font-size: 1rem;
    box-shadow: 0 6px 18px rgba(8, 10, 32, 0.12);
    cursor: pointer;
    transition: transform 0.2s var(--ease-out), background 0.2s;
}

#read-modal .bk-close .i {
    width: 20px;
    height: 20px;
}

/* main.css turns any focused .close-btn red with !important. */
#read-modal .bk-close:hover,
#read-modal .bk-close:focus,
#read-modal .bk-close:active {
    background: var(--paper-edge) !important;
    color: var(--ink) !important;
    border-color: var(--paper-rule);
    box-shadow: 0 6px 18px rgba(8, 10, 32, 0.12) !important;
}

#read-modal .bk-close:hover {
    transform: rotate(90deg);
}

#profile-modal .pf-close:focus {
    background: rgba(255, 255, 255, 0.24) !important;
    color: #fff !important;
    box-shadow: none !important;
}

/* ── Left page: heading ──────────────────────────────────────────────────── */

#read-modal .bk-toprow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    margin-bottom: 18px;
}

#read-modal .bk-category {
    color: #FFE08A;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#read-modal .bk-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

#read-modal .share-btn-aesthetic {
    min-height: 40px;
    padding: 0 14px;
    gap: 6px;
    border: 1px solid var(--night-line);
    border-radius: 999px;
    background: var(--night-glass);
    color: #fff !important;               /* the JS paints the heart's button blue/red */
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 800;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#read-modal .share-btn-aesthetic:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: none;
    transform: translateY(-1px);
}

#read-modal .share-btn-aesthetic svg {
    width: 17px;
    height: 17px;
}

#read-modal .book-title {
    margin: 0 0 10px;
    color: #fff;
    font-size: clamp(1.6rem, 2.4vw, 2.1rem);
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-wrap: balance;
}

/* Stars: gold on the night, faint until chosen */
#read-modal .star-rating-container {
    gap: 6px;
    margin: 0 0 16px;
    font-size: 1.9rem;
    color: rgba(255, 255, 255, 0.25);
}

#read-modal .star-rating-container:hover span {
    color: #FFC247;
}

#read-modal .star-rating-container span:hover ~ span {
    color: rgba(255, 255, 255, 0.25);
}

#read-modal .star-rating-container span.active,
#read-modal .star-rating-container:not(:hover) span.active {
    color: #FFC247 !important;
    transform: none;
    filter: drop-shadow(0 2px 8px rgba(255, 194, 71, 0.5));
}

#read-modal .modal-metadata {
    gap: 8px;
    margin: 0 0 18px;
    padding: 0;
    background: none;
    justify-content: center;
}

#read-modal .meta-item {
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--night-glass);
    border: 1px solid var(--night-line);
    color: var(--night-text);
    font-size: 0.85rem;
    font-weight: 700;
}

#read-modal .meta-item span {
    color: #fff;
}

#read-modal .book-img {
    display: block;
    width: 100%;
    max-height: 300px;
    margin: 0 0 6px;
    object-fit: cover;
    border: 0;
    border-radius: 22px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 24px 48px rgba(0, 0, 0, 0.45);
}

/* ── Left page: player ───────────────────────────────────────────────────── */

#read-modal .custom-player {
    margin-top: 16px;
    padding: 18px 16px 16px;
    gap: 10px;
    border: 1px solid var(--night-line);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
}

#read-modal .progress-container {
    width: 100% !important;
    height: 8px;
    margin: 4px 0 !important;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    box-shadow: none;
}

#read-modal .progress-bar {
    border-radius: 999px;
    background: linear-gradient(90deg, #FFE08A, #FFB547);
    box-shadow: 0 0 10px rgba(255, 194, 71, 0.5);
}

#read-modal .time-display {
    color: var(--night-text);
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#read-modal .player-main-controls {
    gap: 22px;
}

#read-modal .skip-time-btn {
    width: 50px;
    height: 50px;
    padding: 0;                          /* .player-control-btn's 18px squeezed the icon to 14px */
    border: 1px solid var(--night-line);
    border-radius: 50%;
    background: var(--night-glass);
    color: #fff;
    box-shadow: none;
    font-size: 1rem;
}

#read-modal .skip-time-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    transform: scale(1.06);
}

#read-modal .skip-time-btn svg {
    width: 26px;
    height: 26px;
}

#read-modal .play-btn {
    width: 72px;
    min-width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #FFE08A 0%, #FFC247 55%, #FFB547 100%);
    color: #1B1F3B;
    box-shadow: 0 12px 30px rgba(255, 181, 71, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

#read-modal .play-btn svg {
    width: 28px;
    height: 28px;
    fill: #1B1F3B;
}

#read-modal .play-btn #play-icon {
    margin-left: 3px;
}

#read-modal .play-btn #buffer-icon {
    fill: none;
    color: #1B1F3B;
}

#read-modal .play-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 16px 36px rgba(255, 181, 71, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

#read-modal .play-btn.playing {
    box-shadow: 0 0 0 6px rgba(255, 194, 71, 0.18), 0 12px 30px rgba(255, 181, 71, 0.35);
}

#read-modal .volume-container {
    width: 100%;
    max-width: 280px;
    box-sizing: border-box;
    padding: 8px 16px;
    border: 1px solid var(--night-line);
    border-radius: 999px;
    background: var(--night-glass);
    box-shadow: none;
    color: #fff;
}

#read-modal #volume-slider {
    height: 5px;
    background: rgba(255, 255, 255, 0.22);
}

#read-modal #volume-slider::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    border: 0;
    background: #FFC247;
    box-shadow: 0 2px 8px rgba(255, 181, 71, 0.5);
}

#read-modal #volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 0;
    border-radius: 50%;
    background: #FFC247;
}

/* The nine extras: one glass grid, every one of them visible. */
#read-modal .player-extra-controls {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 4px 0 0;
    overflow: visible;
}

#read-modal .player-extra-controls .player-control-btn {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: auto;
    height: auto;
    min-height: 66px;
    padding: 8px 4px;
    border: 1px solid var(--night-line);
    border-radius: 16px;
    background: var(--night-glass);
    color: #fff;
    box-shadow: none;
    font-size: 1.25rem;
    line-height: 1;
    transform: none;
}

#read-modal .player-extra-controls .player-control-btn span {
    display: block !important;
    color: var(--night-text);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
    opacity: 1;
}

#read-modal .player-extra-controls .player-control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.28);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: none;
}

#read-modal .player-extra-controls .player-control-btn:active {
    transform: scale(0.95);
}

/* One "on" look for every toggle (ambient, timer, scroll, speed) */
#read-modal .player-extra-controls .player-control-btn.active {
    background: rgba(255, 194, 71, 0.18);
    border-color: rgba(255, 214, 107, 0.7);
    color: #FFE08A;
    box-shadow: 0 0 0 3px rgba(255, 194, 71, 0.12);
}

#read-modal .player-extra-controls .player-control-btn.active span {
    color: #FFE08A;
}

#read-modal .btn-mic.recording {
    background: #DC2626;
    border-color: transparent;
}

#read-modal .speed-popup {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: var(--shadow-lg);
}

/* Parent recordings and tags keep their own colours, on glass */
#read-modal #parent-voice-section {
    border-radius: 22px !important;
    box-shadow: none !important;
}

#read-modal .modal-tags {
    gap: 6px;
    margin: 20px 0 0 !important;
    justify-content: center;
}

#read-modal .tag-pill {
    padding: 6px 12px;
    border: 1px solid var(--night-line);
    border-radius: 999px;
    background: var(--night-glass);
    color: var(--night-text);
    box-shadow: none;
    font-size: 0.8rem;
    font-weight: 700;
}

#read-modal .tag-pill:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
    transform: none;
    box-shadow: none;
}

/* ── Right page: the story ───────────────────────────────────────────────── */

#read-modal .resizer-controls {
    justify-content: flex-end;
    gap: 6px;
    margin: 0 56px 18px 0;               /* clear of the close button */
}

.resizer-label {
    margin-right: 4px;
    color: var(--ink-soft);
    font-family: 'Noto Serif Georgian', serif;
    font-size: 1rem;
    font-weight: 700;
}

#read-modal .resizer-btn {
    min-width: 40px;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid var(--paper-rule);
    border-radius: 999px;
    background: transparent;
    color: var(--ink);
    box-shadow: none;
    font-size: 0.85rem;
}

#read-modal .resizer-btn:hover {
    background: var(--paper-edge);
    border-color: var(--paper-rule);
    color: var(--ink);
}

.resizer-value {
    min-width: 46px;
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

#read-modal .book-text-container {
    max-width: 68ch;
}

#read-modal .book-text {
    color: var(--ink);
    font-family: 'Noto Serif Georgian', 'Noto Sans Georgian', serif;
    font-size: 1.2em;
    line-height: 1.95;
    letter-spacing: 0.005em;
}

#read-modal .book-text::first-letter {
    margin: 6px 12px 0 0;
    color: var(--gold-text);
    font-family: 'Noto Serif Georgian', serif;
    font-size: 3.6em;
    font-weight: 700;
    line-height: 0.85;
    text-shadow: none;
}

#read-modal .book-pagination {
    gap: 12px;
    margin: 8px 0 28px;
    padding: 18px 0;
    border-top: 1px solid var(--paper-rule);
    border-bottom: 1px solid var(--paper-rule);
}

#read-modal .page-btn {
    min-height: 44px;
    padding: 0 20px;
    border: 1px solid var(--paper-rule);
    border-radius: 999px;
    background: transparent;
    color: var(--ink);
    box-shadow: none;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 800;
}

#read-modal .page-btn:hover:not(:disabled) {
    border-color: transparent;
    background: var(--primary-gradient);
    color: #fff;
    transform: none;
    box-shadow: var(--shadow-primary);
}

#read-modal .page-btn:disabled {
    opacity: 0.4;
    background: transparent;
}

#read-modal .page-num {
    padding: 6px 16px;
    border-radius: 999px;
    background: var(--paper-edge);
    color: var(--ink);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

#read-modal .dict-word {
    color: var(--primary-text);
    border-bottom-color: rgba(37, 99, 235, 0.4);
}

/* Related stories */
#read-modal .related-section {
    margin-top: 8px;
    padding-top: 0;
    border-top: 0;
}

#read-modal .related-title,
#read-modal .comments-title {
    margin-bottom: 14px;
    color: var(--ink);
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: 0;
}

#read-modal .related-grid {
    gap: 12px;
    padding-bottom: 8px;
    scrollbar-width: none;
}

#read-modal .related-card {
    flex: 0 0 150px;
    text-align: left;
}

#read-modal .related-card:hover {
    transform: translateY(-3px);
}

#read-modal .related-img {
    height: auto;
    aspect-ratio: 31 / 24;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 6px 16px rgba(8, 10, 32, 0.14);
}

#read-modal .related-card-title {
    margin-top: 8px;
    color: var(--ink);
    font-size: 0.85rem;
    line-height: 1.35;
}

/* Comments */
#read-modal .comments-section {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--paper-rule);
}

#read-modal .add-comment-box {
    flex-direction: row;
    gap: 8px;
    margin-bottom: 20px;
    padding: 6px;
    border: 1px solid var(--paper-rule);
    border-radius: 18px;
    background: var(--paper-edge);
    box-shadow: none;
}

#read-modal .add-comment-box:focus-within {
    border-color: var(--primary-color);
    box-shadow: var(--ring);
}

#read-modal .comment-input {
    margin: 0;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 16px;
    box-shadow: none;
}

#read-modal .comment-input:focus {
    box-shadow: none;
}

#read-modal .comment-submit-btn {
    width: auto;
    margin: 0;
    padding: 0 18px;
    min-height: 44px;
    border-radius: 14px;
    font-size: 0.9rem;
}

#read-modal .comment-item {
    border: 1px solid var(--paper-rule);
    border-radius: 18px;
    background: var(--paper);
    box-shadow: none;
}

#read-modal .comment-author {
    color: var(--ink);
}

#read-modal .comment-text {
    color: var(--ink);
}

#read-modal .comment-date {
    color: var(--ink-soft);
}

/* ── Quiz: the night sky again, over the whole book ──────────────────────── */

#read-modal #quiz-overlay {
    background:
        radial-gradient(120% 70% at 85% 0%, rgba(109, 74, 255, 0.55) 0%, transparent 60%),
        linear-gradient(170deg, rgba(11, 16, 38, 0.97) 0%, rgba(21, 27, 82, 0.97) 60%, rgba(35, 28, 102, 0.97) 100%);
    color: #fff;
}

#read-modal .quiz-title {
    color: #fff;
    font-size: clamp(1.5rem, 3vw, 2.1rem);
    letter-spacing: 0;
}

#read-modal .quiz-btn {
    border: 1px solid var(--night-line);
    border-radius: 18px;
    background: var(--night-glass);
    color: #fff;
    box-shadow: none;
    font-size: 1.05rem;
}

#read-modal .quiz-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: none;
    box-shadow: none;
}

#read-modal #quiz-progress,
#read-modal #quiz-result-score,
#read-modal #quiz-skip-btn {
    color: var(--night-text) !important;
}

#read-modal #quiz-next-btn,
#read-modal #quiz-result button {
    background: linear-gradient(135deg, #FFE08A, #FFB547) !important;
    color: #1B1F3B !important;
}

#read-modal #quiz-result-points {
    color: #FFE08A !important;
}

/* ── Tablet and phone: the pages stack ───────────────────────────────────── */

@media (max-width: 950px) {
    #read-modal .book-modal-content {
        width: calc(100% - 32px);
        height: 94vh;
        margin-top: 3vh;
        overflow-y: auto;
        overscroll-behavior-y: contain;
    }

    #read-modal .book-layout {
        flex: none;
        gap: 0;
    }

    #read-modal .book-left {
        flex: none;
        padding: 60px 22px 26px;
        border-bottom: 0;
        overflow: visible;
    }

    #read-modal .book-right {
        flex: none;
        padding: 26px 22px 40px;
        overflow: visible;
        box-shadow: inset 0 26px 30px -26px rgba(8, 10, 32, 0.3);
    }

    #read-modal .book-right::before {
        left: auto;
        right: 26px;
    }

    #read-modal .bk-close {
        border-color: rgba(255, 255, 255, 0.22);
        background: rgba(255, 255, 255, 0.12);
        color: #fff;
        box-shadow: none;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    #read-modal .bk-close:hover,
    #read-modal .bk-close:focus,
    #read-modal .bk-close:active {
        background: rgba(255, 255, 255, 0.24) !important;
        color: #fff !important;
        border-color: rgba(255, 255, 255, 0.3);
        box-shadow: none !important;
    }

    #read-modal .book-img {
        max-height: 260px;
    }

    #read-modal .resizer-controls {
        margin-right: 36px;
    }

    #read-modal .book-text-container {
        max-width: none;
    }
}

@media (max-width: 600px) {
    #read-modal .book-modal-content {
        width: 100%;
        height: 96%;
        margin: 0;
        padding: 0;
        border-radius: 28px 28px 0 0;
    }

    /* the drag handle, now over the night page */
    #read-modal .book-modal-content::before {
        position: absolute;
        top: 8px;
        left: 50%;
        z-index: 5;
        margin: 0;
        transform: translateX(-50%);
        background: #fff;
        opacity: 0.45;
    }

    #read-modal .bk-close {
        top: calc(14px + env(safe-area-inset-top, 0px));
        right: 14px;
    }

    #read-modal .book-left {
        padding: 56px 16px 22px;
    }

    #read-modal .bk-toprow {
        padding-right: 52px;             /* clear of the close button */
    }

    #read-modal .book-title {
        font-size: 1.6rem;
        margin-bottom: 8px;
    }

    #read-modal .star-rating-container {
        font-size: 1.7rem;
        margin-bottom: 12px;
    }

    #read-modal .book-img {
        max-height: 210px;
        border-radius: 18px;
        box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
    }

    #read-modal .custom-player {
        padding: 16px 12px 12px;
        border-radius: 22px;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--night-line);
    }

    #read-modal .player-extra-controls {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    #read-modal .player-main-controls .skip-time-btn {
        width: 48px;
        height: 48px;
        border: 1px solid var(--night-line);
        background: var(--night-glass);
    }

    #read-modal .book-right {
        padding: 22px 18px calc(36px + env(safe-area-inset-bottom, 0px));
    }

    #read-modal .book-text {
        font-size: 1.1em;
        text-align: left;
    }

    #read-modal .book-pagination {
        gap: 8px;
    }

    #read-modal .page-btn {
        padding: 0 14px;
    }

    #read-modal .add-comment-box {
        flex-direction: row;
    }
}
