* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
}

body {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;

    overflow: hidden;

    background: #ffffff;
    color: #1d1d1f;
}

.hidden {
    display: none !important;
}


/* -------------------
   IMPORT
------------------- */

#importScreen {
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;

    display: flex;
    justify-content: center;
    align-items: safe center;

    padding: 30px;

    background: #101010;
    color: white;
}

.importCard {
    width: 640px;
    max-width: 100%;

    text-align: center;
}

.importCard h1 {
    font-size: 38px;
    margin-bottom: 10px;
}

.importCard p {
    color: #aaa;
    margin-bottom: 30px;
}

.importButton {
    display: inline-block;

    padding: 15px 30px;

    border-radius: 100px;

    background: white;
    color: black;

    font-weight: 600;

    cursor: pointer;
}

.muted {
    margin-top: 20px;

    font-size: 14px;

    color: #777 !important;
}


/* -------------------
   READER
------------------- */

#readerView {
    height: 100vh;
    height: 100dvh;

    display: flex;
    flex-direction: column;

    background: var(--background);
    color: var(--text);
}


/* -------------------
   TOP
------------------- */

.topBar {
    height: 65px;

    display: flex;
    align-items: center;

    padding: 8px 14px;

    border-bottom: 1px solid var(--border);

    flex-shrink: 0;
    padding-top: max(8px, env(safe-area-inset-top));
}

.bookInfo {
    flex: 1;

    min-width: 0;

    text-align: center;
}

#bookTitle {
    font-weight: 600;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chapterName {
    margin-top: 3px;

    font-size: 12px;

    color: var(--secondary);
}

.iconButton {
    width: 44px;
    height: 44px;

    border: none;
    border-radius: 50%;

    background: transparent;
    color: var(--text);

    font-size: 18px;

    cursor: pointer;
}


/* -------------------
   CHAPTER BAR
------------------- */

.chapterBar {
    padding: 8px 15px;

    border-bottom: 1px solid var(--border);

    background: var(--background);

    flex-shrink: 0;
}

#chapterSelect {
    width: 100%;

    padding: 9px;

    border: none;

    background: transparent;
    color: var(--text);

    text-align: center;

    font-size: 14px;
}


/* -------------------
   SETTINGS
------------------- */

.settingsPanel {
    position: absolute;

    z-index: 20;

    top: 60px;
    right: 15px;

    width: 300px;
    max-height: calc(100dvh - 100px);
    overflow-y: auto;

    padding: 18px;

    border: 1px solid var(--border);
    border-radius: 14px;

    background: var(--panel);

    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.18);
}

.settingRow {
    display: flex;
    justify-content: space-between;
    align-items: center;

    margin: 12px 0;
}

.settingRow button,
.settingRow select,
.voiceSetting select {
    padding: 8px 12px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--background);
    color: var(--text);

    cursor: pointer;
}

.voiceSetting {
    margin-top: 20px;

    display: flex;
    flex-direction: column;

    gap: 8px;

    text-align: left;
}

.voiceSetting select {
    width: 100%;
}


/* -------------------
   BOOK TEXT
------------------- */

#readerScroll {
    flex: 1;

    overflow-y: auto;

    scroll-behavior: smooth;

    background: var(--background);
}

#reader {
    max-width: 720px;

    margin: 0 auto;

    padding:
        55px
        34px
        160px;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-size: var(--reader-size);

    line-height: 1.75;
}

#reader h1,
#reader h2,
#reader h3 {
    line-height: 1.3;

    margin-top: 2em;
    margin-bottom: 0.8em;
}

#reader h1 {
    font-size: 1.8em;
}

#reader h2 {
    font-size: 1.45em;
}

#reader h3 {
    font-size: 1.2em;
}

#reader p {
    margin:
        0
        0
        1.35em;
}

.book-list-item {
    padding-left: 18px;
}


/* -------------------
   SENTENCES
------------------- */

.sentence {
    border-radius: 4px;

    cursor: pointer;

    transition:
        background 0.15s,
        box-shadow 0.15s;
}

.sentence:hover {
    background: var(--hover);
}

.sentence.active {
    background: var(--highlight);

    box-shadow:
        0 0 0 2px var(--highlight);
}


/* -------------------
   PLAYER
------------------- */

.bottomBar {
    flex-shrink: 0;

    padding:
        0
        14px
        10px;

    background: var(--panel);

    border-top: 1px solid var(--border);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.progressTrack {
    height: 4px;

    margin-bottom: 10px;

    background: var(--border);
}

#progressFill {
    width: 0%;
    height: 100%;

    background: var(--text);

    transition: width 0.2s;
}

.audioControls {
    display: flex;

    justify-content: center;
    align-items: center;

    gap: 12px;
}

.audioControls button {
    width: 42px;
    height: 42px;

    border: none;
    border-radius: 50%;

    background: transparent;
    color: var(--text);

    font-size: 18px;

    cursor: pointer;
}

.audioControls .playButton {
    width: 52px;
    height: 52px;

    background: var(--text);
    color: var(--background);

    font-size: 20px;
}

#speedSelect {
    padding: 8px;

    border: 1px solid var(--border);
    border-radius: 8px;

    background: var(--background);
    color: var(--text);
}

.bookControls {
    display: flex;

    align-items: center;
    justify-content: space-between;

    margin-top: 4px;
}

.bookControls button {
    border: none;

    padding: 8px;

    background: transparent;
    color: var(--text);

    cursor: pointer;
}

#progressText {
    font-size: 13px;

    color: var(--secondary);
}

#audioStatus {
    text-align: center;

    min-height: 16px;

    font-size: 12px;

    color: var(--secondary);
}


/* -------------------
   THEMES
------------------- */

body[data-theme="light"] {
    --background: #ffffff;
    --panel: #ffffff;
    --text: #202020;
    --secondary: #777;
    --border: #e5e5e5;

    --highlight: #ffe88a;
    --hover: #f2f2f2;
}

body[data-theme="sepia"] {
    --background: #f4ecd8;
    --panel: #f4ecd8;
    --text: #382f25;
    --secondary: #756857;
    --border: #d8cdb5;

    --highlight: #e8cd83;
    --hover: #eadfc5;
}

body[data-theme="dark"] {
    --background: #121212;
    --panel: #181818;
    --text: #e8e8e8;
    --secondary: #888;
    --border: #303030;

    --highlight: #665a20;
    --hover: #252525;
}


/* -------------------
   MOBILE
------------------- */

@media (max-width: 600px) {

    #reader {
        padding:
            35px
            23px
            170px;

        line-height: 1.7;
    }

    .topBar {
        height: 60px;
    }

    .settingsPanel {
        right: 10px;

        width:
            calc(100% - 20px);
    }

    .audioControls {
        gap: 7px;
    }
}

#libraryList { list-style: none; padding: 0; text-align: left; }
#libraryList li { display: flex; align-items: center; gap: 8px; border-top: 1px solid #333; padding: 14px 0; }
#libraryList button { border: 1px solid #555; border-radius: 9px; padding: 10px; color: white; background: #242424; cursor: pointer; min-height: 44px; }
#libraryList .libraryOpen { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; font-size: 16px; overflow-wrap: anywhere; }
.libraryOpen small { display: block; color: #aaa; margin-top: 6px; font-size: 12px; }
.importCard .installHint, .importCard #libraryStatus { font-size: 13px; line-height: 1.6; margin-bottom: 16px; }
#connectionStatus:not(:empty) { background: #ffe88a; color: #202020; border-radius: 8px; padding: 10px; font-size: 13px; line-height: 1.5; }
#deviceVoiceSettings { display: flex; flex-direction: column; gap: 10px; }
#deviceVoiceSettings[hidden] { display: none; }
.voiceSetting small { line-height: 1.5; color: var(--secondary); }
.voiceSetting button, .voiceSetting input { padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--background); color: var(--text); min-height: 44px; max-width: 100%; }
.voiceSetting input[type="range"] { width: 100%; padding: 0; }
.presetButtons { display: flex; flex-wrap: wrap; gap: 6px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #b99024; outline-offset: 3px; }
