/**
 * Lucky Draw - Created by Dragon
 * Dark theme inspired by dev4.local with Pokemon card-style animations
 * v1.0.0-alpha
 */

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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #22c55e;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --danger-color: #ef4444;
    --gold-color: #fbbf24;
    --gold-dark: #f59e0b;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100vw;
    overflow: hidden;
}

/* Header - Mobile First */
.app-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.6rem 1rem;
    background: var(--surface-color);
    position: relative;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    font-size: 1.2rem;
    color: var(--gold-color);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Mode Toggle - Below Grid */
.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 0;
}

.mode-btn {
    padding: 0.6rem 1rem;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.5);
    transform: scale(1.05);
    font-weight: 700;
}

.mode-btn[data-mode="outside"].active {
    background: #f59e0b;
    border-color: #f59e0b;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.5);
}

.mode-btn:not(.active):hover {
    border-color: var(--primary-color);
    color: var(--text-color);
}

.settings-btn {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.2rem;
    transition: transform 0.2s;
}

.settings-btn:hover {
    transform: translateY(-50%) scale(1.2);
}

/* Grid Container */
.grid-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
}

/* Slot Styles - White background for images */
.slot {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background-color: #ffffff;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 0 0 2px rgba(255, 255, 255, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.slot:hover {
    transform: scale(1.03);
    box-shadow:
        0 8px 25px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(99, 102, 241, 0.3),
        inset 0 0 0 2px rgba(99, 102, 241, 0.5);
}

.slot::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, 0.7) 100%);
    pointer-events: none;
    z-index: 1;
}

/* Big slot number - unpicked slots */
.slot-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    font-weight: 900;
    color: white;
    text-shadow:
        0 0 15px rgba(99, 102, 241, 0.9),
        0 0 30px rgba(99, 102, 241, 0.6),
        0 6px 12px rgba(0, 0, 0, 0.9),
        3px 3px 0 var(--primary-dark),
        -3px -3px 0 var(--primary-dark),
        3px -3px 0 var(--primary-dark),
        -3px 3px 0 var(--primary-dark);
    z-index: 2;
    transition: all 0.3s;
}

.slot:hover .slot-number {
    text-shadow:
        0 0 15px rgba(251, 191, 36, 0.9),
        0 0 30px rgba(251, 191, 36, 0.6),
        0 4px 8px rgba(0, 0, 0, 0.8);
    color: var(--gold-color);
}

/* Selected slot - faded image with text overlay */
.slot.selected {
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 0 0 3px var(--secondary-color);
}

.slot.selected::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    z-index: 1;
}

.slot.selected .slot-number {
    font-size: 0.7rem;
    top: 3px;
    bottom: auto;
    left: 3px;
    transform: none;
    background: rgba(34, 197, 94, 0.9);
    padding: 2px 5px;
    border-radius: 4px;
    text-shadow: none;
    color: white;
}

/* Prize text on selected slot - full box coverage */
.slot-prize {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: transparent;
    color: #000;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    z-index: 3;
    cursor: pointer;
    text-shadow:
        1px 1px 0 #fff,
        -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff;
    line-height: 1.3;
}

.slot-prize:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Footer - In-flow below mode toggle */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0 1rem;
    margin-top: 15px;
    flex-wrap: wrap;
}

.credit {
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: var(--text-muted);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

/* Modal Base */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    padding-bottom: 20vh;
    perspective: 1000px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    border: 1px solid var(--border-color);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-color);
}

/* Prize Modal - Pokemon Card Style */
.prize-modal-content {
    background: transparent;
    border: none;
    text-align: center;
    max-width: 640px;
    width: 90%;
}

.prize-card {
    position: relative;
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border-radius: 24px;
    padding: 32px;
    padding-bottom: 48px;
    border: 6px solid var(--gold-color);
    box-shadow:
        0 0 40px rgba(251, 191, 36, 0.5),
        0 25px 70px rgba(0, 0, 0, 0.7),
        inset 0 0 100px rgba(251, 191, 36, 0.05);
    animation: cardAppear 0.6s ease-out;
}

.prize-card-inner {
    background: linear-gradient(180deg, #2a2a4a 0%, #1a1a2e 100%);
    border-radius: 16px;
    padding: 50px 40px;
    border: 2px solid rgba(251, 191, 36, 0.3);
}

.modal-prize-text {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--gold-color);
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.5);
    line-height: 1.4;
}

.prize-card-type {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--gold-color), var(--gold-dark));
    color: #1a1a2e;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 6px 20px;
    border-radius: 15px;
    text-transform: uppercase;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

@keyframes cardAppear {
    0% {
        transform: scale(0.3) rotateY(-30deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotateY(5deg);
    }
    100% {
        transform: scale(1) rotateY(0);
        opacity: 1;
    }
}

/* 3D Dice Roller */
.dice-section {
    margin-top: 1.5rem;
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid rgba(251, 191, 36, 0.3);
}

.dice-container {
    perspective: 600px;
    width: 80px;
    height: 80px;
    margin: 0 auto 1rem;
}

.dice {
    width: 80px;
    height: 80px;
    position: relative;
    transform-style: preserve-3d;
    background: #c62828;
    border-radius: 10px;
    transition: opacity 0.15s ease;
}

.dice.rolling {
    animation: diceRoll 3s linear;
}

.dice-face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(145deg, #e53935, #c62828);
    border-radius: 10px;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.3);
    box-sizing: border-box;
    backface-visibility: hidden;
}

.dot {
    width: 14px;
    height: 14px;
    background: radial-gradient(circle at 30% 30%, #fff, #eee);
    border-radius: 50%;
    position: absolute;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Dot positions */
.dot.center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.dot.top-left { top: 12px; left: 12px; }
.dot.top-right { top: 12px; right: 12px; }
.dot.middle-left { top: 50%; left: 12px; transform: translateY(-50%); }
.dot.middle-right { top: 50%; right: 12px; transform: translateY(-50%); }
.dot.bottom-left { bottom: 12px; left: 12px; }
.dot.bottom-right { bottom: 12px; right: 12px; }

/* Face positions */
.dice-face.front  { transform: rotateY(0deg) translateZ(40px); }
.dice-face.back   { transform: rotateY(180deg) translateZ(40px); }
.dice-face.right  { transform: rotateY(90deg) translateZ(40px); }
.dice-face.left   { transform: rotateY(-90deg) translateZ(40px); }
.dice-face.top    { transform: rotateX(90deg) translateZ(40px); }
.dice-face.bottom { transform: rotateX(-90deg) translateZ(40px); }

/* Inner faces to hide gaps */
.dice-inner {
    position: absolute;
    width: 80px;
    height: 80px;
    background: #b71c1c;
    border-radius: 10px;
    backface-visibility: hidden;
}
.dice-inner.inner-front  { transform: rotateY(0deg) translateZ(39px); }
.dice-inner.inner-back   { transform: rotateY(180deg) translateZ(39px); }
.dice-inner.inner-right  { transform: rotateY(90deg) translateZ(39px); }
.dice-inner.inner-left   { transform: rotateY(-90deg) translateZ(39px); }
.dice-inner.inner-top    { transform: rotateX(90deg) translateZ(39px); }
.dice-inner.inner-bottom { transform: rotateX(-90deg) translateZ(39px); }

/* Show specific face */
.dice.show-1 { transform: rotateY(0deg) rotateX(0deg); }
.dice.show-2 { transform: rotateX(90deg); }
.dice.show-3 { transform: rotateY(-90deg); }
.dice.show-4 { transform: rotateY(90deg); }
.dice.show-5 { transform: rotateX(-90deg); }
.dice.show-6 { transform: rotateY(180deg); }

@keyframes diceRoll {
    0% { transform: rotateX(0deg) rotateY(0deg); }
    100% { transform: rotateX(1440deg) rotateY(1080deg); }
}

.dice-result {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gold-color);
    margin-bottom: 0.75rem;
}

.dice-result span {
    font-size: 1.8rem;
    color: #fff;
    background: var(--primary-color);
    padding: 0.15rem 0.6rem;
    border-radius: 6px;
    margin-left: 0.4rem;
}

.dice-btn {
    font-size: 1rem;
    padding: 0.6rem 1.5rem;
}

.dice-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Confetti container */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 99;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -20px;
    animation: confettiFall 3s ease-in forwards;
}

/* Animations */
@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Confirm Modal */
.confirm-modal .modal-content {
    max-width: 350px;
    text-align: center;
    padding: 2rem;
}

.confirm-modal h3 {
    color: var(--danger-color);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.confirm-modal p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.confirm-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Already Chosen Modal */
.already-chosen-content {
    max-width: 640px;
    width: 90%;
    text-align: center;
    padding: 3rem;
    background: var(--surface-color);
    border: 3px solid var(--danger-color);
    border-radius: 20px;
}

.already-chosen-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
}

.already-chosen-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--danger-color);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.already-chosen-subtitle {
    font-size: 1.4rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.already-prize-box {
    background: var(--bg-color);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid var(--border-color);
}

.already-prize-text {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    line-height: 1.4;
}

/* Admin Modal */
.admin-modal .modal-content {
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.admin-header h2 {
    color: var(--gold-color);
}

.admin-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.setting-group input[type="text"] {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-color);
    font-size: 1rem;
}

.setting-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.prizes-header {
    margin-bottom: 1rem;
}

.prizes-header h3 {
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 0.75rem;
}

/* Admin Tabs */
.admin-tabs {
    display: flex;
    gap: 0.5rem;
}

.admin-tab {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.admin-tab.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.5);
    transform: scale(1.05);
    font-weight: 700;
}

.admin-tab[data-tab="outside"].active {
    background: #f59e0b;
    border-color: #f59e0b;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.5);
}

.admin-tab:not(.active):hover {
    border-color: var(--primary-color);
    color: var(--text-color);
}

.hidden {
    display: none !important;
}

.prizes-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
}

.prize-item {
    display: grid;
    grid-template-columns: 35px 1fr;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.prize-item:last-child {
    border-bottom: none;
}

.prize-number {
    font-weight: 700;
    color: var(--gold-color);
    text-align: center;
}

.prize-item input {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: var(--text-color);
    font-size: 0.85rem;
}

.prize-item input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.admin-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

/* Responsive */
@media (max-width: 600px) {
    .grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .slot-number {
        font-size: 3.5rem;
    }

    .slot-prize {
        font-size: 0.7rem;
        padding: 5px 10px;
    }

    .prize-item {
        grid-template-columns: 30px 1fr;
    }

    .prize-item input:nth-child(3),
    .prize-item input:nth-child(4) {
        grid-column: 2;
    }

}

@media (max-width: 400px) {
    .grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .slot-number {
        font-size: 2rem;
    }

    .slot-prize {
        font-size: 0.55rem;
    }
}
