/* Variables i configuració global */
:root {
    /* Colors principals */
    --bg-color: #ffffff;
    --text-color: #000000;
    --accent-color: #ff0000;
    --ui-gray: #dddddd;
    --progress-fill: #555555;
    --hover-color: #f0f0f0;

    --transition-duration: 0.3s;
}

/* Mode fosc */
.dark-mode {
    --bg-color: #121212;
    --text-color: #ffffff;
    --ui-gray: #636363;
    --progress-fill: #aaaaaa;
}

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

/* Estils base */
body {
    height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-duration), color var(--transition-duration);
}

/* Títol */
#project-title {
    position: fixed;
    top: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: var(--progress-fill);
    font-size: 1.5rem;
    font-weight: 500;
    margin: 0;
    z-index: 50;
    pointer-events: none; /* Per evitar que interfereixi amb els controls */
}


/* Controls superiors */
.top-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 100;
}

.icon-btn {
    background: var(--ui-gray);
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.icon-btn:hover {
    opacity: 1;
}

/* Control de mida de font */
.font-slider-container {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 90;
}

#font-size-slider {
    -webkit-appearance: slider-vertical;
    width: 8px;
    height: 200px;
    cursor: pointer;
}

/* Contenidor principal i guia */
#main-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
}

/* Guía visual (línea vertical) */
#focus-guide {
    position: absolute;
    top: 50%;
    left: 33.33%; /* un tercio de la pantalla */
    transform: translate(-50%, -50%);
    width: 5px;
    height: 100%;
    background-color: var(--accent-color);
    opacity: 0.2;
    pointer-events: none;
    z-index: 0; /* Col·loquem la guia per sota del text */
}

#word-display {
    font-size: 10rem; /* Ajustable por JS */
    font-weight: 700;
    letter-spacing: -1px;
    white-space: nowrap;
    user-select: none;
    position: relative;
    background-color: var(--bg-color); /* Mateix color que el fons */
    padding: 0.2em 0.5em; /* Afegim padding per evitar que la guia es vegi pels costats */
    z-index: 1; /* Col·loquem el text per sobre de la guia */
    transition: background-color var(--transition-duration), color var(--transition-duration);

}

.highlight {
    color: var(--accent-color);
}

/* Popup i overlay */
#popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 750;
}

#input-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-color);
    border: 1px solid var(--ui-gray);
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    display: block;
}

#input-popup.visible {
    display: block;
    animation: fadeIn 0.3s ease-out forwards;
}

#input-popup.hiding {
    animation: fadeOut 0.3s ease-out forwards;
}


@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -48%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -48%);
    }
}

.sample-text-selector {
    margin-bottom: 1rem;
}

.sample-text-selector label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

#sample-text-select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--ui-gray);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

#sample-text-select:hover {
    border-color: var(--accent-color);
}

#sample-text-select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.dark-mode #sample-text-select {
    background-color: var(--bg-color);
    color: var(--text-color);
}

.config-row {
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.config-row label {
    flex: 1;
    font-weight: 600;
}

.config-row input {
    flex: 1;
    max-width: 100px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--ui-gray);
    font-size: 1rem;
    text-align: center;
}

#input-popup h3 {
    margin-bottom: 15px;
}

#input-text {
    width: 100%;
    height: 150px;
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--ui-gray);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
    resize: vertical;
}

.word-count-info {
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.9rem;
    text-align: right;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--ui-gray);
}

/* Controls inferiors i comptadors */
#controls-overlay {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    z-index: 500;
}

#word-counter, #wpm-counter {
    color: var(--progress-fill);
    font-size: 0.9rem;
    font-weight: 600;
    margin-right: 15px;
    min-width: 70px;
    text-align: right;
    font-family: 'Segoe UI', monospace;
}

/* Barra de progrés */
#progress-bar-container {
    height: 6px;
    background-color: var(--ui-gray);
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
}

#progress-bar {
    height: 100%;
    width: 0;
    background-color: var(--progress-fill);
    transition: width 0.1s linear;
}

/* Selector d'idioma */
#language-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

#language-popup .popup-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-color);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lang-option {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    color: var(--text-color);
    cursor: pointer;
    border-radius: 4px;
    width: 100%;
    text-align: left;
}

.lang-option:hover {
    background-color: var(--hover-color);
}

/* Responsivitat */
@media (max-width: 768px) {
    #project-title {
        font-size: 1.2rem;
    }

    #word-display {
        font-size: 6rem;
    }

    #input-popup {
        width: 90%;
        padding: 1rem;
    }

    .config-row {
        flex-direction: column;
        align-items: stretch;
    }
}