:root {
    --bg-color: #000000;
    --text-silver: #c0c0c0;
    --text-red: #ff0000;
    --ui-bg: #1a1a1a;
    --ui-border: #333;
    --accent: #444;
    --active-btn: #333;
    
    /* Dynamic Settings */
    --reader-font: 'Courier New', Courier, monospace;
    --reader-size: 4rem; 
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-silver);
    font-family: var(--reader-font);
    margin: 0;
    overflow: hidden;
    height: 100vh; /* Fallback */
    height: 100dvh; /* Dynamic viewport height for mobile */
    width: 100vw;
}

/* --- UTILS --- */
.hidden { display: none !important; }
.btn-icon { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-silver); padding: 5px; transition: color 0.2s; }
.btn-icon:hover { color: #fff; }

/* --- PAGE 0: INTRO --- */
#page-intro {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #000; 
    position: relative;
    overflow: hidden; /* Prevent scrolling on page-intro */
}

.intro-footer-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 10px;
    z-index: 10;
    width: 100%;
}

.skip-btn-container {
    /* Removed absolute positioning */
    display: none; /* Hide container if still present in HTML logic, rely on footer actions */
}

.btn-skip {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: underline;
    transition: color 0.2s;
    padding: 10px;
}
.btn-skip:hover { color: #fff; }

/* Tooltip Styles */
.tutorial-tooltip {
    position: absolute;
    background: var(--text-red);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: sans-serif;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s ease;
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.4);
}

.tutorial-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
}

/* Tooltip Arrow: Pointing Down (Tooltip is Above) */
.tutorial-tooltip[class*="tip-above"]::after {
    top: 100%;
    border-top-color: var(--text-red);
}

/* Tooltip Arrow: Pointing Up (Tooltip is Below) */
.tutorial-tooltip[class*="tip-below"]::after {
    bottom: 100%;
    border-bottom-color: var(--text-red);
}

.tutorial-tooltip.active {
    opacity: 1;
    transform: translateY(0);
}

.pulse-btn {
    animation: pulse 2s infinite;
}

/* Highlight for the button user needs to click */
.highlight-target {
    border-color: var(--text-red) !important;
    color: #fff !important;
    box-shadow: 0 0 15px var(--text-red);
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(255, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

/* --- SCROLLABLE LAYOUT --- */
.scroll-container {
    height: 100%;
    width: 100%;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- PAGE 1: HOME --- */
#page-home { width: 100%; height: 100%; }

.home-header {
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 20px;
}

.home-header h1 { margin: 0; font-weight: normal; letter-spacing: 2px; }
.logo-red { color: var(--text-red); font-weight: bold; }

.header-actions {
    position: absolute;
    right: 0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.gear-icon, .help-icon {
    font-size: 1.5rem;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
}
.gear-icon:hover, .help-icon:hover { color: #fff; }
.gear-icon:hover { transform: rotate(90deg); transition: transform 0.3s; }

.home-content {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 40px;
}

.section-title {
    font-size: 1.1rem;
    color: #fff;
    border-bottom: 1px solid var(--text-red);
    padding-bottom: 5px;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.card {
    background-color: var(--ui-bg);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.subsection-label {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: -5px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

select {
    width: 100%;
    padding: 12px;
    background: #222;
    color: #fff;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 1rem;
    box-sizing: border-box;
    font-family: inherit;
}

/* Options Grid */
.options-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: #111;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid #333;
}

.option-btn {
    background: transparent;
    border: none;
    color: #888;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.option-btn:hover { color: #fff; }

.option-btn.selected {
    background: var(--text-red);
    color: white;
    font-weight: bold;
}

.summary-box {
    background: #111;
    border: 1px solid #333;
    padding: 12px;
    border-radius: 6px;
    color: #ccc;
    font-size: 0.9rem;
    line-height: 1.4;
    min-height: 60px;
}

button.primary-btn {
    background: var(--text-red);
    color: white;
    border: none;
    padding: 15px;
    font-size: 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s;
    margin-top: 10px;
}
button.primary-btn:active { transform: scale(0.98); }
button.primary-btn:disabled { background: #333; color: #666; cursor: not-allowed; animation: none; }

/* --- PAGE 2: READER (IMMERSIVE) --- */
#page-reader {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
}

.reader-top-bar {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 10;
}

.reader-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0; /* Allows shrinking in flex container */
}

.word-display {
    display: flex;
    width: 100%;
    font-size: var(--reader-size); 
    font-weight: bold;
    line-height: 1;
    user-select: none;
    transition: font-size 0.2s;
}

.segment { white-space: pre; font-family: var(--reader-font); }
.segment.left { flex: 1; text-align: right; color: var(--text-silver); }
.segment.pivot { color: var(--text-red); width: 0.8ch; text-align: center; display: inline-block; }
.segment.right { flex: 1; text-align: left; color: var(--text-silver); }

.guide-notch-top, .guide-notch-bottom {
    position: absolute; left: 50%; width: 2px; height: 15px; background-color: #333; transform: translateX(-50%);
}
.guide-notch-top { top: 20%; }
.guide-notch-bottom { bottom: 20%; }

.reader-footer {
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: linear-gradient(to top, rgba(0,0,0,1) 30%, rgba(0,0,0,0));
    position: relative;
    flex-shrink: 0; /* Prevents footer from being crushed */
}

.progress-text { color: #666; font-size: 0.85rem; letter-spacing: 1px; margin-bottom: 5px; }

.control-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
    background: rgba(26, 26, 26, 0.8);
    padding: 10px 30px;
    border-radius: 50px;
    border: 1px solid #333;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    position: relative;
}

.btn-circle {
    width: 45px; height: 45px; border-radius: 50%; border: 1px solid #444;
    background: transparent; color: var(--text-silver); font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s ease;
}
.btn-circle:hover { background: #333; color: white; transform: scale(1.05); }
.btn-circle.play { width: 55px; height: 55px; border-color: var(--text-red); color: white; font-size: 1.4rem; }
.btn-circle.play:hover { background: rgba(255, 0, 0, 0.1); box-shadow: 0 0 15px rgba(255, 0, 0, 0.2); }
.speed-text { color: var(--text-red); font-size: 0.9rem; font-weight: bold; margin-top: 5px; }

/* --- PAGE 3: SETTINGS --- */
#page-settings {
    background: #000;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.settings-header h2 { margin: 0; color: #fff; }

.settings-content {
    flex: 1;
    overflow-y: auto;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.setting-group {
    background: var(--ui-bg);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
}
.setting-label { display: block; color: #aaa; margin-bottom: 10px; font-weight: bold; }

.preview-box {
    background: #000;
    border: 1px solid #444;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 10px;
    border-radius: 4px;
    overflow: hidden;
}
.preview-box .word-display { font-size: 2rem; } 

.sound-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid #222;
    padding-bottom: 5px;
}
.sound-row select { width: 150px; padding: 5px; font-size: 0.9rem; }
.sound-label { color: #ccc; font-size: 0.9rem; }

.settings-footer {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid #333;
    padding-top: 20px;
    max-width: 600px;
    margin-left: auto; margin-right: auto; width: 100%;
}

.btn-secondary { background: #333; color: #ccc; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; }
.btn-secondary:hover { background: #444; color: #fff; }
.btn-save { background: var(--text-red); color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-save:hover { background: #d00000; }

input[type=range] { width: 100%; cursor: pointer; accent-color: var(--text-red); }

/* --- MOBILE ADJUSTMENTS --- */
@media (max-width: 600px) {
    /* Only specific overrides if needed, generic responsive already handles skip button */
    
}

@media (max-height: 800px) {
    :root {
        --reader-size: 2.5rem; /* Smaller text on mobile */
    }

    .reader-top-bar {
        padding: 10px 15px;
    }

    .reader-footer {
        padding: 10px 15px 15px 15px;
        gap: 5px; /* Tighter gap */
    }

    .intro-footer-actions {
        margin-top: 5px;
        gap: 5px;
    }

    button.primary-btn {
        padding: 10px 20px;
        font-size: 1rem;
        margin-top: 2px;
    }

    .control-panel {
        padding: 6px 20px;
        gap: 15px;
    }

    .btn-circle {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

    .btn-circle.play {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
    }

    #tip-sound {
        top: 55px;
        right: 15px;
    }
}
