/* ======================================================= */
/* --- style.css (VERSIÓN REFACTORIZADA Y OPTIMIZADA) --- */
/* ======================================================= */

/* --- 1. FUENTES Y VARIABLES GLOBALES --- */
/* 
  Fuentes importadas con un propósito específico:
  - Quicksand: Legible y amigable, ideal para texto general y escolar.
  - Chakra Petch: Estilo digital/mecánico para botones y pantalla.
  - Titillium Web: Moderna y técnica para el título principal.
  - Outfit: Limpia y funcional para la navegación.
  - Roboto & Roboto Mono: Fuentes para el lector de números en el modal.
*/
@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;700&family=Quicksand:wght@400;700&family=Outfit:wght@400;700&family=Titillium+Web:wght@700&family=Roboto+Mono:wght@400;700&family=Roboto:wght@400;500;700&display=swap');

:root {
    /* Paleta de Colores */
    --bg-main: #121212;
    --bg-grid-lines: rgba(200, 200, 200, 0.04);
    --bg-display: #1a1a1a;
    --bg-keyboard: #000;
    --bg-output-screen: #111;
    --history-panel-bg: #1f1f1f;
    --history-header-bg: #2b2b2b;
    --nav-bg: #333;

    --color-display-text: #f0e68c;
    --history-text-color: #e0e0e0;
    --history-input-color: #b0b0b0;
    --history-border-color: #404040;
    --history-hover-bg: #333333;
    --color-lineas-output: #ddd;
    --color-error: #e84d4d; /* Rojo para mensajes de error */
    --focus-color: #66FF66;

    /* Colores de Botones */
    --btn-num-bg: #FFFF66;
    --btn-op-bg: #FF3333;
    --btn-special-bg: #6666FF;
    --btn-equal-bg: #66FF66;
    --btn-text-color: #000;
    --btn-disabled-bg: #333;
    --btn-disabled-text: #666;
    --history-clear-btn-bg: #e74c3c;
    --history-clear-btn-hover-bg: #c0392b;

    /* Dimensiones */
    --nav-height: 60px;

    /* Variables para el Lector de Números (dentro del modal) */
    --ln-color-fondo: #f8f9fa;
    --ln-color-texto-principal: #333;
    --ln-color-entero: #0d6efd;
    --ln-color-decimal: #198754;
    --ln-color-coma: #dc3545;
    --ln-color-placeholder: #6c757d;
}

/* --- 2. RESET Y ESTILOS BASE --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    padding: 20px;
    background-color: var(--bg-main);
    background-image: repeating-linear-gradient(90deg, var(--bg-grid-lines) 0 1px, transparent 1px 96px),
                      repeating-linear-gradient(0deg, var(--bg-grid-lines) 0 1px, transparent 1px 96px);
    font-family: 'Quicksand', sans-serif;
    color: #eee;
    overflow: hidden; /* Evita scroll en escritorio */
}

button {
    border: none;
    outline: none;
    font-family: inherit;
    cursor: pointer;
    line-height: 1.2;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

.error {
    color: var(--color-error);
}

/* --- 3. ESTRUCTURA Y LAYOUT PRINCIPAL --- */
.main-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 0;
}

/* --- 4. COMPONENTES PRINCIPALES --- */

/* --- Contenedor de la Calculadora --- */
.calculator-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    opacity: 0;
    transition: opacity 1s;
}

/* --- Título (Header) --- */
header[role="banner"] {
    margin-bottom: 25px;
    text-align: center;
    margin-top: 0;
}

header h1 {
    font-family: 'Titillium Web', sans-serif;
    font-size: clamp(1.2rem, 3.5vw, 2rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 1px;
    color: var(--color-error);
    text-transform: uppercase;
    text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
}

header h1 span {
    color: #4de89d;
}

header .subtitle {
    margin-top: 15px;
    font-size: clamp(0.6rem, 1.2vw, 0.75rem);
    color: var(--color-error);
    opacity: 0.8;
}

header .subtitle a {
    color: var(--btn-special-bg);
    font-weight: bold;
    text-decoration: underline;
    transition: color 0.2s ease;
}

header .subtitle a:hover {
    color: #4de89d;
}

/* --- Pantalla (Display) --- */
.display {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    min-height: 65px;
    margin-bottom: 15px;
    padding: 20px;
    background-color: var(--bg-display);
    color: var(--color-display-text);
    font-family: 'Chakra Petch', sans-serif;
    font-size: 2.2rem;
    text-align: right;
    border-radius: 10px;
    word-wrap: break-word;
    overflow: hidden;
}

/* --- Contenedor de Teclado y Salida --- */
.keyboard-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: var(--bg-keyboard);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* --- Teclado (Keyboard) --- */
.keyboard {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    width: 100%;
    height: 100%;
    transition: top 0.5s ease-in-out, opacity 0.3s ease-in-out;
}

.keyboard--hidden {
    top: 100%;
    opacity: 0;
    pointer-events: none;
}

.keyboard__button {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--btn-text-color);
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.4rem;
    border: 2px solid #000;
    overflow: hidden;
    transition: transform 0.1s ease, background-color 0.2s ease;
}

.keyboard__button--number { background-color: var(--btn-num-bg); }
.keyboard__button--operator { background-color: var(--btn-op-bg); }
.keyboard__button--special {
    background-color: var(--btn-special-bg);
    font-size: 0.8em;
}
.keyboard__button--equals { background-color: var(--btn-equal-bg); }
.keyboard__button--double-width { grid-column: span 2; }
.keyboard__button--triple-width { grid-column: span 3; }

.keyboard__button:not(:disabled):hover {
    background: linear-gradient(90deg, #ff0000, #ff8000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff);
    background-size: 200% 200%;
    animation: arcoiris 2s linear infinite;
    transform: scale(1.05);
}

.keyboard__button:disabled {
    background-color: var(--btn-disabled-bg) !important;
    color: var(--btn-disabled-text);
    cursor: not-allowed;
    animation: none !important;
    transform: none !important;
}

/* --- Pantalla de Salida (Output Screen) --- */
.output-screen {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: calc(100% - var(--nav-height));
    padding: 15px;
    background-color: var(--bg-output-screen);
    opacity: 0;
    pointer-events: none;
    overflow: auto;
    transition: opacity 0.3s ease-in-out;
}

.output-screen--visible {
    opacity: 1;
    pointer-events: all;
}

.output-screen__error-message {
    position: relative;
    width: 90%;
    margin: auto;
    color: var(--color-error);
    font-size: 1.2rem;
    text-align: center;
}

.output-grid__cell {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
}
.output-grid__line {
    position: absolute;
    background-color: var(--color-lineas-output);
}
.output-grid__cell--dividendo { color: #ff8c00; }
.output-grid__cell--divisor { color: #6495ed; }
.output-grid__cell--cociente { color: #00ff00; }
.output-grid__cell--producto { color: #ccc; }
.output-grid__cell--resto { color: #f08080; }
.output-grid__cell--suma-intermedia {
    color: #f0ad4e;
    font-weight: bold;
    z-index: 10;
    animation: fadeIn 0.3s ease-out;
}

/* --- Navegación Inferior (Bottom Nav) --- */
.bottom-nav {
    position: absolute;
    bottom: -100%;
    left: 0;
    z-index: 3;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: var(--nav-height);
    padding: 10px;
    background-color: var(--nav-bg);
    opacity: 0;
    pointer-events: none;
    transition: bottom 0.5s ease-in-out, opacity 0.3s ease-in-out;
}

.bottom-nav--visible {
    bottom: 0;
    opacity: 1;
    pointer-events: all;
}

.bottom-nav__button {
    flex-grow: 1;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    border-radius: 5px;
    transition: background-color 0.2s, color 0.2s;
}

.bottom-nav__button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.bottom-nav__button--arrow {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
}

/* --- 5. COMPONENTES FLOTANTES Y SUPERPUESTOS --- */

/* --- Panel de Historial --- */
.history-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1002;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 50px;
    height: 50px;
    background-color: var(--nav-bg);
    border: 1px solid #555;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, opacity 0.3s;
}

.history-toggle-btn:hover {
    background-color: #4CAF50;
    transform: scale(1.1);
}

.history-toggle-btn svg {
    width: 28px;
    height: 28px;
    fill: #eee;
}

.history-panel.history-panel--open + .history-toggle-btn {
    opacity: 0;
    pointer-events: none;
}

.history-panel {
    position: fixed;
    top: 0;
    right: -100%;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    width: 350px;
    max-width: 100vw;
    height: 100dvh;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background-color: var(--history-panel-bg);
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
    font-family: 'Quicksand', sans-serif;
    visibility: hidden;
    transition: right 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.history-panel--open {
    right: 0;
    visibility: visible;
}

.history-panel__header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-shrink: 0;
    padding: 15px 20px;
    background-color: var(--history-header-bg);
    border-bottom: 1px solid var(--history-border-color);
}

.history-panel__title {
    margin: 0;
    font-size: 1.3em;
    font-weight: bold;
    color: var(--history-text-color);
}

.history-panel__clear-btn {
    flex-shrink: 0;
    margin-left: 20px;
    padding: 8px 15px;
    background-color: var(--history-clear-btn-bg);
    color: #fff;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.history-panel__clear-btn:hover {
    background-color: var(--history-clear-btn-hover-bg);
    transform: scale(1.05);
}

.history-panel__list {
    flex-grow: 1;
    margin: 0;
    padding: 0 10px 10px;
    list-style: none;
    color: var(--history-text-color);
    overflow-y: auto;
}

.history-panel__item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 10px;
    border-bottom: 1px solid var(--history-border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-panel__item:last-child {
    border-bottom: none;
}

.history-panel__item:hover {
    background-color: var(--history-hover-bg);
}

.history-panel__item.history-item-highlight {
    animation: history-item-highlight 1.5s ease-out forwards;
}

.history-panel__input {
    font-size: 0.95em;
    line-height: 1.3;
    color: var(--history-input-color);
    word-break: break-all;
}

.history-panel__result {
    display: block;
    margin-top: 6px;
    font-size: 1.2em;
    font-weight: bold;
    color: var(--color-display-text);
    word-break: break-all;
}

/* --- Barra Lateral de Utilidades --- */
.sidebar-wrapper {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1050;
}
.bubble-main {
    width: 65px;
    height: 65px;
    transition: transform 0.3s ease-in-out;
}
.bubble-main[aria-expanded="true"] {
    transform: rotate(45deg);
}
.bubble-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    background-color: var(--nav-bg);
    color: #eee;
}
.bubble-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}
.bubble-sub {
    width: 45px;
    height: 45px;
}
.bubble-sub i {
    font-size: 1.2rem;
}

/* --- Modal y Lector de Números --- */
#infoModalLabel {
    color: #040101;
    text-align: center;
    width: 100%;
}

.modal-body .input-section { margin-bottom: 2rem; text-align: center; }
.modal-body .input-section label { display: block; margin-bottom: 0.5rem; font-weight: 500; font-size: 1.1rem; color: var(--ln-color-texto-principal); }
.modal-body .input-section input {
    font-family: 'Roboto Mono', monospace; padding: 0.75rem; border: 1px solid #ccc;
    border-radius: 8px; font-size: 1.5rem; width: 100%; max-width: 400px; text-align: center;
    color: var(--ln-color-texto-principal);
}
.modal-body .card {
    background: #ffffff; padding: 1.5rem; border-radius: 12px; border: 1px solid #e0e0e0;
    margin-bottom: 1.5rem; box-shadow: 0 4px 6px rgba(0,0,0,0.05); color: #000;
}
.modal-body .card h2 {
    margin-top: 0; margin-bottom: 1rem; font-size: 1.25rem;
    color: var(--ln-color-texto-principal); border-bottom: 1px solid #eee; padding-bottom: 0.75rem;
}
.modal-body .result-box {
    padding: 1rem; border-radius: 8px; min-height: 50px; display: flex; align-items: center;
    justify-content: center; background-color: var(--ln-color-fondo); font-size: 1.2rem;
    font-family: 'Roboto', sans-serif; transition: background-color 0.3s;
}
.modal-body .placeholder-text { color: var(--ln-color-placeholder); font-style: italic; }
.modal-body .phonetic-box {
    font-family: 'Roboto Mono', monospace; font-weight: 700; letter-spacing: 1px;
    word-spacing: 10px; display: flex; flex-wrap: wrap;
}
.modal-body .phonetic-box .palabra-fonetica {
    padding: 2px 5px; transition: background-color 0.2s, color 0.2s; border-radius: 4px;
}
.modal-body .svg-box { padding: 0; background-color: transparent; overflow-x: auto; }
.modal-body .svg-box svg { display: block; width: 100%; max-height: 250px; }
.modal-body .svg-etiqueta-principal {
    font-family: 'Roboto', sans-serif; font-size: 18px; font-weight: 700;
    text-transform: uppercase; fill: #555;
}
.modal-body .svg-etiqueta-vertical {
    font-family: 'Roboto', sans-serif; font-size: 14px;
    text-transform: uppercase; fill: var(--ln-color-decimal);
}
.modal-body .svg-numero { font-family: 'Roboto Mono', monospace; font-size: 5rem; font-weight: 700; }
.modal-body .highlight {
    background-color: var(--ln-color-entero) !important; color: white !important;
    fill: white !important; transition: background-color 0.1s, color 0.1s;
}
.modal-body .play-btn {
    margin-top: 1rem; padding: 0.5rem 1rem; font-size: 1rem; border-radius: 20px;
    border: 1px solid #ccc; background: #fff; cursor: pointer; color: #333;
    transition: background-color 0.2s, transform 0.2s;
}
.modal-body .play-btn:hover { background-color: #f0f0f0; transform: translateY(-2px); }

/* --- 6. FOOTER --- */
.main-footer {
    margin-top: 30px;
    padding-bottom: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
}

.main-footer a {
    color: var(--btn-special-bg);
    text-decoration: none;
    transition: color 0.2s ease;
}

.main-footer a:hover {
    color: #4de89d;
    text-decoration: underline;
}

/* --- 7. ANIMACIONES GLOBALES --- */
@keyframes fadeInScale-animation {
    to { opacity: 1; transform: scale(1); }
}
.animate-fade-in-scale {
    opacity: 0;
    transform: scale(0.5);
    animation: fadeInScale-animation 0.5s forwards cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes arcoiris {
    0% { background-position: 0% 50% }
    50% { background-position: 100% 50% }
    100% { background-position: 0% 50% }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
}
.pulse {
    animation: pulse 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes history-item-highlight {
    0% { background-color: transparent; transform: scale(1); }
    50% { background-color: rgba(76, 175, 80, 0.4); transform: scale(1.02); }
    100% { background-color: transparent; transform: scale(1); }
}

/* ======================================================= */
/* --- 8. MEDIA QUERIES PARA VISTAS MÓVILES --- */
/* ======================================================= */

@media (max-width: 600px) {

    /* --- Variables específicas para móvil --- */
    :root {
        --floating-btn-size-mobile: 60px;
        --floating-btn-margin-mobile: 10px;
    }

    /* --- Reset y base para móvil --- */
    html { box-sizing: border-box; }
    *, *:before, *:after { box-sizing: inherit; }

    body {
        margin: 0;
        padding: env(safe-area-inset-top, 10px) env(safe-area-inset-right, 10px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 10px);
        overflow-y: auto;
        overflow-x: hidden;
    }

    .main-content-wrapper { padding-top: 0; }

    /* --- Layout de la calculadora en móvil --- */
    .calculator-container {
        width: 100% !important;
        max-width: none !important;
        margin-bottom: 0;
        flex-grow: 1;
    }
    .keyboard-container {
        width: 100% !important;
        height: auto !important;
        flex-grow: 1;
    }
    .keyboard { height: 100%; }

    /* --- Componentes en móvil --- */
    .display {
        font-size: 10vw !important;
        padding: 15px;
        flex-shrink: 0;
    }
    .output-screen { font-size: 5vw !important; }
    .keyboard__button { font-size: 6vw; }
    .bottom-nav__button--arrow { font-size: 7vw !important; }
    #botexp, #botnor { font-size: 3.5vw !important; padding: 8px; }

    /* --- Encabezado en móvil --- */
    header { flex-shrink: 0; }
    header h1 { font-size: 12vw !important; letter-spacing: 1px !important; }
    header .subtitle { font-size: 3.5vw !important; }
    .output-screen__error-message { font-size: 4.5vw !important; padding-top: 25%; }

    /* --- Componentes flotantes y Header del Historial en móvil --- */
    .history-toggle-btn,
    .sidebar-wrapper {
        top: calc(env(safe-area-inset-top, 10px) + var(--floating-btn-margin-mobile));
    }

    .history-toggle-btn { right: var(--floating-btn-margin-mobile); }
    .sidebar-wrapper { left: var(--floating-btn-margin-mobile); }

    .history-toggle-btn,
    .sidebar-wrapper .bubble-main {
        width: var(--floating-btn-size-mobile);
        height: var(--floating-btn-size-mobile);
    }
    .history-toggle-btn svg {
        width: 50%; /* Proporcional al botón */
        height: 50%;
    }
    .bubble-btn {
        width: 52px;
        height: 52px;
    }
    .bubble-sub {
        width: 45px;
        height: 45px;
    }

    .history-panel__header {
        padding-left: calc(var(--floating-btn-size-mobile) + var(--floating-btn-margin-mobile) + 10px);
        padding-right: calc(var(--floating-btn-size-mobile) + var(--floating-btn-margin-mobile) + 10px);
        justify-content: flex-start;
    }

    /* --- Ocultar Footer en móvil --- */
    .main-footer {
        display: none;
    }

      /* --- Calculadora ancha --- */

#contenedor {
  padding-left: 0 !important;
}

#display {
  margin-left: 0 !important;
}



}


    /* --- Centrar contenedor y display --- */

#contenedor {
  padding-left: 1em; /* relativo al tamaño de fuente */
}

#display {
  margin-left: 0; /* que siga el flujo sin desplazarse */
}
