/* ==================================================================
   Wyndham — Reader
   ------------------------------------------------------------------
   The reading surface fills the screen and the chrome gets out of the
   way. Tapping the middle of the page shows or hides the bars; the
   page colour flows out to the bars and the system status bar so the
   whole device matches the paper.
   ================================================================== */

.reader {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    flex-direction: column;
    background: var(--reader-paper, var(--bg));
    color: var(--reader-ink, var(--text));
    overflow: hidden;
}

/* --- Chrome ------------------------------------------------------- */

.reader__bar {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 12;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) max(var(--space-3), var(--safe-left)) var(--space-2) max(var(--space-3), var(--safe-right));
    background: var(--reader-paper, var(--bg));
    color: var(--reader-ink, var(--text));
    transition: transform var(--duration-slow) var(--ease), opacity var(--duration-base) var(--ease);
}

.reader__bar--top {
    top: 0;
    padding-top: calc(var(--space-2) + var(--safe-top));
    min-height: 52px;
}

.reader__bar--bottom {
    bottom: 0;
    flex-direction: column;
    gap: var(--space-2);
    padding-bottom: calc(var(--space-3) + var(--safe-bottom));
}

.reader.is-immersive .reader__bar--top    { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.is-immersive .reader__bar--bottom { transform: translateY(100%);  opacity: 0; pointer-events: none; }

.reader__title {
    flex: 1;
    min-width: 0;
    font-size: var(--size-sm);
    font-weight: var(--weight-medium);
    letter-spacing: var(--tracking-snug);
    text-align: center;
    opacity: 0.72;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader__bar .icon-btn { color: inherit; opacity: 0.78; }
.reader__bar .icon-btn:hover { opacity: 1; background: rgba(127, 127, 127, 0.13); }

/* --- Reading surface ---------------------------------------------- */

.reader__surface {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.reader-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
}

/* Tap zones: left third turns back, right third forward, centre
   toggles the chrome. Only active in paginated mode. */
.reader__zones {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr 1.1fr 1fr;
    pointer-events: none;
}

.reader__zones.is-enabled > * { pointer-events: auto; }
.reader__zone { -webkit-tap-highlight-color: transparent; }

/* --- Progress ----------------------------------------------------- */

.reader__progress {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    font-size: var(--size-2xs);
    font-variant-numeric: tabular-nums;
    opacity: 0.62;
}

.reader__scrubber {
    flex: 1;
    height: 22px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.reader__scrubber::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: var(--radius-full);
    background: currentColor;
    opacity: 0.28;
}

.reader__scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    margin-top: -6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.reader__scrubber::-moz-range-track {
    height: 3px;
    border-radius: var(--radius-full);
    background: currentColor;
    opacity: 0.28;
}

.reader__scrubber::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
}

.reader__tools {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 100%;
}

/* --- Loading and errors ------------------------------------------- */

.reader__status {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-6);
    text-align: center;
    background: var(--reader-paper, var(--bg));
    color: var(--reader-ink, var(--text));
}

.reader__status p { max-width: 44ch; opacity: 0.7; line-height: var(--leading-normal); }
.reader__status .spin { opacity: 0.5; }

/* --- Selection popover -------------------------------------------- */

.reader__popover {
    position: absolute;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1);
    border: 1px solid var(--material-line);
    border-radius: var(--radius-md);
    background: var(--material);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    animation: pop-in var(--duration-fast) var(--ease-out);
}

@keyframes pop-in {
    from { opacity: 0; transform: scale(0.94) translateY(4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: transform var(--duration-fast) var(--ease);
}

.swatch:active { transform: scale(1.18); }
.swatch.is-active { border-color: var(--text); }

.swatch--yellow { background: #FBE28A; }
.swatch--green  { background: #A8E6A8; }
.swatch--blue   { background: #A6D2F5; }
.swatch--pink   { background: #F8B8CF; }
.swatch--purple { background: #CDBAF2; }
.swatch--orange { background: #FBC48A; }

/* --- PDF and comic surfaces --------------------------------------- */

.pdf-scroll, .comic-scroll {
    position: absolute;
    inset: 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--reader-paper, var(--bg));
}

.pdf-page {
    position: relative;
    margin: 0 auto var(--space-4);
    background: #fff;
    box-shadow: var(--shadow-md);
}

.pdf-page canvas { display: block; }

.pdf-page__placeholder {
    display: grid;
    place-items: center;
    background: var(--surface-2);
    color: var(--text-3);
    font-size: var(--size-sm);
}

.comic-page {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
}

.comic-page img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    -webkit-user-drag: none;
}

.comic-page--fit-width img { width: 100%; height: auto; max-height: none; object-fit: contain; }

/* --- Panels inside the reader ------------------------------------- */

.toc-item {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-sm);
    text-align: left;
    font-size: var(--size-base);
    line-height: var(--leading-snug);
    color: var(--text);
    transition: background var(--duration-fast) var(--ease);
}

.toc-item + .toc-item { box-shadow: inset 0 1px 0 var(--line); }
.toc-item:active { background: var(--surface-2); }
.toc-item.is-current { color: var(--accent); font-weight: var(--weight-semibold); }
.toc-item[data-depth="1"] { padding-left: var(--space-6); font-size: var(--size-sm); color: var(--text-2); }
.toc-item[data-depth="2"] { padding-left: var(--space-8); font-size: var(--size-sm); color: var(--text-3); }
.toc-item[data-depth="3"] { padding-left: var(--space-9); font-size: var(--size-sm); color: var(--text-3); }

/* Theme picker inside the appearance sheet. */
.paper-picker { display: flex; gap: var(--space-3); flex-wrap: wrap; }

.paper-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--size-xs);
    color: var(--text-2);
}

.paper-swatch i {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--line);
    font-family: var(--font-serif);
    font-size: 21px;
    font-style: normal;
    transition: border-color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}

.paper-swatch.is-active i { border-color: var(--accent); transform: scale(1.06); }

.font-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: var(--space-2); }

.font-option {
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    background: var(--surface);
    text-align: center;
    transition: var(--transition);
}

.font-option strong { display: block; font-size: var(--size-lg); font-weight: var(--weight-regular); }
.font-option span   { display: block; margin-top: 2px; font-size: var(--size-2xs); color: var(--text-2); }
.font-option.is-active { border-color: var(--accent); background: var(--accent-soft); }

.stepper {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.stepper output {
    flex: 1;
    text-align: center;
    font-size: var(--size-sm);
    font-variant-numeric: tabular-nums;
}

/* --- Annotation list ---------------------------------------------- */

.annotation {
    display: block;
    width: 100%;
    padding: var(--space-4);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    text-align: left;
}

.annotation + .annotation { margin-top: var(--space-3); }

.annotation__quote {
    padding-inline-start: var(--space-3);
    border-inline-start: 3px solid var(--accent);
    font-size: var(--size-sm);
    line-height: var(--leading-normal);
    color: var(--text);
}

.annotation__quote.is-yellow { border-color: #E5C245; }
.annotation__quote.is-green  { border-color: #6FBF6F; }
.annotation__quote.is-blue   { border-color: #5AA3DD; }
.annotation__quote.is-pink   { border-color: #E27CA0; }
.annotation__quote.is-purple { border-color: #9B7FDB; }
.annotation__quote.is-orange { border-color: #E09A4D; }

.annotation__note {
    margin-top: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-xs);
    background: var(--surface);
    font-size: var(--size-sm);
    line-height: var(--leading-normal);
}

.annotation__meta {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-3);
    font-size: var(--size-xs);
    color: var(--text-3);
}

/* --- Read-aloud bar ------------------------------------------------ */

.tts-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    padding-top: var(--space-1);
}

.tts-bar__play {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
}

.tts-bar__play svg { width: 19px; height: 19px; fill: currentColor; stroke: none; }
