@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@700&family=Cinzel:wght@600;700&display=swap');

:root {
    --bg-color: #0d0a1d;
    --panel-color: #171130;
    --text-color: #f1ecdd;
    --accent-color: #f2c14e;      /* oro alquímico */
    --oro-claro: #ffe9b0;
    --pergamino: #cfc4a6;
    --acento-cielo: #6fc3e8;
    --btn-hint: #fca311;
    --btn-danger: #ff4757;
    --slot-bg: #1d1738;
    --borde: #35295c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(ellipse 120% 70% at 50% -10%, #241b47 0%, transparent 60%),
        radial-gradient(ellipse 80% 50% at 85% 100%, #1b1038 0%, transparent 55%);
    background-attachment: fixed;
    color: var(--text-color);
    padding: 20px;
    display: flex;
    justify-content: center;
    transition: background-color 0.3s ease;
    min-height: 100vh;
    position: relative;
}

/* Cielo estrellado animado */
body::before, body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(1px 1px at 12% 22%, rgba(255,255,255,0.8), transparent 2px),
        radial-gradient(1px 1px at 68% 12%, rgba(255,233,176,0.7), transparent 2px),
        radial-gradient(1.5px 1.5px at 85% 42%, rgba(255,255,255,0.6), transparent 2px),
        radial-gradient(1px 1px at 35% 68%, rgba(255,255,255,0.5), transparent 2px),
        radial-gradient(1px 1px at 55% 88%, rgba(255,233,176,0.6), transparent 2px),
        radial-gradient(1.5px 1.5px at 22% 92%, rgba(255,255,255,0.5), transparent 2px);
    background-size: 480px 480px;
    animation: titilar 5s ease-in-out infinite alternate;
}

body::after {
    background-size: 340px 340px;
    background-position: 160px 90px;
    animation-duration: 7s;
    animation-delay: 2s;
}

@keyframes titilar {
    from { opacity: 0.35; }
    to   { opacity: 0.9; }
}

.game-container {
    width: 100%;
    max-width: 800px;
    background: linear-gradient(180deg, #1b1438 0%, var(--panel-color) 35%, #130e28 100%);
    border: 1px solid rgba(242, 193, 78, 0.3);
    border-radius: 16px;
    padding: 25px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.6),
        0 0 60px rgba(242, 193, 78, 0.06) inset;
    position: relative;
    z-index: 1;
}

.game-header {
    text-align: center;
    margin-bottom: 25px;
}

.game-header h1 {
    font-family: 'Cinzel Decorative', 'Cinzel', serif;
    font-size: 2.3rem;
    margin-bottom: 10px;
    background: linear-gradient(180deg, var(--oro-claro) 20%, var(--accent-color) 60%, #c08f2c 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 30px rgba(242, 193, 78, 0.25);
    letter-spacing: 2px;
}

.game-header h1 .h1-emoji {
    color: var(--text-color);
    -webkit-text-fill-color: initial;
    text-shadow: none;
}

.stats {
    font-size: 1.05rem;
    margin-bottom: 10px;
    color: var(--pergamino);
    font-family: 'Cinzel', serif;
    letter-spacing: 1px;
}

progress {
    width: 100%;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--borde);
}

progress::-webkit-progress-bar {
    background-color: #1b1536;
}

progress::-webkit-progress-value {
    background: linear-gradient(90deg, #a87820, var(--accent-color), var(--oro-claro));
}

/* === ALTAR DE FORJA === */
.forge-zone {
    background:
        radial-gradient(ellipse 90% 120% at 50% -30%, rgba(242, 193, 78, 0.07), transparent 60%),
        linear-gradient(180deg, #201845, #170f33);
    border: 1px solid rgba(242, 193, 78, 0.22);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    position: relative;
}

.forge-zone::before,
.forge-zone::after {
    content: '✦';
    position: absolute;
    top: 8px;
    color: rgba(242, 193, 78, 0.45);
    font-size: 0.9rem;
}

.forge-zone::before { left: 14px; }
.forge-zone::after { right: 14px; }

.slots-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.slot {
    width: 110px;
    height: 110px;
    background: radial-gradient(circle at 50% 35%, #272050, var(--slot-bg) 70%);
    border: 2px dashed rgba(242, 193, 78, 0.55);
    border-radius: 14px;
    box-shadow: inset 0 4px 14px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.9rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    color: rgba(242, 193, 78, 0.6);
}

.slot span {
    font-size: 0.82rem;
    margin-top: 5px;
    color: var(--pergamino);
}

.slot:hover {
    background: radial-gradient(circle at 50% 35%, #2e2660, #221a48 70%);
    transform: scale(1.05);
    border-color: var(--accent-color);
}

.forge-operator {
    font-size: 2rem;
    font-family: 'Cinzel', serif;
    color: var(--accent-color);
    text-shadow: 0 0 12px rgba(242, 193, 78, 0.5);
}

.message-board {
    min-height: 24px;
    margin-bottom: 20px;
    font-weight: 500;
    font-size: 1.02rem;
    font-style: italic;
}

.control-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 20px;
    border: 1px solid rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.5px;
    transition: transform 0.1s, filter 0.2s, opacity 0.2s;
}

.btn:active { transform: scale(0.95); }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(180deg, var(--oro-claro), var(--accent-color) 55%, #d9a334);
    color: #2a1d05;
    box-shadow: 0 0 16px rgba(242, 193, 78, 0.35);
}

.btn-hint {
    background: linear-gradient(180deg, #ffc966, var(--btn-hint));
    color: #2a1d05;
}

.btn-info {
    background: linear-gradient(180deg, #a5e2ff, var(--acento-cielo));
    color: #06283a;
}

.btn-danger {
    background: linear-gradient(180deg, #ff7a85, var(--btn-danger));
    color: #fff;
}

.btn-sound {
    background: var(--slot-bg);
    color: #fff;
    border: 1px solid var(--borde);
    padding: 10px 14px;
}

.btn:hover { filter: brightness(1.08); }

.search-box {
    margin-bottom: 20px;
}

.search-box input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--borde);
    background: #120d26;
    color: #fff;
    font-size: 1rem;
}

.search-box input:focus {
    outline: none;
    border-color: rgba(242, 193, 78, 0.55);
}

.inventory-zone {
    max-height: 420px;
    overflow-y: auto;
    padding-right: 5px;
}

.category-block {
    margin-bottom: 20px;
    background: linear-gradient(180deg, #1b1438, #160f2e);
    border: 1px solid rgba(242, 193, 78, 0.12);
    padding: 15px;
    border-radius: 10px;
}

.category-title {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    letter-spacing: 1px;
    color: var(--accent-color);
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(242, 193, 78, 0.22);
    padding-bottom: 6px;
}

/* === FICHAS DE ELEMENTOS === */
.category-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
    gap: 8px;
}

.element {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 74px;
    padding: 8px 4px;
    text-align: center;
    background: linear-gradient(180deg, #241c48, #1a1335);
    border: 1px solid #2c2355;
    border-radius: 10px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.element .el-emoji {
    font-size: 1.55rem;
    line-height: 1.15;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.element .el-nombre {
    font-size: 0.66rem;
    line-height: 1.15;
    color: var(--pergamino);
    word-break: break-word;
}

.element:hover {
    background: linear-gradient(180deg, #2c2358, #211944);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(242, 193, 78, 0.25);
}

.element:active { cursor: grabbing; }

/* Foco visible para navegación con teclado */
.element:focus-visible,
.enc-chip:focus-visible,
.slot:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Puntito: este elemento todavía puede crear algo nuevo */
.element.has-combos::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 0 6px var(--accent-color);
}

/* === ARRASTRAR Y SOLTAR === */
.slot.drag-over {
    background: radial-gradient(circle at 50% 35%, #332a68, #262050 70%);
    border-style: solid;
    border-color: var(--accent-color);
    box-shadow: 0 0 18px rgba(242, 193, 78, 0.45);
    transform: scale(1.08);
}

/* Táctil: el elemento está listo para arrastrarse */
.element.drag-ready {
    border-color: var(--accent-color);
    transform: scale(1.12);
    box-shadow: 0 0 10px rgba(242, 193, 78, 0.5);
}

/* Fantasma que sigue al dedo durante el arrastre táctil */
.drag-ghost {
    position: fixed;
    z-index: 400;
    pointer-events: none;
    opacity: 0.92;
    transform: translate(-50%, -120%) scale(1.15);
    border-color: var(--accent-color) !important;
    box-shadow: 0 0 14px rgba(242, 193, 78, 0.6);
    margin: 0;
    width: 90px;
}

/* === ENCICLOPEDIA (MODAL) === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 3, 12, 0.75);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: linear-gradient(180deg, #1b1438, var(--panel-color));
    border: 1px solid rgba(242, 193, 78, 0.35);
    border-radius: 16px;
    max-width: 640px;
    width: 100%;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), 0 0 40px rgba(242, 193, 78, 0.08);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(242, 193, 78, 0.2);
}

.modal-header h2 {
    font-family: 'Cinzel', serif;
    color: var(--accent-color);
    font-size: 1.3rem;
    letter-spacing: 1px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--pergamino);
    font-size: 1.2rem;
    cursor: pointer;
}

.modal-close:hover { color: #fff; }

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.enc-search {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--borde);
    background: #120d26;
    color: #fff;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.enc-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--slot-bg);
    border: 1px solid #2c2355;
    padding: 6px 10px;
    border-radius: 6px;
    margin: 3px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.enc-chip:hover { border-color: var(--accent-color); }

.enc-hero {
    text-align: center;
    margin-bottom: 10px;
}

.enc-hero .enc-emoji { font-size: 2.6rem; }

.enc-hero h3 {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    margin-top: 5px;
    color: var(--oro-claro);
}

.enc-hero .enc-cat { color: var(--pergamino); font-size: 0.9rem; }

.enc-section-title {
    font-family: 'Cinzel', serif;
    color: var(--accent-color);
    margin: 15px 0 8px;
    font-size: 1rem;
    border-bottom: 1px solid rgba(242, 193, 78, 0.2);
    padding-bottom: 4px;
}

.enc-recipe {
    background: #1b1438;
    padding: 6px 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
}

.enc-locked {
    color: var(--btn-hint);
    font-style: italic;
    margin-top: 8px;
    font-size: 0.9rem;
}

.enc-none {
    color: var(--pergamino);
    font-style: italic;
    font-size: 0.9rem;
}

.enc-back {
    margin-bottom: 12px;
}

/* === TOASTS DE LOGROS === */
#toasts {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: max-content;
    max-width: 90vw;
}

.toast {
    background: var(--panel-color);
    border: 1px solid var(--btn-hint);
    color: var(--text-color);
    padding: 10px 18px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(252, 163, 17, 0.4);
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    animation: toastIn 4s ease forwards;
}

@keyframes toastIn {
    0%   { opacity: 0; transform: translateY(25px) scale(0.9); }
    10%  { opacity: 1; transform: translateY(0) scale(1); }
    85%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-12px); }
}

/* Filas del panel de logros */
.logro-fila {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #1b1438;
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 0.92rem;
}

.logro-fila.logrado { border: 1px solid var(--btn-hint); }
.logro-fila .logro-progreso { color: var(--pergamino); white-space: nowrap; }
.logro-fila.logrado .logro-progreso { color: var(--btn-hint); }

/* === REVELACIÓN DIVINA (descubrimiento estilo Doodle God) === */
.discovery-fx {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
}

.dg-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, rgba(24, 16, 48, 0.94) 0%, rgba(5, 3, 12, 0.99) 75%);
    overflow: hidden;
    pointer-events: auto;
    cursor: pointer;
    animation: dgOverlay 2.4s ease forwards;
}

@keyframes dgOverlay {
    0%   { opacity: 0; }
    8%   { opacity: 1; }
    86%  { opacity: 1; }
    100% { opacity: 0; }
}

/* Rayos de luz divinos girando */
.dg-rays {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 170vmax;
    height: 170vmax;
    background: repeating-conic-gradient(
        rgba(242, 193, 78, 0.16) 0deg 8deg,
        transparent 8deg 22deg
    );
    border-radius: 50%;
    -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 58%);
    mask-image: radial-gradient(circle, #000 0%, transparent 58%);
    animation: dgSpin 18s linear infinite;
}

@keyframes dgSpin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Relámpago inicial */
.dg-flash {
    position: absolute;
    inset: 0;
    background: #fff;
    opacity: 0;
    animation: dgFlash 0.8s ease-out;
}

@keyframes dgFlash {
    0%   { opacity: 0; }
    5%   { opacity: 0.9; }
    12%  { opacity: 0; }
    18%  { opacity: 0.45; }
    28%  { opacity: 0; }
    100% { opacity: 0; }
}

.dg-centro {
    position: relative;
    text-align: center;
    padding: 20px;
    animation: dgPop 2.4s ease forwards;
}

@keyframes dgPop {
    0%   { transform: scale(0.25); opacity: 0; }
    12%  { transform: scale(1.12); opacity: 1; }
    20%  { transform: scale(1); }
    86%  { opacity: 1; }
    100% { opacity: 0; transform: scale(0.96); }
}

.dg-emoji {
    font-size: clamp(4.5rem, 18vw, 7rem);
    line-height: 1.1;
    filter: drop-shadow(0 0 32px rgba(242, 193, 78, 0.8));
}

.dg-titulo {
    font-family: 'Cinzel', serif;
    letter-spacing: 4px;
    text-transform: uppercase;
    font-size: 0.82rem;
    color: var(--pergamino);
    margin-top: 12px;
}

.dg-nombre {
    font-family: 'Cinzel Decorative', 'Cinzel', serif;
    font-size: clamp(1.7rem, 7vw, 2.7rem);
    color: var(--accent-color);
    text-shadow: 0 0 26px rgba(242, 193, 78, 0.6);
    margin: 4px 0 14px;
}

.dg-cita {
    font-style: italic;
    color: #bfb49a;
    font-size: 0.95rem;
    max-width: 480px;
    margin: 0 auto;
}

/* === MÓVIL === */
@media (max-width: 480px) {
    body { padding: 8px; }
    .game-container { padding: 14px; }
    .game-header h1 { font-size: 1.45rem; margin-bottom: 6px; }
    .game-header { margin-bottom: 15px; }
    .stats { font-size: 0.92rem; }
    .forge-zone { padding: 12px; }
    .slot { width: 76px; height: 76px; font-size: 1.2rem; border-radius: 10px; }
    .slot span { font-size: 0.6rem; }
    .slots-container { gap: 6px; margin-bottom: 10px; }
    .forge-operator { font-size: 1.2rem; }
    .control-actions { gap: 6px; }
    .btn { padding: 8px 12px; font-size: 0.8rem; }
    .message-board { font-size: 0.9rem; }
    .modal-body { padding: 14px; }
    .inventory-zone { max-height: none; }
    .category-items { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
    .element { min-height: 64px; padding: 6px 3px; }
    .element .el-emoji { font-size: 1.35rem; }
    .element .el-nombre { font-size: 0.6rem; }
}
