/* Root variables for design system */
:root {
    --bg-dark: #090d16;
    --card-bg: rgba(15, 23, 42, 0.65);
    --border-color: rgba(99, 102, 241, 0.25);
    --neon-indigo: #6366f1;
    --neon-pink: #ec4899;
    --neon-cyan: #06b6d4;
    --neon-yellow: #eab308;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', 'Noto Sans KR', sans-serif;
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    box-sizing: border-box;
    padding-top: 20px;
    padding-bottom: 20px;
}

/* Prevent Google AdSense / Auto Ads / wide banners from stretching the screen horizontally */
ins.adsbygoogle,
.google-auto-placed,
[id^="google_ads_iframe"],
[id^="aswift_"],
iframe,
.ad-container,
.admob-card {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

.google-auto-placed {
    width: 100% !important;
    max-width: 100vw !important;
    left: 0 !important;
}

/* Background glowing particles/circles */
.glow-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(236, 72, 153, 0.05) 50%, rgba(0, 0, 0, 0) 100%);
    filter: blur(80px);
    z-index: -1;
    pointer-events: none;
}

.app-container {
    width: 100%;
    max-width: 700px;
    padding: 20px;
    z-index: 1;
    overflow: hidden !important;
    box-sizing: border-box;
}

header {
    margin-bottom: 24px;
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-sound {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: var(--neon-cyan);
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition-smooth);
    text-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
}

.btn-sound:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.3);
}

.logo-text {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, var(--neon-indigo), var(--neon-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.logo-text span {
    font-weight: 300;
    color: var(--neon-cyan);
    -webkit-text-fill-color: var(--neon-cyan);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 6px;
}

/* Glassmorphism Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 28px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    transition: var(--transition-smooth);
    width: 100%;
    max-width: 100%;
    overflow: hidden !important;
    box-sizing: border-box;
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 20px 45px rgba(99, 102, 241, 0.1), 0 20px 40px rgba(0, 0, 0, 0.6);
}

.section-title {
    margin-bottom: 16px;
}

.section-title h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--neon-cyan);
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

/* Player Count Selector */
.player-count-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.btn-count {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-count:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--neon-indigo);
}

.btn-count.active {
    background: var(--neon-indigo);
    border-color: var(--neon-indigo);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.custom-count-input {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 12px;
}

.custom-count-input input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 36px;
    font-weight: 600;
    text-align: center;
    font-size: 0.9rem;
}

.custom-count-input input:focus {
    outline: none;
}

/* Two Columns Setup Layout */
.setup-columns-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 24px;
}

.setup-col {
    background: rgba(30, 41, 59, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 16px;
    border-radius: 20px;
}

.inputs-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 6px;
}

.inputs-list::-webkit-scrollbar {
    width: 4px;
}

.inputs-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.input-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-item span {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 24px;
}

.inputs-list input {
    flex: 1;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: var(--transition-smooth);
}

.inputs-list input:focus {
    outline: none;
}

.inputs-list .name-input {
    border-left: 3px solid var(--neon-indigo);
}

.inputs-list .name-input:focus {
    border-color: var(--neon-indigo);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.inputs-list .prize-input {
    border-left: 3px solid var(--neon-pink);
}

.inputs-list .prize-input:focus {
    border-color: var(--neon-pink);
    box-shadow: 0 0 10px rgba(236, 72, 153, 0.2);
}

.penalty-setup {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.penalty-count-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.8);
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.penalty-count-row label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.dropdown-select {
    background: rgba(30, 41, 59, 0.8);
    color: var(--neon-cyan);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.dropdown-select:focus {
    outline: none;
    border-color: var(--neon-cyan);
}

.penalty-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 8px;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--neon-indigo), #4f46e5);
    color: var(--text-primary);
    border: none;
    padding: 14px 28px;
    border-radius: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn-glow {
    position: relative;
    overflow: hidden;
}

.btn-glow::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    transition: 0.5s;
    pointer-events: none;
}

.btn-glow:hover::after {
    left: 120%;
}

.btn-secondary {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-secondary:hover {
    color: var(--text-primary);
    background: rgba(51, 65, 85, 0.8);
}

.btn-accent {
    background: linear-gradient(135deg, var(--neon-pink), #db2777);
    color: var(--text-primary);
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-accent:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(236, 72, 153, 0.4);
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Game Arena Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

.game-status {
    font-size: 0.85rem;
    color: var(--neon-cyan);
    font-weight: 600;
    text-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
    text-align: center;
}

/* Ladder Interactive Board & Scroll Wrapper */
.ladder-canvas-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(9, 13, 22, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 20px 14px;
    margin-top: 10px;
    width: 100%;
    max-width: 100%;
    overflow: hidden !important;
    box-sizing: border-box;
}

.scroll-hint {
    font-size: 0.8rem;
    color: var(--neon-yellow);
    background: rgba(234, 179, 8, 0.15);
    border: 1px dashed var(--neon-yellow);
    padding: 6px 14px;
    border-radius: 20px;
    margin-bottom: 12px;
    text-align: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.ladder-scroll-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--neon-indigo) rgba(15, 23, 42, 0.5);
    box-sizing: border-box;
}

.ladder-scroll-wrapper::-webkit-scrollbar {
    height: 6px;
}

.ladder-scroll-wrapper::-webkit-scrollbar-thumb {
    background: var(--neon-indigo);
    border-radius: 3px;
}

.ladder-inner-board {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100%;
    margin: 0 auto;
}

.names-row {
    position: relative;
    display: flex;
    width: 100%;
    height: 48px;
    z-index: 2;
}

.names-row.top-row {
    margin-bottom: 8px;
}

.names-row.bottom-row {
    margin-top: 8px;
}

.node-card {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    min-width: 56px;
    max-width: 85px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.top-row .node-card {
    cursor: pointer;
    border-bottom: 3px solid var(--neon-indigo);
}

.top-row .node-card:hover {
    transform: translateX(-50%) translateY(-4px);
    border-color: var(--neon-indigo);
    background: rgba(99, 102, 241, 0.25);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

.top-row .node-card.completed {
    border-color: var(--text-secondary);
    border-bottom-color: var(--text-secondary);
    opacity: 0.5;
    cursor: default;
    transform: translateX(-50%);
}

.bottom-row .node-card {
    border-top: 3px solid var(--neon-pink);
    background: rgba(30, 41, 59, 0.7);
    border-radius: 12px;
}

.bottom-row .node-card.revealed {
    background: rgba(236, 72, 153, 0.2);
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    text-shadow: 0 0 10px rgba(236, 72, 153, 0.3);
    animation: flip 0.6s ease-out forwards;
}

.bottom-row .node-card.mystery {
    border-top: 3px solid var(--neon-cyan);
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
    background: rgba(15, 23, 42, 0.85);
    font-size: 1.1rem;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.2);
}

#ladder-canvas {
    width: 100%;
    height: 380px;
    display: block;
    background: transparent;
    z-index: 1;
}

@keyframes flip {
    from { transform: translateX(-50%) rotateX(90deg); opacity: 0; }
    to { transform: translateX(-50%) rotateX(0); opacity: 1; }
}

/* Comprehensive Mobile & Tablet Optimizations */
@media (max-width: 650px) {
    .app-container {
        padding: 8px;
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    .card {
        padding: 18px 12px;
        border-radius: 18px;
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    .setup-columns-container {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .setup-col {
        padding: 14px 12px;
        border-radius: 16px;
    }
    
    .logo-text {
        font-size: 1.8rem;
    }
    
    .game-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .game-header button {
        width: 100%;
        justify-content: center;
        padding: 12px;
    }
    
    .game-status {
        font-size: 0.9rem;
        margin: 4px 0;
    }
    
    .action-bar button {
        width: 100%;
        padding: 16px;
        font-size: 1.1rem;
    }
    
    .inputs-list input {
        font-size: 0.95rem;
        padding: 10px 12px;
    }
    
    .ladder-canvas-container {
        padding: 14px 6px;
        border-radius: 16px;
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    .node-card {
        padding: 6px 8px;
        font-size: 0.8rem;
        min-width: 50px;
        max-width: 72px;
    }
    
    #ladder-canvas {
        height: 350px;
    }
}

@media (max-width: 400px) {
    .logo-text {
        font-size: 1.5rem;
    }
    
    .node-card {
        padding: 5px 6px;
        font-size: 0.75rem;
        min-width: 46px;
        max-width: 65px;
    }
}

/* Modals & AdMob Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(9, 13, 22, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: var(--transition-smooth);
}

.admob-card {
    background: #1e293b;
    border: 2px solid var(--neon-indigo);
    border-radius: 24px;
    width: 90%;
    max-width: 420px;
    padding: 24px;
    box-shadow: 0 25px 50px rgba(99, 102, 241, 0.3);
    position: relative;
    overflow: hidden;
    animation: scale-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ad-tag {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--neon-yellow);
    color: #0f172a;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 4px 10px;
    border-bottom-right-radius: 12px;
    text-transform: uppercase;
}

.admob-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    margin-bottom: 20px;
}

.admob-logo {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
}

.ad-close-btn {
    color: var(--neon-pink);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.ad-close-btn:hover {
    text-shadow: 0 0 10px var(--neon-pink);
}

.ad-body {
    background: #0f172a;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.ad-banner-img {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.ad-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.ad-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.ad-action-btn {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: var(--transition-smooth);
}

.ad-action-btn:hover {
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.ad-footer {
    text-align: center;
    margin-top: 18px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Results modal */
.results-card {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    width: 90%;
    max-width: 450px;
    padding: 28px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: scale-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.results-card h2 {
    color: var(--neon-cyan);
    margin-bottom: 20px;
    font-size: 1.4rem;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 6px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    background: #0f172a;
    padding: 12px 18px;
    border-radius: 12px;
    border-left: 4px solid var(--neon-indigo);
}

.result-row span.name {
    font-weight: 600;
    color: var(--text-primary);
}

.result-row span.prize {
    font-weight: 600;
    color: var(--neon-pink);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* Utilities */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fade-in 0.4s ease-out forwards;
}

/* Animations */
@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scale-up {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes flip {
    from { transform: rotateX(90deg); opacity: 0; }
    to { transform: rotateX(0); opacity: 1; }
}

/* Responsive adjustment */
@media (max-width: 480px) {
    .inputs-grid {
        grid-template-columns: 1fr;
    }
    
    .logo-text {
        font-size: 2.2rem;
    }
}
