/* ========================================
   DEĞİŞKENLER
======================================== */

:root {
    --paper: #faf6ed;
    --page-paper: #faf3e3;

    --navy: #172b42;
    --navy-light: #29435f;

    --gold: #b18b4e;
    --border: #d0c5b5;

    --text-muted: #697078;
}

/* ========================================
   TEMEL
======================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background-image: url("images/lale-motif.png");
    background-repeat: repeat;
    background-size: 200px 460px;

    color: var(--navy);
    font-family: "Inter", Arial, sans-serif;
}

button,
input,
select {
    font: inherit;
}

button,
input,
select {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
#flipbook:focus-visible {
    outline: 2px solid var(--navy);
    outline-offset: 3px;
}

[hidden] {
    display: none !important;
}

/* ========================================
   TEK EKRAN SAYFA DÜZENİ
======================================== */

.reader {
    width: min(1100px, calc(100% - 320px));

    height: 100vh;
    height: 100dvh;

    margin: 0 auto;
    padding: 18px 28px;

    display: flex;
    flex-direction: column;
    gap: 12px;

    overflow: hidden;

    background: var(--paper);
    border-inline: 3px double var(--navy);
}

/* ========================================
   ÜST KONTROLLER
======================================== */

.toolbar {
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 16px;

    min-height: 42px;
}

.toolbar-field,
.meal-toggle {
    display: flex;
    align-items: center;
    gap: 8px;

    font-size: 13px;
    line-height: 1.4;
}

.toolbar select,
.toolbar input[type="number"] {
    min-height: 40px;
    padding: 8px 10px;

    border: 1px solid var(--border);
    border-radius: 5px;

    background: #fcf9f1;
    color: var(--navy);
}

.toolbar select {
    max-width: 180px;
}

.toolbar input[type="number"] {
    width: 65px;
}

.toolbar-divider {
    width: 1px;
    height: 26px;
    background: var(--gold);
    opacity: 0.6;
}

/* MEAL ANAHTARI */

.meal-toggle input {
    appearance: none;
    position: relative;

    width: 42px;
    height: 24px;
    margin: 0;

    border: 0;
    border-radius: 20px;
    background: #c9c5bd;
}

.meal-toggle input::after {
    content: "";

    position: absolute;
    top: 3px;
    left: 3px;

    width: 18px;
    height: 18px;

    border-radius: 50%;
    background: #fff;
}

.meal-toggle input:checked {
    background: var(--navy);
}

.meal-toggle input:checked::after {
    left: 21px;
}

/* ========================================
   KİTAP SAHNESİ
======================================== */

.book-stage {
    position: relative;

    flex: 1 1 auto;
    min-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 12px;
    overflow: hidden;
}

#flipbook {
    position: relative;
    flex-shrink: 0;

    width: 800px;
    height: 480px;

    direction: ltr;
    touch-action: none;

    user-select: none;
    -webkit-user-select: none;
}

#flipbook:focus-visible {
    outline-offset: 6px;
}

/* ========================================
   SAYFALAR
======================================== */

#flipbook .quran-sheet {
    background: var(--page-paper);
    overflow: hidden;
}

.quran-sheet__inner {
    position: relative;

    width: 100%;
    height: 100%;
    padding: 22px;

    background: var(--page-paper);
}

/* Ortadaki birleşime doğru gölge */

#flipbook .odd .quran-sheet__inner {
    background: linear-gradient(
        to right,
        #eadfc9,
        #faf3e3 12%,
        #faf3e3 95%,
        #eee3ce
    );
}

#flipbook .even .quran-sheet__inner {
    background: linear-gradient(
        to right,
        #eee3ce,
        #faf3e3 5%,
        #faf3e3 88%,
        #eadfc9
    );
}

/* SAYFA ÇERÇEVESİ */

.quran-sheet__frame {
    position: relative;

    width: 100%;
    height: 100%;
    padding: 12px;

    border: 1px solid var(--gold);
    outline: 3px double var(--gold);
    outline-offset: 5px;
}

.quran-sheet__frame::before,
.quran-sheet__frame::after {
    content: "✧";

    position: absolute;
    left: 50%;
    transform: translateX(-50%);

    padding: 0 8px;

    background: var(--page-paper);
    color: var(--gold);

    font-size: 26px;
    line-height: 1;
}

.quran-sheet__frame::before {
    top: -14px;
}

.quran-sheet__frame::after {
    bottom: -14px;
}

/* PDF İÇİN BOŞ ALAN */

.quran-sheet__content {
    position: relative;

    width: 100%;
    height: 100%;

    overflow: hidden;
    direction: rtl;
}

.quran-sheet__content canvas,
.quran-sheet__content img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;
}

/* KİTAP GÖLGESİ */

#flipbook .shadow {
    box-shadow:
        0 6px 14px rgba(55, 39, 20, 0.16);
}

/* HATA MESAJI */

.book-error {
    max-width: 420px;
    padding: 22px;

    border: 1px solid var(--gold);
    border-radius: 8px;

    color: var(--navy);
    background: #fcf9f1;

    text-align: center;
    font-size: 14px;
    line-height: 1.7;
}

/* ========================================
   ALT KONTROLLER
======================================== */

.reader-controls {
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.page-button {
    min-height: 42px;
    padding: 9px 13px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    border: 1px solid var(--gold);
    border-radius: 8px;

    background: transparent;
    color: var(--navy);

    font-family: "Libre Caslon Display", Georgia, serif;
    font-size: 17px;
    line-height: 1.2;

    white-space: nowrap;

    transition: background-color 0.2s ease;
}

.page-button:hover:not(:disabled) {
    background: #eee5d4;
}

/* SES ÇUBUĞU */

.audio-bar {
    flex: 1;
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 6px 12px;

    border: 1px solid var(--border);
    border-radius: 30px;

    font-size: 13px;
}

.play-button {
    flex-shrink: 0;

    width: 34px;
    height: 34px;

    display: grid;
    place-items: center;

    border: 0;
    border-radius: 50%;

    background: var(--navy);
    color: #fff;
}

.play-button svg {
    display: block;
}

.audio-label {
    white-space: nowrap;
}

.audio-bar input {
    min-width: 20px;
    accent-color: var(--navy);
}

.audio-progress {
    flex: 1;
    width: 100%;
}

.audio-time {
    font-size: 10px;
    white-space: nowrap;
}

.volume-icon {
    flex-shrink: 0;
}

.audio-volume {
    width: 65px;
    flex-shrink: 0;
}

/* ========================================
   MEAL
======================================== */

.meal-panel {
    flex: 0 0 auto;

    padding: 12px 20px;

    border: 1px solid var(--gold);
    border-radius: 10px;
}

.meal-label {
    font-size: 11px;
}

.meal-panel p {
    margin: 6px 0 0;

    color: #5c6470;

    font-family: "Libre Caslon Display", Georgia, serif;
    font-size: 19px;
    line-height: 1.4;
}

/* DURUM SATIRI */

.reader-status {
    flex: 0 0 auto;
    margin: 0;

    color: var(--text-muted);

    font-size: 10px;
    line-height: 1.5;
    text-align: center;
}

/* ========================================
   TABLET
======================================== */

@media (max-width: 900px) {
    .reader {
        width: calc(100% - 80px);
        padding: 14px 18px;
        gap: 9px;
    }

    .reader-controls {
        flex-wrap: wrap;
    }

    .audio-bar {
        order: 3;
        flex-basis: 100%;
    }

    .page-button {
        min-height: 38px;
        padding: 7px 10px;
    }

    .meal-panel p {
        font-size: 17px;
    }
}

/* ========================================
   MOBİL
======================================== */

@media (max-width: 600px) {
    body {
        background-image: none;
    }

    .reader {
        width: 100%;
        padding: 10px;
        gap: 7px;
        border: 0;
    }

    .toolbar {
        min-height: 36px;
        gap: 8px;
    }

    .toolbar-field,
    .meal-toggle {
        gap: 4px;
        font-size: 11px;
    }

    .toolbar select,
    .toolbar input[type="number"] {
        min-height: 36px;
        padding: 5px 7px;
    }

    .toolbar select {
        max-width: 140px;
    }

    .toolbar input[type="number"] {
        width: 48px;
    }

    .toolbar-divider {
        height: 22px;
    }

    .book-stage {
        padding: 8px;
    }

    .quran-sheet__inner {
        padding: 12px;
    }

    .quran-sheet__frame {
        padding: 4px;
        outline-offset: 2px;
    }

    .quran-sheet__frame::before,
    .quran-sheet__frame::after {
        font-size: 18px;
        padding: 0 4px;
    }

    .quran-sheet__frame::before {
        top: -10px;
    }

    .quran-sheet__frame::after {
        bottom: -10px;
    }

    .page-button {
        font-size: 15px;
    }

    .audio-bar {
        gap: 8px;
    }

    .audio-volume {
        width: 45px;
    }

    .meal-panel {
        padding: 9px 12px;
    }

    .meal-panel p {
        font-size: 16px;
    }

    .reader-status {
        font-size: 9px;
    }
}

@media (max-width: 380px) {
    .toolbar-divider {
        display: none;
    }

    .audio-volume,
    .volume-icon {
        display: none;
    }
}

/* ========================================
   KISA EKRANLAR
======================================== */

@media (max-height: 650px) {
    .reader {
        padding-top: 8px;
        padding-bottom: 8px;
        gap: 6px;
    }

    .toolbar select,
    .toolbar input[type="number"] {
        min-height: 32px;
    }

    .meal-panel {
        padding: 7px 12px;
    }

    .meal-panel p {
        margin-top: 3px;
        font-size: 15px;
    }

    .play-button {
        width: 28px;
        height: 28px;
    }

    .page-button {
        min-height: 34px;
        padding: 6px 10px;
    }
}

@media (max-height: 420px) {
    .meal-panel {
        display: none;
    }
}

/* ========================================
   AZALTILMIŞ HAREKET
======================================== */

@media (prefers-reduced-motion: reduce) {
    .page-button {
        transition: none;
    }
}

/* Kitabın üzerinde: tutma imleci */
#flipbook,
#flipbook * {
    cursor: grab;
}

/* Fare basılıyken: kapalı el */
#flipbook:active,
#flipbook:active * {
    cursor: grabbing;
}

/* PDF SAYFALARI */

#flipbook .quran-sheet,
#flipbook .quran-sheet__inner {
    background: #fff4d8;
}

#flipbook .quran-sheet__inner {
    padding: 0;
    background-image: none;
}

#flipbook .quran-sheet__frame {
    padding: 0;
    border: 0;
    outline: 0;
}

#flipbook .quran-sheet__frame::before,
#flipbook .quran-sheet__frame::after {
    display: none;
}

.pdf-page-content {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #fff4d8;
}

.pdf-page-content canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pdf-page-placeholder {
    padding: 16px;
    color: #756849;
    font-size: 12px;
    text-align: center;
}

#flipbook,
#flipbook * {
    cursor: grab;
}

#flipbook:active,
#flipbook:active * {
    cursor: grabbing;
}

/* KİTABA DAHA FAZLA OKUMA ALANI */

.reader {
    padding: 8px 20px;
    gap: 6px;
}

.toolbar {
    min-height: 34px;
    gap: 12px;
}

.toolbar select,
.toolbar input[type="number"] {
    min-height: 34px;
    padding: 5px 9px;
}

.book-stage {
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px;
}

/* İçerikleri bağlanana kadar yer kaplamasın. */
.audio-bar,
.meal-panel {
    display: none;
}

.reader-controls {
    justify-content: space-between;
    gap: 10px;
}

.page-button {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 16px;
}

.reader-status {
    font-size: 10px;
    line-height: 1.2;
}

/* Mobil */

@media (max-width: 600px) {
    .reader {
        padding: 6px 8px;
        gap: 5px;
    }

    .toolbar {
        gap: 8px;
    }

    .page-button {
        min-height: 34px;
        font-size: 14px;
    }
}

/* ========================================
   OKUMA EKRANI — GÖRSEL İYİLEŞTİRMELER
======================================== */

:root {
    --reader-width: min(1100px, calc(100% - 320px));
    --side-width: calc((100% - var(--reader-width)) / 2);

    --paper: #faf6ed;
    --navy: #172b42;
    --gold: #b18b4e;
}

/* Eski yatay tekrar eden arka planı kaldır. */

body {
    position: relative;
    isolation: isolate;
    background: var(--paper);
}

/* Her kenara ayrı motif: yatay tekrar ve yarım desen yok. */

body::before,
body::after {
    content: "";
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--side-width);

    background-color: var(--paper);
    background-image:
        linear-gradient(
            rgba(250, 246, 237, 0),
            rgba(250, 246, 237, 0)
        ),
        url("images/lale-motif.png");

    background-repeat: repeat-y;
    background-position: center top;
    background-size: 100% auto;

    pointer-events: none;
    z-index: 0;
}

body::before {
    left: 0;
}

body::after {
    right: 0;
    transform: scaleX(-1);
}

/* ORTA ALAN */

.reader {
    position: relative;
    z-index: 1;

    width: var(--reader-width);
    padding: 10px 20px;
    gap: 8px;

    background: var(--paper);
    border-inline: 1px solid rgba(177, 139, 78, 0.4);

    box-shadow:
        -10px 0 22px rgba(55, 39, 20, 0.035),
         10px 0 22px rgba(55, 39, 20, 0.035);
}

/* ÜST KONTROLLER */

.toolbar {
    align-self: center;
    max-width: 100%;
    min-height: 42px;
    padding: 5px 16px;
    gap: 14px;

    border: 1px solid rgba(177, 139, 78, 0.22);
    border-radius: 8px;
    background: #f5efe3;
}

.toolbar-field,
.meal-toggle {
    font-size: 12px;
    color: #526174;
}

.toolbar select,
.toolbar input[type="number"] {
    min-height: 32px;
    padding: 5px 9px;

    border: 1px solid #d9cebc;
    border-radius: 4px;
    background: #fffaf0;
    color: var(--navy);
}

.toolbar input[type="number"] {
    width: 62px;
    text-align: center;
    font-weight: 500;
}

.toolbar select:disabled {
    opacity: 0.65;
}

.toolbar-divider {
    height: 20px;
    opacity: 0.35;
}

/* KİTAP */

.book-stage {
    padding: 6px 10px 12px;
}

/* Sabit orta gölge kitabın iki sayfasını ayırır. */

#flipbook::after {
    content: "";
    position: absolute;
    z-index: 2;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 16px;
    transform: translateX(-50%);

    background: linear-gradient(
        to right,
        transparent,
        rgba(80, 57, 25, 0.14),
        transparent
    );

    pointer-events: none;
}

#flipbook .shadow {
    box-shadow:
        0 3px 5px rgba(55, 39, 20, 0.08),
        0 10px 20px rgba(55, 39, 20, 0.12);
}

/* GEZİNME */

.reader-controls {
    align-items: center;
    padding: 0 4px;
}

.page-button {
    min-height: 38px;
    padding: 8px 16px;
    gap: 10px;

    border: 1px solid rgba(177, 139, 78, 0.6);
    border-radius: 6px;
    background: #fcf8ef;

    color: var(--navy);
    font-family: "Inter", Arial, sans-serif;
    font-size: 12px;
    font-weight: 500;

    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease;
}

.page-button:hover:not(:disabled) {
    border-color: var(--navy);
    background: var(--navy);
    color: #faf6ed;
}

.page-button:disabled {
    opacity: 0.35;
}

.reader-status {
    margin: 0;
    color: #8b8172;
    font-size: 10px;
    letter-spacing: 0.02em;
}

/* Henüz kullanılmayan alanlar gizli kalır. */

.audio-bar,
.meal-panel {
    display: none;
}

/* TABLET */

@media (max-width: 900px) {
    :root {
        --reader-width: calc(100% - 80px);
    }

    .reader {
        padding: 10px 12px;
    }

    .toolbar {
        padding: 5px 10px;
        gap: 10px;
    }
}

/* MOBİL */

@media (max-width: 600px) {
    :root {
        --reader-width: 100%;
    }

    body::before,
    body::after {
        display: none;
    }

    .reader {
        padding: 8px;
        border: 0;
        box-shadow: none;
        gap: 6px;
    }

    .toolbar {
        width: 100%;
        padding: 5px 8px;
        gap: 8px;
    }

    .toolbar-field,
    .meal-toggle {
        font-size: 11px;
    }

    .book-stage {
        padding: 4px 3px 8px;
    }

    .page-button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 11px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .page-button {
        transition: none;
    }
}