@import url("https://fonts.googleapis.com/css2?family=Bungee&family=JetBrains+Mono:wght@400;700;800&family=Nunito:wght@400;700;800&display=swap");

/* Colores base del proyecto */
:root {
    --bg-1: #0b1220;
    --bg-2: #151f34;
    --ink: #ecf3ff;
    --ink-soft: #b7c4dd;
    --panel: #10192b;
    --border: #6ddcff;
    --accent-pink: #ff7db6;
    --accent-green: #5ff1cf;
    --accent-yellow: #ffd166;
    --accent-blue: #59a8ff;
}

/* Reset para empezar desde una base limpia */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Fondo general y tipografía principal */
body {
    font-family: "Nunito", "Segoe UI", sans-serif;
    color: var(--ink);
    min-height: 100vh;
    text-align: center;
    padding: 2.4rem 1rem 2rem;
    background:
    radial-gradient(circle at 14% 12%, rgba(89, 168, 255, 0.28), transparent 24%),
    radial-gradient(circle at 86% 16%, rgba(255, 125, 182, 0.22), transparent 26%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0 8px, rgba(255, 255, 255, 0) 8px 16px),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

/* Caja principal para centrar y limitar ancho en todos los dispositivos */
.app-shell {
    width: min(980px, 100%);
    margin: 0 auto;
    border: 2px solid rgba(109, 220, 255, 0.5);
    border-radius: 24px;
    background: rgba(16, 25, 43, 0.72);
    backdrop-filter: blur(2px);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
    padding: 1.4rem 1rem 1.6rem;
}

/* Fila superior con input y botón Add */
.top-controls {
    width: min(560px, 100%);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
}

/* Fila de botones Spin/Clear */
.action-controls {
    margin-top: 0.7rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.45rem;
}

/* Titulares */
h1,
h2,
h3 {
    font-family: "Bungee", "Trebuchet MS", sans-serif;
    letter-spacing: 0.02em;
}

h1 {
    font-size: clamp(2rem, 7vw, 3.3rem);
    margin-bottom: 1.2rem;
    text-shadow: 0 0 18px rgba(95, 241, 207, 0.34);
}

/* Input de añadir nombre */
input {
    border: 3px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    width: min(100%, 330px);
    font-size: 1rem;
    font-family: "JetBrains Mono", Consolas, monospace;
    background: rgba(12, 18, 33, 0.92);
    color: var(--ink);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
}

input:focus {
    outline: 3px solid rgba(87, 166, 255, 0.45);
    outline-offset: 2px;
}

/* Botones generales */
button {
    border: 3px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 1rem;
    margin-left: 0.35rem;
    margin-top: 0.65rem;
    background: linear-gradient(145deg, #10213c, #132947);
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
    transition: transform 0.16s ease, background 0.2s ease;
}

button:hover {
    background: linear-gradient(145deg, #18325a, #1b3d6f);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(1px);
}

/* Estado deshabilitado mientras la ruleta gira */
button:disabled,
input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(0.2);
}

/* Clase para etiquetas ocultas visualmente pero útiles para lectores de pantalla */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Contenedor de chips */
#options {
    margin-top: 1.2rem;
    min-height: 2rem;
    width: min(96%, 960px);
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.3rem;
}

/* Chip de nombre */
.option-tag {
    display: inline-flex;
    align-items: center;
    border: 2px solid var(--border);
    background: rgba(17, 38, 68, 0.94);
    color: #dcecff;
    padding: 0.42rem 0.7rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.24);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.option-text {
    margin-right: 0.45rem;
    user-select: none;
}

/* Botón x dentro de cada chip */
.option-remove {
    margin: 0;
    padding: 0;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(109, 220, 255, 0.65);
    border-radius: 50%;
    background: rgba(9, 18, 31, 0.92);
    color: var(--ink);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.option-remove:hover {
    transform: none;
    background: rgba(255, 209, 102, 0.9);
}

.option-tag:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.winner {
    background: var(--accent-green);
    color: #052228;
    transform: scale(1.08);
}

/* Caja de ruleta */
.wheel-container {
    position: relative;
    width: min(76vw, 340px);
    aspect-ratio: 1 / 1;
    margin: 2rem auto 0;
    isolation: isolate;
}

/* Disco de la ruleta */
#wheel {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 6px solid var(--border);
    background: radial-gradient(circle at 30% 30%, #1b335d, #0f1a2f 72%);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38), 0 0 24px rgba(109, 220, 255, 0.22);
    transition: transform 3s ease-out;
}

/* Flecha de resultado */
.pointer {
    position: absolute;
    z-index: 3;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 26px solid var(--accent-yellow);
    filter: drop-shadow(0 0 10px rgba(255, 209, 102, 0.45));
}

/* Capa de textos dentro de la ruleta */
#wheel-labels {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

/* Texto de cada sector */
.wheel-label {
    position: absolute;
    left: 50%;
    top: 50%;
    transform-origin: 0 0;
    font-size: 13px;
    color: #ffffff;
    font-weight: 800;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* Modo vertical para cuando hay muchas opciones */
.wheel-label.vertical {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    letter-spacing: -0.02em;
}

/* Texto de resultado */
#result {
    margin-top: 1.5rem;
    min-height: 2rem;
    font-size: clamp(1.3rem, 4vw, 2rem);
    color: #f3f8ff;
}

/* Título de historial */
h3 {
    margin-top: 1.4rem;
    font-size: 1.25rem;
}

/* Caja del historial */
#history {
    width: min(92%, 420px);
    margin: 0.7rem auto 0;
    list-style: none;
    text-align: left;
    background: rgba(9, 16, 28, 0.76);
    border: 2px solid rgba(109, 220, 255, 0.75);
    border-radius: 16px;
    padding: 0.7rem 0.9rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* Línea de cada registro en historial */
#history li {
    font-family: "JetBrains Mono", Consolas, monospace;
    color: var(--ink-soft);
    font-weight: 700;
    border-bottom: 1px dashed rgba(109, 220, 255, 0.24);
    padding: 0.45rem 0.1rem;
}

#history li:last-child {
    border-bottom: 0;
}

/* Ajustes para pantallas pequeñas */
@media (max-width: 900px) {
    h1 {
        font-size: clamp(1.8rem, 8vw, 2.8rem);
    }

    #history {
        width: min(94%, 500px);
    }
}

@media (max-width: 640px) {
    body {
        padding: 1.35rem 0.85rem 1.8rem;
    }

    .top-controls {
        flex-direction: column;
        gap: 0.35rem;
    }

    .action-controls {
        margin-top: 0.5rem;
    }

    input {
        width: min(100%, 360px);
    }

    button {
        margin-left: 0;
        margin-right: 0;
    }

    #options {
        width: min(100%, 540px);
    }

    .option-tag {
        font-size: 0.84rem;
        padding: 0.35rem 0.58rem;
    }

    .wheel-container {
        width: min(88vw, 330px);
        margin-top: 1.4rem;
    }

    #result {
        margin-top: 1.2rem;
    }
}

/* Ajuste para moviles muy estrechos */
@media (max-width: 390px) {
    h1 {
        font-size: clamp(1.55rem, 9.2vw, 2.2rem);
    }

    .option-tag {
        font-size: 0.78rem;
    }

    .wheel-container {
        width: min(92vw, 300px);
    }

    #result {
        font-size: clamp(1.05rem, 6vw, 1.4rem);
    }

    #history {
        width: min(96%, 370px);
    }
}

/* Ajuste para pantallas bajitas en horizontal */
@media (max-height: 520px) and (orientation: landscape) {
    body {
        padding-top: 0.9rem;
    }

    h1 {
        margin-bottom: 0.55rem;
    }

    #options {
        margin-top: 0.65rem;
    }

    .action-controls {
        margin-top: 0.45rem;
    }

    .wheel-container {
        width: min(52vh, 300px);
        margin-top: 1rem;
    }
}

/* Leyenda auxiliar para muchos nombres */
#wheelLegend {
    width: min(92%, 620px);
    margin: 1rem auto 0;
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.4rem 0.7rem;
    text-align: left;
    background: rgba(9, 16, 28, 0.78);
    border: 2px solid rgba(109, 220, 255, 0.75);
    border-radius: 16px;
    padding: 0.7rem 0.8rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#wheelLegend.is-visible {
    display: grid;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--ink);
    min-width: 0;
}

.legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.legend-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}