:root {
    /* --- E-Ink Light Mode (Paper) --- */
    --bg-color: #F4F4F0; 
    --surface-color: #FFFFFF;
    --text-primary: #111111; 
    --text-secondary: #444444;
    --accent-color: #111111;
    --accent-hover: #000000;
    --border-color: #999999; 
    --orp-color: #8B0000; 
    --progress-bg: #E0E0E0;
    --progress-fill: #333333; 
    --shadow: none; 
    --font-ui: 'Inter', sans-serif; 
    --font-reader: 'Merriweather', serif; 
    --transition-speed: 0.1s;
}

/* --- Dark Mode (OLED / Night E-Ink) --- */
[data-theme="dark"] {
    --bg-color: #111111;
    --surface-color: #000000;
    --text-primary: #DDDDDD;
    --text-secondary: #888888;
    --accent-color: #EEEEEE;
    --accent-hover: #FFFFFF;
    --border-color: #444444;
    --orp-color: #D94040; 
    --progress-bg: #333333;
    --progress-fill: #AAAAAA;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-primary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-bottom: 2px solid var(--text-primary); 
    z-index: 10;
}

.brand {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.02em;
}
.brand svg { width: 24px; height: 24px; fill: var(--text-primary); }

.header-controls { display: flex; align-items: center; gap: 0.5rem; }
button.icon-btn {
    background: none; border: 2px solid var(--text-primary); cursor: pointer; color: var(--text-primary);
    padding: 0.25rem 0.5rem; border-radius: 4px; transition: all 0.1s;
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.75rem; font-weight: 600;
    white-space: nowrap;
}
button.icon-btn:hover { background-color: var(--text-primary); color: var(--bg-color); }
button.icon-btn span { display: inline; }
@media (max-width: 600px) {
    button.icon-btn span { display: none; }
}

/* --- Main Content Area --- */
main { 
    flex: 1; 
    position: relative; 
    width: 100%; 
    display: flex;           
    justify-content: center; 
    align-items: center;     
}

/* 1. Upload State */
#upload-section {
    text-align: center; padding: 2rem; max-width: 600px; width: 100%;
    display: flex; flex-direction: column; gap: 1.5rem;
    align-items: center;
}
.upload-zone {
    border: 2px solid var(--text-primary); 
    border-radius: 0px; 
    padding: 4rem 2rem;
    background-color: var(--surface-color);
    transition: all 0.1s; cursor: pointer; width: 100%;
}
.upload-zone:hover { background-color: var(--bg-color); }
.upload-icon { width: 48px; height: 48px; fill: var(--text-primary); margin-bottom: 1rem; }
.upload-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.5rem; }
.upload-subtitle { color: var(--text-secondary); font-size: 0.875rem; font-family: var(--font-reader); }
input[type="file"] { display: none; }

.sample-btn {
    background-color: transparent; border: 1px solid var(--text-primary); color: var(--text-primary);
    padding: 0.5rem 1rem; font-family: var(--font-ui); font-weight: 600; cursor: pointer;
    border-radius: 0; margin-top: 1rem;
}
.sample-btn:hover { background-color: var(--text-primary); color: var(--bg-color); }

/* 2. Loading State */
#loading-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(255,255,255,0.98); display: none; flex-direction: column;
    justify-content: center; align-items: center; z-index: 20;
}
[data-theme="dark"] #loading-overlay { background-color: rgba(0, 0, 0, 0.98); }
.loader {
    width: 48px; height: 4px; background-color: var(--border-color); position: relative;
    margin-bottom: 2rem;
}
.loader::after {
    content: ''; position: absolute; left: 0; top: 0; height: 100%; width: 30%;
    background-color: var(--text-primary); animation: loadBar 1s ease-in-out infinite;
}
@keyframes loadBar { 0% { left: 0; } 100% { left: 70%; } }
.loading-text { font-weight: 600; font-family: var(--font-reader); margin-bottom: 0.5rem; }
.loading-percent { color: var(--text-secondary); font-variant-numeric: tabular-nums; font-family: var(--font-reader); }

/* 3. Reader State */
#reader-section { display: none; width: 100%; height: 100%; position: relative; }
.center-anchor {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 0; height: 0; overflow: visible;
}
.word-assembly {
    position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 4.5rem;
    line-height: 1.2; font-weight: 400; color: var(--text-primary);
    transform-origin: left center; will-change: transform;
    font-family: var(--font-reader);
}
.word-assembly.text-small { font-size: 3rem; }
.word-assembly.text-medium { font-size: 4.5rem; }
.word-assembly.text-large { font-size: 6rem; }
.char-span { display: inline; position: relative; letter-spacing: 0; color: var(--text-primary); }
.char-orp { color: var(--orp-color); font-weight: 700; z-index: 2; }

/* --- Controls Bar --- */
.controls-bar {
    background-color: var(--surface-color); border-top: 2px solid var(--text-primary);
    padding: 1.5rem 2rem; display: none; flex-direction: column; gap: 1.5rem;
    z-index: 10;
}
.progress-container { width: 100%; display: flex; align-items: center; gap: 1rem; }
.progress-track {
    flex: 1; height: 6px; background-color: var(--progress-bg); border-radius: 0px;
    overflow: hidden; cursor: pointer; position: relative;
}
.progress-fill { height: 100%; background-color: var(--progress-fill); width: 0%; transition: width 0.05s linear; }
.progress-text { font-size: 0.875rem; color: var(--text-secondary); min-width: 45px; text-align: right; font-family: var(--font-reader); }
.main-controls { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.playback-group { display: flex; align-items: center; gap: 1rem; }
.control-btn {
    background-color: transparent; border: 2px solid var(--text-primary);
    color: var(--text-primary); padding: 0.5rem 1rem; border-radius: 0px; cursor: pointer;
    font-family: var(--font-ui); font-size: 0.875rem; font-weight: 600;
    display: flex; align-items: center; gap: 0.5rem; transition: all 0.1s;
    min-width: 48px;
    justify-content: center;
}
.control-btn:hover { background-color: var(--text-primary); color: var(--bg-color); }
.control-btn.primary {
    background-color: var(--text-primary); color: var(--bg-color);
    min-width: 64px;
}
.control-btn.primary:hover { background-color: var(--accent-hover); opacity: 0.9; }
.settings-group { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.setting-item { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 120px; }
.setting-label {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em;
    color: var(--text-secondary); font-weight: 700;
    white-space: nowrap;
}

.action-buttons {
    display: flex; gap: 0.75rem; margin-left: auto;
}
input[type=range] { -webkit-appearance: none; width: 120px; background: transparent; }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; height: 18px; width: 18px; border-radius: 50%;
    background: var(--bg-color); border: 2px solid var(--text-primary); cursor: pointer; margin-top: -7px;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 4px; cursor: pointer; background: var(--text-secondary); border-radius: 0px;
}
select {
    background-color: transparent; border: 2px solid var(--text-primary); color: var(--text-primary);
    padding: 0.25rem 0.5rem; border-radius: 0px; font-family: var(--font-ui); font-size: 0.875rem; cursor: pointer;
    font-weight: 600;
}

/* --- Enhanced PDF Viewer / Map Modal --- */
#pdf-viewer-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-color); z-index: 50;
    display: none; flex-direction: column;
}
.viewer-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem; background-color: var(--surface-color);
    border-bottom: 2px solid var(--text-primary);
}
.viewer-content {
    flex: 1; overflow-y: auto; padding: 2rem;
    display: flex; flex-direction: column; align-items: center; gap: 2rem;
    scroll-behavior: smooth;
}
.pdf-page-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin-bottom: 2rem;
}
.page-label {
    text-align: center; color: var(--text-secondary); font-family: var(--font-reader); margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}
.pdf-canvas-container {
    position: relative;
    display: inline-block;
    border: 2px solid var(--border-color);
    box-shadow: none;
}
.pdf-canvas-container.active-page {
    border: 2px solid var(--orp-color);
    box-shadow: 0 0 0 4px rgba(139, 0, 0, 0.1);
}
.pdf-page-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* The Grid Overlay for precise clicking */
.click-zone-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    display: grid;
    grid-template-rows: repeat(10, 1fr);
}

/* The Current Position Marker */
.current-position-marker {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--orp-color);
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 0 8px rgba(139, 0, 0, 0.5);
}

@media (max-width: 600px) {
    #upload-section {
        padding: 1rem;
        max-width: 100%;
    }

    .upload-zone {
        padding: 2rem 1rem;
    }

    .sample-btn {
        width: 100%;
        margin: 0.5rem 0;
    }

    .controls-bar {
        padding: 1rem;
        gap: 1rem;
        max-height: 50vh;
        overflow-y: auto;
    }
    .progress-container { gap: 0.5rem; }
    .progress-text { min-width: 40px; font-size: 0.75rem; }

    .main-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .playback-group {
        justify-content: center;
        gap: 0.5rem;
    }

    .settings-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .setting-item {
        justify-content: space-between;
        gap: 0.5rem;
        flex: none;
        width: 100%;
    }

    .control-btn {
        padding: 0.5rem;
        min-width: 44px;
        justify-content: center;
        font-size: 0.75rem;
    }

    .action-buttons {
        width: 100%;
        justify-content: space-between;
    }

    .action-buttons .control-btn {
        flex: 1;
    }

    .setting-label { font-size: 0.65rem; }
    input[type=range] { width: 100%; max-width: 150px; }
    select { padding: 0.25rem; font-size: 0.75rem; flex: 1; }

    .brand span { display: none; }
    button.icon-btn { padding: 0.25rem 0.5rem; }
}
