:root {
    --bg-color: #f0f4f8;
    --container-bg: white;
    --text-color: #333;
    --accent-color: #2575fc;
    --secondary-bg: #f9f9f9;
    --border-color: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --button-bg: linear-gradient(to right, #6a11cb, #2575fc);
    --add-bg: #28a745;
    --clear-bg: #ffc107;
    --reset-bg: #ff4757;
    --tag-bg: #e2eafc;
    --winner-color: #2575fc;
    --prob-color: #555;
}

body.dark {
    --bg-color: #121212;
    --container-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --accent-color: #4d9aff;
    --secondary-bg: #2c2c2c;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --button-bg: linear-gradient(to right, #4a0d9e, #1a5bb8);
    --add-bg: #1f7a38;
    --clear-bg: #d39e00;
    --reset-bg: #e74c3c;
    --tag-bg: #3a3f5e;
    --winner-color: #4d9aff;
    --prob-color: #bbb;
}

body {
    font-family: 'Roboto', sans-serif;
    background: linear-gradient(to bottom, var(--bg-color), #d9e2ec);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    max-width: 1000px;
    background: var(--container-bg);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--shadow-color);
    display: flex;
    flex-direction: column;
    width: 100%;
}

#mainContent {
    flex: 1;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 5px;
    color: var(--text-color);
}

header p {
    font-size: 1.1em;
    color: #777;
    margin-bottom: 20px;
}

#darkModeToggle {
    background: var(--clear-bg);
    color: var(--text-color);
    padding: 8px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    margin-bottom: 15px;
}

#darkModeToggle:hover {
    background: #e0a800;
}

.input-section label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    color: var(--text-color);
}
.input-section small {
    color: var(--prob-color);
    margin-top: 5px;
    display: block;
}

.name-input-wrapper {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

#nameInput, #weightInput, #itemInput {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1em;
    background: var(--container-bg);
    color: var(--text-color);
    min-width: 150px;
}

#weightInput {
    flex: 0.3;
    min-width: 80px;
}

#weightType {
    flex: 0.3;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1em;
    background: var(--container-bg);
    color: var(--text-color);
    min-width: 120px;
}

/* Nuevo estilo para el label y input de numWinners */
.winners-input-wrapper {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
    padding: 10px;
    background: var(--secondary-bg);
    border-radius: 10px;
    box-shadow: 0 2px 5px var(--shadow-color);
}

.winners-input-wrapper label {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--accent-color);
    margin: 0;
}

#numWinners {
    flex: 0.2;
    padding: 12px;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    font-size: 1.1em;
    background: var(--container-bg);
    color: var(--text-color);
    min-width: 80px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#numWinners:focus {
    border-color: var(--winner-color);
    box-shadow: 0 0 5px var(--winner-color);
}

#numWinners:disabled {
    background: var(--secondary-bg);
    opacity: 0.7;
    cursor: not-allowed;
}

#addButton, #addItemButton {
    padding: 12px 20px;
    background: var(--add-bg);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
    min-width: 100px;
}

#addButton:hover, #addItemButton:hover {
    background: #218838;
}

.names-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    min-height: 40px;
    padding: 10px;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: var(--secondary-bg);
    justify-content: center;
}

.name-tag {
    display: flex;
    align-items: center;
    background: var(--tag-bg);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    animation: fadeIn 0.3s ease-in;
}

.name-tag span {
    margin-right: 8px;
}

.name-tag input {
    width: 50px;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--container-bg);
    color: var(--text-color);
    margin-left: 5px;
}

.name-tag .remove {
    cursor: pointer;
    color: var(--reset-bg);
    font-weight: bold;
    margin-left: 10px;
}

.name-tag .remove:hover {
    color: #e74c3c;
}

#clearButton, #clearItemsButton {
    background: var(--clear-bg);
    color: var(--text-color);
    padding: 8px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    margin-bottom: 15px;
}

#clearButton:hover, #clearItemsButton:hover {
    background: #e0a800;
}

button#startButton {
    padding: 12px 25px;
    background: var(--button-bg);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    margin: 20px 0;
    display: block;
    width: 100%;
}

button#startButton:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-color);
}

.content-row {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    margin: 20px 0;
}

.hat-section {
    flex: 1;
    margin: 0;
    display: flex;
    justify-content: center;
}

#hatContainer {
    position: relative;
    width: 400px;
    height: 400px;
    margin: 0 auto;
}

#hat {
    transition: transform 0.3s ease-in-out;
}

.shake {
    animation: shake 1s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.result-section {
    flex: 1;
    display: none;
    margin-top: 0;
    padding: 20px;
    background: var(--secondary-bg);
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow-color);
    max-width: 400px;
}

.result-section h2 {
    margin-bottom: 10px;
    color: var(--text-color);
}

#winnersList {
    list-style: none;
    padding: 0;
    margin: 0 0 10px 0;
}

#winnersList li {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--winner-color);
    margin-bottom: 5px;
}

#probability {
    font-size: 1.2em;
    color: var(--prob-color);
    margin-top: 10px;
}

#resetButton {
    background: var(--reset-bg);
    margin-top: 15px;
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ffd700;
    border-radius: 50%;
    opacity: 0;
    animation: flyOut 1.5s ease-out forwards;
}

@keyframes flyOut {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-150px) scale(0.5); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.analytics-section {
    margin-top: 40px;
    padding: 20px;
    background: var(--secondary-bg);
    border-radius: 10px;
    box-shadow: 0 5px 15px var(--shadow-color);
    font-size: 0.9em;
    color: var(--prob-color);
}

.analytics-section h3 {
    margin-bottom: 10px;
    color: var(--text-color);
}

.analytics-section h4 {
    margin-top: 15px;
    margin-bottom: 5px;
}

#historyList {
    list-style: none;
    padding: 0;
    text-align: left;
}

#historyList li {
    margin-bottom: 5px;
    font-size: 0.85em;
}

/* Responsive - Ajustes para PC: Resultados a la derecha, analíticas a la derecha */
@media (min-width: 1024px) {
    .container {
        flex-direction: row;
        gap: 30px;
        align-items: flex-start;
    }
    #mainContent {
        flex: 3; /* Mayor espacio para contenido principal */
    }
    .content-row {
        flex: 2; /* Ajusta para equilibrar sombrero y resultados */
    }
    .hat-section {
        flex: 1;
        justify-content: flex-start;
    }
    .result-section {
        flex: 1;
        max-width: 400px;
    }
    .analytics-section {
        flex: 1;
        margin-top: 0;
        position: sticky;
        top: 20px;
    }
}

@media (max-width: 600px) {
    .container { padding: 20px; max-width: 100%; }
    #hatContainer { width: 300px; height: 300px; }
    svg { width: 300px; height: 350px; }
    header h1 { font-size: 2em; }
    button { font-size: 1em; padding: 10px 20px; }
    .content-row {
        flex-direction: column;
    }
    .result-section {
        margin-top: 30px;
    }
}

@media (min-width: 601px) {
    .container { max-width: 1000px; padding: 40px; }
    header h1 { font-size: 3em; }
    header p { font-size: 1.3em; }
    #nameInput, #weightInput { font-size: 1.2em; padding: 15px; }
    button { font-size: 1.3em; padding: 15px 30px; }
    #hatContainer { width: 400px; height: 400px; }
    svg { width: 400px; height: 400px; }
    .result-section h2 { font-size: 2em; }
    #winnersList li { font-size: 1.8em; }
    .particle { width: 10px; height: 10px; }
    .name-input-wrapper { justify-content: space-between; }
    .names-list { justify-content: flex-start; }
}

body.dark #hatGradient stop {
    stop-color: #0a0a0a;
}

body.dark .particle {
    background: #ffeb3b;
}